summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Userland/Libraries/LibCore/Object.h14
-rw-r--r--Userland/Libraries/LibGUI/Widget.cpp41
-rw-r--r--Userland/Libraries/LibGUI/Widget.h6
-rw-r--r--Userland/Libraries/LibGfx/FontDatabase.h15
4 files changed, 76 insertions, 0 deletions
diff --git a/Userland/Libraries/LibCore/Object.h b/Userland/Libraries/LibCore/Object.h
index c3b105aa54..105ca91260 100644
--- a/Userland/Libraries/LibCore/Object.h
+++ b/Userland/Libraries/LibCore/Object.h
@@ -347,4 +347,18 @@ T* Object::find_descendant_of_type_named(const String& name) requires IsBaseOf<O
{ Gfx::TextAlignment::CenterRight, "CenterRight" }, \
{ Gfx::TextAlignment::TopRight, "TopRight" }, \
{ Gfx::TextAlignment::BottomRight, "BottomRight" })
+
+#define REGISTER_FONT_WEIGHT_PROPERTY(property_name, getter, setter) \
+ REGISTER_ENUM_PROPERTY( \
+ property_name, getter, setter, unsigned, \
+ { Gfx::FontWeight::Thin, "Thin" }, \
+ { Gfx::FontWeight::ExtraLight, "ExtraLight" }, \
+ { Gfx::FontWeight::Light, "Light" }, \
+ { Gfx::FontWeight::Regular, "Regular" }, \
+ { Gfx::FontWeight::Medium, "Medium" }, \
+ { Gfx::FontWeight::SemiBold, "SemiBold" }, \
+ { Gfx::FontWeight::Bold, "Bold" }, \
+ { Gfx::FontWeight::ExtraBold, "ExtraBold" }, \
+ { Gfx::FontWeight::Black, "Black" }, \
+ { Gfx::FontWeight::ExtraBlack, "ExtraBlack" })
}
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;
diff --git a/Userland/Libraries/LibGfx/FontDatabase.h b/Userland/Libraries/LibGfx/FontDatabase.h
index 4fb77b1d49..96d0519ae6 100644
--- a/Userland/Libraries/LibGfx/FontDatabase.h
+++ b/Userland/Libraries/LibGfx/FontDatabase.h
@@ -34,6 +34,21 @@
namespace Gfx {
+namespace FontWeight {
+enum {
+ Thin = 100,
+ ExtraLight = 200,
+ Light = 300,
+ Regular = 400,
+ Medium = 500,
+ SemiBold = 600,
+ Bold = 700,
+ ExtraBold = 800,
+ Black = 900,
+ ExtraBlack = 950
+};
+}
+
class FontDatabase {
public:
static FontDatabase& the();