diff --git a/libs/ui/source/label.cpp b/libs/ui/source/label.cpp index 9f0763ce..064e0bdc 100644 --- a/libs/ui/source/label.cpp +++ b/libs/ui/source/label.cpp @@ -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 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 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(3, end) - 3; i < end; ++i) + text[i] = '.'; + cached_state_->glyphs = st->font->shape(text, opts); + } + break; + } + geom::box bbox; for (auto const & g : cached_state_->glyphs) bbox |= g.position; - int lines = 1; - geom::vector offset; switch (halign_)