Browse Source

LibGUI: Register a whole bunch of properties in various widgets

AnotherTest 4 years ago
parent
commit
90aeacbb58

+ 1 - 0
Libraries/LibCore/Object.h

@@ -119,6 +119,7 @@ public:
 
     bool set_property(const StringView& name, const JsonValue& value);
     JsonValue property(const StringView& name);
+    const HashMap<String, NonnullOwnPtr<Property>>& properties() const { return m_properties; }
 
     static IntrusiveList<Object, &Object::m_all_objects_list_node>& all_objects();
 

+ 5 - 0
Libraries/LibGUI/Button.cpp

@@ -41,6 +41,11 @@ Button::Button(String text)
     set_min_width(32);
     set_fixed_height(22);
     set_focus_policy(GUI::FocusPolicy::StrongFocus);
+
+    REGISTER_ENUM_PROPERTY(
+        "button_style", button_style, set_button_style, Gfx::ButtonStyle,
+        { Gfx::ButtonStyle::Normal, "Normal" },
+        { Gfx::ButtonStyle::CoolBar, "CoolBar" });
 }
 
 Button::~Button()

+ 3 - 0
Libraries/LibGUI/ColorInput.cpp

@@ -42,6 +42,9 @@ ColorInput::ColorInput()
         if (parsed_color.has_value())
             set_color_without_changing_text(parsed_color.value());
     };
+
+    REGISTER_STRING_PROPERTY("color_picker_title", color_picker_title, set_color_picker_title);
+    REGISTER_BOOL_PROPERTY("has_alpha_channel", has_alpha_channel, set_color_has_alpha_channel);
 }
 
 ColorInput::~ColorInput()

+ 2 - 0
Libraries/LibGUI/Forward.h

@@ -34,6 +34,8 @@ class AbstractView;
 class Action;
 class ActionGroup;
 class Application;
+class AutocompleteBox;
+class AutocompleteProvider;
 class BoxLayout;
 class Button;
 class CheckBox;

+ 13 - 0
Libraries/LibGUI/Frame.cpp

@@ -36,6 +36,19 @@ Frame::Frame()
     set_frame_thickness(2);
     set_frame_shape(Gfx::FrameShape::Container);
     set_frame_shadow(Gfx::FrameShadow::Sunken);
+
+    REGISTER_INT_PROPERTY("thickness", frame_thickness, set_frame_thickness);
+    REGISTER_ENUM_PROPERTY("shadow", frame_shadow, set_frame_shadow, Gfx::FrameShadow,
+        { Gfx::FrameShadow::Plain, "Plain" },
+        { Gfx::FrameShadow::Raised, "Raised" },
+        { Gfx::FrameShadow::Sunken, "Sunken" });
+    REGISTER_ENUM_PROPERTY("shape", frame_shape, set_frame_shape, Gfx::FrameShape,
+        { Gfx::FrameShape::NoFrame, "NoFrame" },
+        { Gfx::FrameShape::Box, "Box" },
+        { Gfx::FrameShape::Container, "Container" },
+        { Gfx::FrameShape::Panel, "Panel" },
+        { Gfx::FrameShape::VerticalLine, "VerticalLine" },
+        { Gfx::FrameShape::HorizontalLine, "HorizontalLine" });
 }
 
 Frame::~Frame()

+ 2 - 7
Libraries/LibGUI/GMLLexer.cpp

@@ -66,11 +66,6 @@ static bool is_valid_identifier_character(char ch)
     return isalnum(ch) || ch == '_';
 }
 
-static bool is_valid_class_start(char ch)
-{
-    return isalpha(ch) || ch == '_';
-}
-
 static bool is_valid_class_character(char ch)
 {
     return isalnum(ch) || ch == '_' || ch == ':';
@@ -138,7 +133,7 @@ Vector<GMLToken> GMLLexer::lex()
             continue;
         }
 
-        if (peek(0) == '@' && is_valid_class_start(peek(1))) {
+        if (peek(0) == '@') {
             consume_class();
             continue;
         }
@@ -160,7 +155,7 @@ Vector<GMLToken> GMLLexer::lex()
             while (isspace(peek()))
                 consume();
 
-            if (peek(0) == '@' && is_valid_class_start(peek(1))) {
+            if (peek(0) == '@') {
                 consume_class();
             } else {
                 begin_token();

+ 1 - 0
Libraries/LibGUI/GroupBox.cpp

@@ -35,6 +35,7 @@ namespace GUI {
 GroupBox::GroupBox(const StringView& title)
     : m_title(title)
 {
+    REGISTER_STRING_PROPERTY("title", title, set_title);
 }
 
 GroupBox::~GroupBox()

+ 3 - 0
Libraries/LibGUI/ImageWidget.cpp

@@ -40,6 +40,9 @@ ImageWidget::ImageWidget(const StringView&)
     set_frame_shadow(Gfx::FrameShadow::Plain);
     set_frame_shape(Gfx::FrameShape::NoFrame);
     set_auto_resize(true);
+
+    REGISTER_BOOL_PROPERTY("auto_resize", auto_resize, set_auto_resize);
+    REGISTER_BOOL_PROPERTY("should_stretch", should_stretch, set_should_stretch);
 }
 
 ImageWidget::~ImageWidget()

+ 6 - 0
Libraries/LibGUI/ProgressBar.cpp

@@ -35,6 +35,12 @@ namespace GUI {
 ProgressBar::ProgressBar()
 {
     REGISTER_STRING_PROPERTY("text", text, set_text);
+    REGISTER_ENUM_PROPERTY("format", format, set_format, Format,
+        { Format::NoText, "NoText" },
+        { Format::Percentage, "Percentage" },
+        { Format::ValueSlashMax, "ValueSlashMax" });
+    REGISTER_INT_PROPERTY("min", min, set_min);
+    REGISTER_INT_PROPERTY("max", max, set_max);
 }
 
 ProgressBar::~ProgressBar()

+ 5 - 0
Libraries/LibGUI/ScrollBar.cpp

@@ -109,6 +109,11 @@ ScrollBar::ScrollBar(Orientation orientation)
     m_automatic_scrolling_timer->on_timeout = [this] {
         on_automatic_scrolling_timer_fired();
     };
+
+    REGISTER_INT_PROPERTY("min", min, set_min);
+    REGISTER_INT_PROPERTY("max", max, set_max);
+    REGISTER_INT_PROPERTY("step", step, set_step);
+    REGISTER_INT_PROPERTY("big_step", big_step, set_big_step);
 }
 
 ScrollBar::~ScrollBar()

+ 18 - 0
Libraries/LibGUI/Slider.cpp

@@ -36,12 +36,30 @@ namespace GUI {
 Slider::Slider(Orientation orientation)
     : m_orientation(orientation)
 {
+
+    REGISTER_INT_PROPERTY("min", min, set_min);
+    REGISTER_INT_PROPERTY("max", max, set_max);
+    REGISTER_INT_PROPERTY("step", step, set_step);
+    REGISTER_ENUM_PROPERTY("knob_size_mode", knob_size_mode, set_knob_size_mode, KnobSizeMode,
+        { KnobSizeMode::Fixed, "Fixed" },
+        { KnobSizeMode::Proportional, "Proportional" });
+    REGISTER_ENUM_PROPERTY("orientation", this->orientation, set_orientation, Orientation,
+        { Orientation::Horizontal, "Horizontal" },
+        { Orientation::Vertical, "Vertical" });
 }
 
 Slider::~Slider()
 {
 }
 
+void Slider::set_orientation(Orientation value)
+{
+    if (m_orientation == value)
+        return;
+    m_orientation = value;
+    update();
+}
+
 void Slider::set_range(int min, int max)
 {
     ASSERT(min <= max);

+ 1 - 0
Libraries/LibGUI/Slider.h

@@ -40,6 +40,7 @@ public:
 
     virtual ~Slider() override;
 
+    void set_orientation(Orientation value);
     Orientation orientation() const { return m_orientation; }
 
     int value() const { return m_value; }

+ 3 - 0
Libraries/LibGUI/SpinBox.cpp

@@ -58,6 +58,9 @@ SpinBox::SpinBox()
     m_decrement_button->set_focus_policy(GUI::FocusPolicy::NoFocus);
     m_decrement_button->on_click = [this](auto) { set_value(m_value - 1); };
     m_decrement_button->set_auto_repeat_interval(150);
+
+    REGISTER_INT_PROPERTY("min", min, set_min);
+    REGISTER_INT_PROPERTY("max", max, set_max);
 }
 
 SpinBox::~SpinBox()

+ 2 - 0
Libraries/LibGUI/StatusBar.cpp

@@ -49,6 +49,8 @@ StatusBar::StatusBar(int label_count)
         m_labels.append(create_label());
 
     m_corner = add<ResizeCorner>();
+
+    REGISTER_STRING_PROPERTY("text", text, set_text);
 }
 
 StatusBar::~StatusBar()