diff options
author | Edgar Araújo <edgararaj@gmail.com> | 2021-03-22 19:51:06 +0000 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-03-29 09:10:23 +0200 |
commit | 532e0090fc84e134f50b5b2bef7ad9c1ce4653ff (patch) | |
tree | 19ff6aaeb6d03d198b7769201f98456e28a62c3f /Userland/Libraries/LibGUI | |
parent | 243d7d9ecf3bef98ec3888b1c18116cb77a19b1d (diff) | |
download | serenity-532e0090fc84e134f50b5b2bef7ad9c1ce4653ff.zip |
LibGUI: Enable the use of font properties through GML
You can now specify the font, font_size, font_weight
and font_type (fixed_width/normal) through GML
Diffstat (limited to 'Userland/Libraries/LibGUI')
-rw-r--r-- | Userland/Libraries/LibGUI/Widget.cpp | 41 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/Widget.h | 6 |
2 files changed, 47 insertions, 0 deletions
diff --git a/Userland/Libraries/LibGUI/Widget.cpp b/Userland/Libraries/LibGUI/Widget.cpp index 32c48254a6..86bf5c8b9f 100644 --- a/Userland/Libraries/LibGUI/Widget.cpp +++ b/Userland/Libraries/LibGUI/Widget.cpp @@ -110,6 +110,24 @@ Widget::Widget() REGISTER_INT_PROPERTY("x", x, set_x); REGISTER_INT_PROPERTY("y", y, set_y); + REGISTER_STRING_PROPERTY("font", m_font->family, set_font_family); + 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_property( + "font_type", [this] { return m_font->is_fixed_width() ? "FixedWidth" : "Normal"; }, + [this](auto& value) { + if (value.to_string() == "FixedWidth") { + set_font_fixed_width(true); + return true; + } + if (value.to_string() == "Normal") { + set_font_fixed_width(false); + return true; + } + return false; + }); + register_property( "focus_policy", [this]() -> JsonValue { auto policy = focus_policy(); @@ -684,6 +702,29 @@ void Widget::set_font(const Gfx::Font* font) update(); } +void Widget::set_font_family(const String& family) +{ + set_font(Gfx::FontDatabase::the().get(family, m_font->presentation_size(), m_font->weight())); +} + +void Widget::set_font_size(unsigned size) +{ + set_font(Gfx::FontDatabase::the().get(m_font->family(), size, m_font->weight())); +} + +void Widget::set_font_weight(unsigned weight) +{ + set_font(Gfx::FontDatabase::the().get(m_font->family(), m_font->presentation_size(), weight)); +} + +void Widget::set_font_fixed_width(bool fixed_width) +{ + if (fixed_width) + set_font(Gfx::FontDatabase::the().get(Gfx::FontDatabase::the().default_fixed_width_font().family(), m_font->presentation_size(), m_font->weight())); + else + set_font(Gfx::FontDatabase::the().get(Gfx::FontDatabase::the().default_font().family(), m_font->presentation_size(), m_font->weight())); +} + void Widget::set_global_cursor_tracking(bool enabled) { auto* win = window(); diff --git a/Userland/Libraries/LibGUI/Widget.h b/Userland/Libraries/LibGUI/Widget.h index 9528dab9af..f9829a1843 100644 --- a/Userland/Libraries/LibGUI/Widget.h +++ b/Userland/Libraries/LibGUI/Widget.h @@ -239,9 +239,15 @@ public: bool fill_with_background_color() const { return m_fill_with_background_color; } const Gfx::Font& font() const { return *m_font; } + void set_font(const Gfx::Font*); void set_font(const Gfx::Font& font) { set_font(&font); } + void set_font_family(const String&); + void set_font_size(unsigned); + void set_font_weight(unsigned); + void set_font_fixed_width(bool); + void set_global_cursor_tracking(bool); bool global_cursor_tracking() const; |