Support not skipping extra spaces in ui::label

This commit is contained in:
Nikita Lisitsa 2022-02-02 18:14:54 +03:00
parent 460632a118
commit e4bd58c5ef
2 changed files with 13 additions and 0 deletions

View file

@ -58,6 +58,9 @@ namespace psemek::ui
virtual void set_overflow(overflow_mode value); virtual void set_overflow(overflow_mode value);
virtual overflow_mode overflow() const { return overflow_; } virtual overflow_mode overflow() const { return overflow_; }
virtual void set_skip_spaces(bool value);
virtual bool skip_spaces() const { return skip_spaces_; }
struct shape const & shape() const override { return shape_; } struct shape const & shape() const override { return shape_; }
void reshape(geom::box<float, 2> const & bbox) override; void reshape(geom::box<float, 2> const & bbox) override;
@ -74,6 +77,7 @@ namespace psemek::ui
valignment valign_ = valignment::top; valignment valign_ = valignment::top;
multiline_mode multiline_ = multiline_mode::none; multiline_mode multiline_ = multiline_mode::none;
overflow_mode overflow_ = overflow_mode::ignore; overflow_mode overflow_ = overflow_mode::ignore;
bool skip_spaces_ = false;
box_shape shape_; box_shape shape_;

View file

@ -34,6 +34,12 @@ namespace psemek::ui
on_state_changed(); on_state_changed();
} }
void label::set_skip_spaces(bool value)
{
skip_spaces_ = value;
on_state_changed();
}
void label::set_overflow(overflow_mode value) void label::set_overflow(overflow_mode value)
{ {
overflow_ = value; overflow_ = value;
@ -132,6 +138,9 @@ namespace psemek::ui
for (std::size_t line = 0; line < max_lines; ++line) for (std::size_t line = 0; line < max_lines; ++line)
{ {
if (line != 0) if (line != 0)
++current_glyph;
if (skip_spaces_)
{ {
while (current_glyph < glyphs.size() && std::isspace(glyphs[current_glyph].character)) while (current_glyph < glyphs.size() && std::isspace(glyphs[current_glyph].character))
++current_glyph; ++current_glyph;