1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 17:57:35 +00:00

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
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);
}
}