1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 03:07:36 +00:00

LibGfx+LibGUI: Add support for vertical ProgressBars

This commit is contained in:
thankyouverycool 2021-03-07 17:39:01 -05:00 committed by Andreas Kling
parent bd34cdbbb3
commit 5806630cf4
7 changed files with 60 additions and 13 deletions

View file

@ -31,10 +31,13 @@
#include <LibGfx/Palette.h>
REGISTER_WIDGET(GUI, ProgressBar)
REGISTER_WIDGET(GUI, VerticalProgressBar)
REGISTER_WIDGET(GUI, HorizontalProgressBar)
namespace GUI {
ProgressBar::ProgressBar()
ProgressBar::ProgressBar(Orientation orientation)
: m_orientation(orientation)
{
REGISTER_STRING_PROPERTY("text", text, set_text);
REGISTER_ENUM_PROPERTY("format", format, set_format, Format,
@ -90,7 +93,15 @@ void ProgressBar::paint_event(PaintEvent& event)
progress_text = builder.to_string();
}
Gfx::StylePainter::paint_progress_bar(painter, rect, palette(), m_min, m_max, m_value, progress_text);
Gfx::StylePainter::paint_progress_bar(painter, rect, palette(), m_min, m_max, m_value, progress_text, m_orientation);
}
void ProgressBar::set_orientation(Orientation value)
{
if (m_orientation == value)
return;
m_orientation = value;
update();
}
}

View file

@ -44,6 +44,9 @@ public:
int min() const { return m_min; }
int max() const { return m_max; }
void set_orientation(Orientation value);
Orientation orientation() const { return m_orientation; }
String text() const { return m_text; }
void set_text(String text) { m_text = move(text); }
@ -56,7 +59,7 @@ public:
void set_format(Format format) { m_format = format; }
protected:
ProgressBar();
ProgressBar(Orientation = Orientation::Horizontal);
virtual void paint_event(PaintEvent&) override;
@ -66,6 +69,33 @@ private:
int m_max { 100 };
int m_value { 0 };
String m_text;
Orientation m_orientation { Orientation::Horizontal };
};
class VerticalProgressBar final : public ProgressBar {
C_OBJECT(VerticalProgressBar);
public:
virtual ~VerticalProgressBar() override { }
private:
VerticalProgressBar()
: ProgressBar(Orientation::Vertical)
{
}
};
class HorizontalProgressBar final : public ProgressBar {
C_OBJECT(HorizontalProgressBar);
public:
virtual ~HorizontalProgressBar() override { }
private:
HorizontalProgressBar()
: ProgressBar(Orientation::Horizontal)
{
}
};
}