Support changing ui::label text_style without tagged text
This commit is contained in:
parent
7d55b374e4
commit
d5fdb2a7c5
2 changed files with 19 additions and 3 deletions
|
|
@ -44,6 +44,9 @@ namespace psemek::ui
|
||||||
virtual void set_tagged_text(std::string text);
|
virtual void set_tagged_text(std::string text);
|
||||||
virtual std::string_view text() const { return 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 void set_halign(halignment value);
|
||||||
virtual halignment halign() const { return halign_; }
|
virtual halignment halign() const { return halign_; }
|
||||||
|
|
||||||
|
|
@ -95,6 +98,7 @@ namespace psemek::ui
|
||||||
bool wrap_ = true;
|
bool wrap_ = true;
|
||||||
overflow_mode overflow_ = overflow_mode::ignore;
|
overflow_mode overflow_ = overflow_mode::ignore;
|
||||||
bool skip_spaces_ = false;
|
bool skip_spaces_ = false;
|
||||||
|
ui::text_style text_style_ = {};
|
||||||
|
|
||||||
struct image_provider * image_provider_ = nullptr;
|
struct image_provider * image_provider_ = nullptr;
|
||||||
tagged_text::mapper tag_mapper_ = nullptr;
|
tagged_text::mapper tag_mapper_ = nullptr;
|
||||||
|
|
@ -106,7 +110,7 @@ namespace psemek::ui
|
||||||
struct text_chunk
|
struct text_chunk
|
||||||
{
|
{
|
||||||
std::string text;
|
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<gfx::color_rgba> color;
|
std::optional<gfx::color_rgba> color;
|
||||||
std::optional<std::string> link;
|
std::optional<std::string> link;
|
||||||
};
|
};
|
||||||
|
|
@ -121,6 +125,7 @@ namespace psemek::ui
|
||||||
using chunk = std::variant<text_chunk, image_chunk>;
|
using chunk = std::variant<text_chunk, image_chunk>;
|
||||||
|
|
||||||
std::string text_;
|
std::string text_;
|
||||||
|
bool tagged_ = false;
|
||||||
std::vector<chunk> chunks_;
|
std::vector<chunk> chunks_;
|
||||||
|
|
||||||
struct cached_state
|
struct cached_state
|
||||||
|
|
|
||||||
|
|
@ -19,9 +19,10 @@ namespace psemek::ui
|
||||||
void label::set_text(std::string text)
|
void label::set_text(std::string text)
|
||||||
{
|
{
|
||||||
text_ = std::move(text);
|
text_ = std::move(text);
|
||||||
|
tagged_ = false;
|
||||||
|
|
||||||
chunks_.clear();
|
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();
|
on_state_changed();
|
||||||
}
|
}
|
||||||
|
|
@ -59,6 +60,7 @@ namespace psemek::ui
|
||||||
void label::set_tagged_text(std::string text)
|
void label::set_tagged_text(std::string text)
|
||||||
{
|
{
|
||||||
text_ = std::move(text);
|
text_ = std::move(text);
|
||||||
|
tagged_ = true;
|
||||||
selected_link_ = std::nullopt;
|
selected_link_ = std::nullopt;
|
||||||
|
|
||||||
chunks_.clear();
|
chunks_.clear();
|
||||||
|
|
@ -136,6 +138,15 @@ namespace psemek::ui
|
||||||
on_state_changed();
|
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)
|
void label::set_halign(halignment value)
|
||||||
{
|
{
|
||||||
halign_ = value;
|
halign_ = value;
|
||||||
|
|
@ -372,7 +383,7 @@ namespace psemek::ui
|
||||||
struct item_chunk
|
struct item_chunk
|
||||||
{
|
{
|
||||||
std::size_t end;
|
std::size_t end;
|
||||||
text_style style;
|
ui::text_style style;
|
||||||
gfx::color_rgba color;
|
gfx::color_rgba color;
|
||||||
gfx::texture_view_2d image;
|
gfx::texture_view_2d image;
|
||||||
std::optional<std::string> link;
|
std::optional<std::string> link;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue