mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-30 00:31:14 +00:00
LibGUI: Allow buttons to control the behavior when their text changes
Some buttons control how their text is set in unique ways. For example, GUI::ToolbarButton will set only its tooltip instead of its text if it has an icon. So when the text changes, ToolbarButton will want to change its tooltip instead.
This commit is contained in:
parent
62cbfc68b9
commit
234ae3a2ae
Notes:
sideshowbarker
2024-07-17 17:49:11 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/234ae3a2ae Pull-request: https://github.com/SerenityOS/serenity/pull/16118
|
@ -20,7 +20,7 @@ public:
|
|||
|
||||
Function<void(bool)> on_checked;
|
||||
|
||||
void set_text(String);
|
||||
virtual void set_text(String);
|
||||
String const& text() const { return m_text; }
|
||||
|
||||
bool is_exclusive() const { return m_exclusive; }
|
||||
|
|
|
@ -59,6 +59,17 @@ private:
|
|||
set_text(action.text());
|
||||
set_button_style(Gfx::ButtonStyle::Coolbar);
|
||||
}
|
||||
|
||||
virtual void set_text(String text) override
|
||||
{
|
||||
auto const* action = this->action();
|
||||
VERIFY(action);
|
||||
|
||||
set_tooltip(tooltip(*action));
|
||||
if (!action->icon())
|
||||
Button::set_text(move(text));
|
||||
}
|
||||
|
||||
String tooltip(Action const& action) const
|
||||
{
|
||||
StringBuilder builder;
|
||||
|
|
Loading…
Reference in a new issue