mirror of
https://github.com/RGBCube/serenity
synced 2025-07-15 05:37:34 +00:00
LibGUI: Make button icons settable in GML
`Widget::load_from_gml()` doesn't yet return `ErrorOr`, so we log a warning message if loading the icon fails.
This commit is contained in:
parent
49011e2030
commit
dd17df76e9
2 changed files with 13 additions and 0 deletions
|
@ -29,6 +29,8 @@ Button::Button(String text)
|
||||||
"button_style", button_style, set_button_style, Gfx::ButtonStyle,
|
"button_style", button_style, set_button_style, Gfx::ButtonStyle,
|
||||||
{ Gfx::ButtonStyle::Normal, "Normal" },
|
{ Gfx::ButtonStyle::Normal, "Normal" },
|
||||||
{ Gfx::ButtonStyle::Coolbar, "Coolbar" });
|
{ Gfx::ButtonStyle::Coolbar, "Coolbar" });
|
||||||
|
|
||||||
|
REGISTER_STRING_PROPERTY("icon", icon, set_icon_from_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
Button::~Button()
|
Button::~Button()
|
||||||
|
@ -140,6 +142,16 @@ void Button::set_icon(RefPtr<Gfx::Bitmap>&& icon)
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Button::set_icon_from_path(String const& path)
|
||||||
|
{
|
||||||
|
auto maybe_bitmap = Gfx::Bitmap::try_load_from_file(path);
|
||||||
|
if (maybe_bitmap.is_error()) {
|
||||||
|
dbgln("Unable to load bitmap `{}` for button icon", path);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
set_icon(maybe_bitmap.release_value());
|
||||||
|
}
|
||||||
|
|
||||||
bool Button::is_uncheckable() const
|
bool Button::is_uncheckable() const
|
||||||
{
|
{
|
||||||
if (!m_action)
|
if (!m_action)
|
||||||
|
|
|
@ -21,6 +21,7 @@ public:
|
||||||
virtual ~Button() override;
|
virtual ~Button() override;
|
||||||
|
|
||||||
void set_icon(RefPtr<Gfx::Bitmap>&&);
|
void set_icon(RefPtr<Gfx::Bitmap>&&);
|
||||||
|
void set_icon_from_path(String const&);
|
||||||
const Gfx::Bitmap* icon() const { return m_icon.ptr(); }
|
const Gfx::Bitmap* icon() const { return m_icon.ptr(); }
|
||||||
Gfx::Bitmap* icon() { return m_icon.ptr(); }
|
Gfx::Bitmap* icon() { return m_icon.ptr(); }
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue