diff --git a/libs/ui/include/psemek/ui/label.hpp b/libs/ui/include/psemek/ui/label.hpp index 5e706426..d49b7a75 100644 --- a/libs/ui/include/psemek/ui/label.hpp +++ b/libs/ui/include/psemek/ui/label.hpp @@ -44,6 +44,9 @@ namespace psemek::ui virtual void set_tagged_text(std::string text); virtual std::string_view text() const { return text_; } + virtual void set_text_style(ui::text_style style); + virtual ui::text_style text_style() const { return text_style_; } + virtual void set_halign(halignment value); virtual halignment halign() const { return halign_; } @@ -95,6 +98,7 @@ namespace psemek::ui bool wrap_ = true; overflow_mode overflow_ = overflow_mode::ignore; bool skip_spaces_ = false; + ui::text_style text_style_ = {}; struct image_provider * image_provider_ = nullptr; tagged_text::mapper tag_mapper_ = nullptr; @@ -106,7 +110,7 @@ namespace psemek::ui struct text_chunk { std::string text; - text_style style; // to be OR'd with base style + ui::text_style style; // to be OR'd with base style std::optional color; std::optional link; }; @@ -121,6 +125,7 @@ namespace psemek::ui using chunk = std::variant; std::string text_; + bool tagged_ = false; std::vector chunks_; struct cached_state diff --git a/libs/ui/source/label.cpp b/libs/ui/source/label.cpp index dfd5a724..30ea0170 100644 --- a/libs/ui/source/label.cpp +++ b/libs/ui/source/label.cpp @@ -19,9 +19,10 @@ namespace psemek::ui void label::set_text(std::string text) { text_ = std::move(text); + tagged_ = false; chunks_.clear(); - chunks_.push_back(text_chunk{{text_.data(), text_.size()}, text_style{}, std::nullopt, std::nullopt}); + chunks_.push_back(text_chunk{{text_.data(), text_.size()}, text_style_, std::nullopt, std::nullopt}); on_state_changed(); } @@ -59,6 +60,7 @@ namespace psemek::ui void label::set_tagged_text(std::string text) { text_ = std::move(text); + tagged_ = true; selected_link_ = std::nullopt; chunks_.clear(); @@ -136,6 +138,15 @@ namespace psemek::ui on_state_changed(); } + void label::set_text_style(ui::text_style style) + { + text_style_ = style; + if (tagged_) + set_tagged_text(std::move(text_)); + else + set_text(std::move(text_)); + } + void label::set_halign(halignment value) { halign_ = value; @@ -372,7 +383,7 @@ namespace psemek::ui struct item_chunk { std::size_t end; - text_style style; + ui::text_style style; gfx::color_rgba color; gfx::texture_view_2d image; std::optional link;