mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 00:50:22 +00:00
LibGUI: Register a whole bunch of properties in various widgets
This commit is contained in:
parent
20b74e4ede
commit
90aeacbb58
Notes:
sideshowbarker
2024-07-19 00:23:50 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/90aeacbb582 Pull-request: https://github.com/SerenityOS/serenity/pull/4652 Reviewed-by: https://github.com/awesomekling
14 changed files with 65 additions and 7 deletions
|
@ -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();
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -34,6 +34,8 @@ class AbstractView;
|
|||
class Action;
|
||||
class ActionGroup;
|
||||
class Application;
|
||||
class AutocompleteBox;
|
||||
class AutocompleteProvider;
|
||||
class BoxLayout;
|
||||
class Button;
|
||||
class CheckBox;
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -35,6 +35,7 @@ namespace GUI {
|
|||
GroupBox::GroupBox(const StringView& title)
|
||||
: m_title(title)
|
||||
{
|
||||
REGISTER_STRING_PROPERTY("title", title, set_title);
|
||||
}
|
||||
|
||||
GroupBox::~GroupBox()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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; }
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue