diff options
author | Timothy Flynn <trflynn89@pm.me> | 2021-05-05 14:04:31 -0400 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-05-05 21:38:45 +0200 |
commit | ee1a4a06e0180432acbc9342e07d9f5156e9ec40 (patch) | |
tree | 60a28340278821273785f1ab0ff4794800854477 | |
parent | b2576b7e457496d27d9a37ffe7cbd9e2c98abab9 (diff) | |
download | serenity-ee1a4a06e0180432acbc9342e07d9f5156e9ec40.zip |
LibGUI: Allow specifying GUI::Statusbar segment count in GML
-rw-r--r-- | Userland/Libraries/LibGUI/Statusbar.cpp | 38 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/Statusbar.h | 2 |
2 files changed, 24 insertions, 16 deletions
diff --git a/Userland/Libraries/LibGUI/Statusbar.cpp b/Userland/Libraries/LibGUI/Statusbar.cpp index e2e180a714..9c989d9266 100644 --- a/Userland/Libraries/LibGUI/Statusbar.cpp +++ b/Userland/Libraries/LibGUI/Statusbar.cpp @@ -24,20 +24,11 @@ Statusbar::Statusbar(int label_count) layout()->set_margins({ 0, 0, 0, 0 }); layout()->set_spacing(2); - if (label_count < 1) - label_count = 1; - - for (auto i = 0; i < label_count; i++) { - m_segments.append(Segment { - .label = create_label(), - .text = {}, - .override_text = {}, - }); - } - m_corner = add<ResizeCorner>(); + set_label_count(label_count); REGISTER_STRING_PROPERTY("text", text, set_text); + REGISTER_INT_PROPERTY("label_count", label_count, set_label_count); } Statusbar::~Statusbar() @@ -46,11 +37,12 @@ Statusbar::~Statusbar() NonnullRefPtr<Label> Statusbar::create_label() { - auto& label = add<Label>(); - label.set_frame_shadow(Gfx::FrameShadow::Sunken); - label.set_frame_shape(Gfx::FrameShape::Panel); - label.set_frame_thickness(1); - label.set_text_alignment(Gfx::TextAlignment::CenterLeft); + auto label = Label::construct(); + insert_child_before(*label, *m_corner); + label->set_frame_shadow(Gfx::FrameShadow::Sunken); + label->set_frame_shape(Gfx::FrameShape::Panel); + label->set_frame_thickness(1); + label->set_text_alignment(Gfx::TextAlignment::CenterLeft); return label; } @@ -70,6 +62,20 @@ void Statusbar::set_text(size_t index, String text) update_label(index); } +void Statusbar::set_label_count(size_t label_count) +{ + if (label_count <= 1) + label_count = 1; + + for (auto i = m_segments.size(); i < label_count; i++) { + m_segments.append(Segment { + .label = create_label(), + .text = {}, + .override_text = {}, + }); + } +} + void Statusbar::update_label(size_t index) { auto& segment = m_segments.at(index); diff --git a/Userland/Libraries/LibGUI/Statusbar.h b/Userland/Libraries/LibGUI/Statusbar.h index 781cf87e29..0f6e5ad5d2 100644 --- a/Userland/Libraries/LibGUI/Statusbar.h +++ b/Userland/Libraries/LibGUI/Statusbar.h @@ -28,6 +28,8 @@ protected: virtual void resize_event(ResizeEvent&) override; private: + size_t label_count() const { return m_segments.size(); } + void set_label_count(size_t label_count); NonnullRefPtr<Label> create_label(); struct Segment { NonnullRefPtr<GUI::Label> label; |