1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:47:44 +00:00

LibGUI: Add a title to all Widgets

This title is a generic user-facing name for the widget. For now, it's
only used by TabWidget for tab names.
This commit is contained in:
kleines Filmröllchen 2022-03-18 22:54:30 +01:00 committed by Andreas Kling
parent fd6d87df82
commit 0410414455
2 changed files with 19 additions and 0 deletions

View file

@ -70,6 +70,8 @@ Widget::Widget()
REGISTER_INT_PROPERTY("font_size", m_font->presentation_size, set_font_size);
REGISTER_FONT_WEIGHT_PROPERTY("font_weight", m_font->weight, set_font_weight);
REGISTER_STRING_PROPERTY("title", title, set_title);
register_property(
"font_type", [this] { return m_font->is_fixed_width() ? "FixedWidth" : "Normal"; },
[this](auto& value) {
@ -976,6 +978,19 @@ void Widget::set_palette(Palette const& palette)
update();
}
void Widget::set_title(String title)
{
m_title = move(title);
// For tab widget children, our change in title also affects the parent.
if (parent_widget())
parent_widget()->update();
}
String Widget::title() const
{
return m_title;
}
void Widget::set_background_role(ColorRole role)
{
m_background_role = role;

View file

@ -278,6 +278,9 @@ public:
Gfx::Palette palette() const;
void set_palette(Gfx::Palette const&);
String title() const;
void set_title(String);
Margins const& grabbable_margins() const { return m_grabbable_margins; }
void set_grabbable_margins(Margins const&);
@ -390,6 +393,7 @@ private:
bool m_default_font { true };
NonnullRefPtr<Gfx::PaletteImpl> m_palette;
String m_title { String::empty() };
WeakPtr<Widget> m_focus_proxy;
FocusPolicy m_focus_policy { FocusPolicy::NoFocus };