Support overflow modes in label
This commit is contained in:
parent
585edaf5b5
commit
92a395c293
1 changed files with 38 additions and 2 deletions
|
|
@ -84,12 +84,48 @@ namespace psemek::ui
|
||||||
opts.scale = st->text_scale;
|
opts.scale = st->text_scale;
|
||||||
cached_state_->glyphs = st->font->shape(text_, opts);
|
cached_state_->glyphs = st->font->shape(text_, opts);
|
||||||
|
|
||||||
|
int lines = 1;
|
||||||
|
|
||||||
|
switch (overflow_)
|
||||||
|
{
|
||||||
|
case overflow_mode::ignore:
|
||||||
|
break;
|
||||||
|
case overflow_mode::drop:
|
||||||
|
{
|
||||||
|
geom::interval<float> x;
|
||||||
|
std::size_t end = 0;
|
||||||
|
for (; end < cached_state_->glyphs.size(); ++end)
|
||||||
|
{
|
||||||
|
x |= cached_state_->glyphs[end].position[0];
|
||||||
|
if (x.length() > shape_.box[0].length())
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
cached_state_->glyphs.resize(end);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case overflow_mode::ellipsis:
|
||||||
|
{
|
||||||
|
geom::interval<float> x;
|
||||||
|
std::size_t end = 0;
|
||||||
|
for (; end < cached_state_->glyphs.size(); ++end)
|
||||||
|
{
|
||||||
|
x |= cached_state_->glyphs[end].position[0];
|
||||||
|
if (x.length() > shape_.box[0].length())
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string text = text_.substr(0, end);
|
||||||
|
for (std::size_t i = std::max<std::size_t>(3, end) - 3; i < end; ++i)
|
||||||
|
text[i] = '.';
|
||||||
|
cached_state_->glyphs = st->font->shape(text, opts);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
geom::box<float, 2> bbox;
|
geom::box<float, 2> bbox;
|
||||||
for (auto const & g : cached_state_->glyphs)
|
for (auto const & g : cached_state_->glyphs)
|
||||||
bbox |= g.position;
|
bbox |= g.position;
|
||||||
|
|
||||||
int lines = 1;
|
|
||||||
|
|
||||||
geom::vector<float, 2> offset;
|
geom::vector<float, 2> offset;
|
||||||
|
|
||||||
switch (halign_)
|
switch (halign_)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue