From e11ec20650e5182f47675210dcd71e7301c34905 Mon Sep 17 00:00:00 2001 From: Zac Date: Wed, 27 Jan 2021 15:48:52 +1000 Subject: [PATCH] StatusBar: Allow GML files to set the number of labels to create --- Userland/Libraries/LibGUI/StatusBar.cpp | 27 +++++++++++++++++++------ Userland/Libraries/LibGUI/StatusBar.h | 9 ++++++++- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/Userland/Libraries/LibGUI/StatusBar.cpp b/Userland/Libraries/LibGUI/StatusBar.cpp index c32b45cf0bc..31db3cb947c 100644 --- a/Userland/Libraries/LibGUI/StatusBar.cpp +++ b/Userland/Libraries/LibGUI/StatusBar.cpp @@ -44,15 +44,15 @@ StatusBar::StatusBar(int label_count) layout()->set_margins({ 0, 0, 0, 0 }); layout()->set_spacing(2); - if (label_count < 1) - label_count = 1; + if (label_count > 0) { + for (auto i = 0; i < label_count; i++) + m_labels.append(create_label()); - for (auto i = 0; i < label_count; i++) - m_labels.append(create_label()); - - m_corner = add(); + m_corner = add(); + } REGISTER_STRING_PROPERTY("text", text, set_text); + REGISTER_INT_PROPERTY("label_count", label_count, set_label_count); } StatusBar::~StatusBar() @@ -104,4 +104,19 @@ void StatusBar::resize_event(ResizeEvent& event) Widget::resize_event(event); } +void StatusBar::set_label_count(int label_count) +{ + ASSERT(m_labels.is_empty()); + m_label_count = label_count; + for (auto i = 0; i < label_count; ++i) { + m_labels.append(create_label()); + } + m_corner = add(); +} + +NonnullRefPtr