Parcourir la source

LibGUI: Add direct property for fixed-width font

There's the "font_type" property which currently only handles
fixed-width yes/no, so until we get a proper font type enum and
associated enum property, this is better to use from GML instead of a
special case in the GML compiler.
kleines Filmröllchen il y a 2 ans
Parent
commit
2e46e33a9b
2 fichiers modifiés avec 7 ajouts et 0 suppressions
  1. 6 0
      Userland/Libraries/LibGUI/Widget.cpp
  2. 1 0
      Userland/Libraries/LibGUI/Widget.h

+ 6 - 0
Userland/Libraries/LibGUI/Widget.cpp

@@ -88,6 +88,7 @@ Widget::Widget()
 
 
     REGISTER_STRING_PROPERTY("title", title, set_title);
     REGISTER_STRING_PROPERTY("title", title, set_title);
 
 
+    REGISTER_BOOL_PROPERTY("font_fixed_width", is_font_fixed_width, set_font_fixed_width)
     register_property(
     register_property(
         "font_type", [this] { return m_font->is_fixed_width() ? "FixedWidth" : "Normal"; },
         "font_type", [this] { return m_font->is_fixed_width() ? "FixedWidth" : "Normal"; },
         [this](auto& value) {
         [this](auto& value) {
@@ -841,6 +842,11 @@ void Widget::set_font_fixed_width(bool fixed_width)
         set_font(Gfx::FontDatabase::the().get(Gfx::FontDatabase::the().default_font().family(), m_font->presentation_size(), m_font->weight(), m_font->width(), m_font->slope()));
         set_font(Gfx::FontDatabase::the().get(Gfx::FontDatabase::the().default_font().family(), m_font->presentation_size(), m_font->weight(), m_font->width(), m_font->slope()));
 }
 }
 
 
+bool Widget::is_font_fixed_width()
+{
+    return font().is_fixed_width();
+}
+
 void Widget::set_min_size(UISize const& size)
 void Widget::set_min_size(UISize const& size)
 {
 {
     VERIFY(size.width().is_one_of(SpecialDimension::Regular, SpecialDimension::Shrink));
     VERIFY(size.width().is_one_of(SpecialDimension::Regular, SpecialDimension::Shrink));

+ 1 - 0
Userland/Libraries/LibGUI/Widget.h

@@ -295,6 +295,7 @@ public:
     void set_font_size(unsigned);
     void set_font_size(unsigned);
     void set_font_weight(unsigned);
     void set_font_weight(unsigned);
     void set_font_fixed_width(bool);
     void set_font_fixed_width(bool);
+    bool is_font_fixed_width();
 
 
     void notify_layout_changed(Badge<Layout>);
     void notify_layout_changed(Badge<Layout>);
     void invalidate_layout();
     void invalidate_layout();