Support overflow modes in label

This commit is contained in:
Nikita Lisitsa 2021-02-25 21:25:25 +03:00
parent 585edaf5b5
commit 92a395c293

View file

@ -84,12 +84,48 @@ namespace psemek::ui
opts.scale = st->text_scale;
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;
for (auto const & g : cached_state_->glyphs)
bbox |= g.position;
int lines = 1;
geom::vector<float, 2> offset;
switch (halign_)