StatusBar: Allow GML files to set the number of labels to create

This commit is contained in:
Zac 2021-01-27 15:48:52 +10:00 committed by Andreas Kling
parent ab9cc49fd8
commit e11ec20650
Notes: sideshowbarker 2024-07-18 22:38:36 +09:00
2 changed files with 29 additions and 7 deletions

View file

@ -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<ResizeCorner>();
m_corner = add<ResizeCorner>();
}
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<ResizeCorner>();
}
NonnullRefPtr<Label> StatusBar::label(int index) const
{
return m_labels.at(index);
}
}

View file

@ -39,9 +39,10 @@ public:
String text(int index) const;
void set_text(const StringView&);
void set_text(int index, const StringView&);
NonnullRefPtr<Label> label(int index) const;
protected:
explicit StatusBar(int label_count = 1);
explicit StatusBar(int label_count = 0);
virtual void paint_event(PaintEvent&) override;
virtual void resize_event(ResizeEvent&) override;
@ -49,6 +50,12 @@ private:
NonnullRefPtr<Label> create_label();
NonnullRefPtrVector<Label> m_labels;
RefPtr<ResizeCorner> m_corner;
// Used to initialize the number of labels that should
// be created from a GML file as opposed to the constructor.
int label_count() const { return m_label_count; }
void set_label_count(int);
int m_label_count {};
};
}