mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 09:30:24 +00:00
StatusBar: Allow GML files to set the number of labels to create
This commit is contained in:
parent
ab9cc49fd8
commit
e11ec20650
Notes:
sideshowbarker
2024-07-18 22:38:36 +09:00
Author: https://github.com/supex0fan Commit: https://github.com/SerenityOS/serenity/commit/e11ec20650e Pull-request: https://github.com/SerenityOS/serenity/pull/5126 Reviewed-by: https://github.com/awesomekling
2 changed files with 29 additions and 7 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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 {};
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue