mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 09:38:11 +00:00
LibGUI: Improve GFrame's look for Container shapes.
This is now starting to look like a proper container. Very nice :^)
This commit is contained in:
parent
f939fb7eb7
commit
5d72cf5a3f
7 changed files with 50 additions and 20 deletions
|
@ -3,8 +3,11 @@
|
|||
#include <AK/StringBuilder.h>
|
||||
|
||||
GProgressBar::GProgressBar(GWidget* parent)
|
||||
: GWidget(parent)
|
||||
: GFrame(parent)
|
||||
{
|
||||
set_frame_shape(GFrame::Shape::Container);
|
||||
set_frame_shadow(GFrame::Shadow::Sunken);
|
||||
set_frame_thickness(2);
|
||||
}
|
||||
|
||||
GProgressBar::~GProgressBar()
|
||||
|
@ -32,14 +35,18 @@ void GProgressBar::set_range(int min, int max)
|
|||
|
||||
void GProgressBar::paint_event(GPaintEvent& event)
|
||||
{
|
||||
GFrame::paint_event(event);
|
||||
|
||||
GPainter painter(*this);
|
||||
auto rect = frame_inner_rect();
|
||||
painter.set_clip_rect(rect);
|
||||
painter.set_clip_rect(event.rect());
|
||||
|
||||
// First we fill the entire widget with the gradient. This incurs a bit of
|
||||
// overdraw but ensures a consistent look throughout the progression.
|
||||
Color start_color(110, 34, 9);
|
||||
Color end_color(244, 202, 158);
|
||||
painter.fill_rect_with_gradient(rect(), start_color, end_color);
|
||||
painter.fill_rect_with_gradient(rect, start_color, end_color);
|
||||
|
||||
float range_size = m_max - m_min;
|
||||
float progress = (m_value - m_min) / range_size;
|
||||
|
@ -55,19 +62,14 @@ void GProgressBar::paint_event(GPaintEvent& event)
|
|||
|
||||
auto progress_text = builder.to_string();
|
||||
|
||||
painter.draw_text(rect().translated(1, 1), progress_text, TextAlignment::Center, Color::Black);
|
||||
painter.draw_text(rect(), progress_text, TextAlignment::Center, Color::White);
|
||||
painter.draw_text(rect.translated(1, 1), progress_text, TextAlignment::Center, Color::Black);
|
||||
painter.draw_text(rect, progress_text, TextAlignment::Center, Color::White);
|
||||
|
||||
// Then we carve out a hole in the remaining part of the widget.
|
||||
// We draw the text a third time, clipped and inverse, for sharp contrast.
|
||||
painter.save();
|
||||
float progress_width = progress * width();
|
||||
Rect hole_rect { (int)progress_width, 0, (int)(width() - progress_width), height() };
|
||||
painter.set_clip_rect(hole_rect);
|
||||
painter.fill_rect(hole_rect, Color::White);
|
||||
painter.draw_text(rect().translated(0, 0), progress_text, TextAlignment::Center, Color::Black);
|
||||
painter.restore();
|
||||
|
||||
// Finally, draw a frame around the widget.
|
||||
painter.draw_rect(rect(), Color::Black);
|
||||
painter.draw_text(rect.translated(0, 0), progress_text, TextAlignment::Center, Color::Black);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue