mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:57:45 +00:00
LibGfx+LibGUI: Add support for vertical ProgressBars
This commit is contained in:
parent
bd34cdbbb3
commit
5806630cf4
7 changed files with 60 additions and 13 deletions
|
@ -309,13 +309,13 @@ void ClassicStylePainter::paint_window_frame(Painter& painter, const IntRect& re
|
|||
painter.draw_line(rect.bottom_left().translated(3, -3), rect.bottom_right().translated(-3, -3), base_color);
|
||||
}
|
||||
|
||||
void ClassicStylePainter::paint_progress_bar(Painter& painter, const IntRect& rect, const Palette& palette, int min, int max, int value, const StringView& text)
|
||||
void ClassicStylePainter::paint_progress_bar(Painter& painter, const IntRect& rect, const Palette& palette, int min, int max, int value, const StringView& text, Orientation orientation)
|
||||
{
|
||||
// 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 = palette.active_window_border1();
|
||||
Color end_color = palette.active_window_border2();
|
||||
painter.fill_rect_with_gradient(rect, start_color, end_color);
|
||||
painter.fill_rect_with_gradient(orientation, rect, start_color, end_color);
|
||||
|
||||
if (!text.is_null()) {
|
||||
painter.draw_text(rect.translated(1, 1), text, TextAlignment::Center, palette.base_text());
|
||||
|
@ -327,8 +327,14 @@ void ClassicStylePainter::paint_progress_bar(Painter& painter, const IntRect& re
|
|||
|
||||
// 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.
|
||||
float progress_width = progress * rect.width();
|
||||
IntRect hole_rect { (int)progress_width, 0, (int)(rect.width() - progress_width), rect.height() };
|
||||
IntRect hole_rect;
|
||||
if (orientation == Orientation::Horizontal) {
|
||||
float progress_width = progress * rect.width();
|
||||
hole_rect = { (int)progress_width, 0, (int)(rect.width() - progress_width), rect.height() };
|
||||
} else {
|
||||
float progress_height = progress * rect.height();
|
||||
hole_rect = { 0, 0, rect.width(), (int)(rect.height() - progress_height) };
|
||||
}
|
||||
hole_rect.move_by(rect.location());
|
||||
hole_rect.set_right_without_resize(rect.right());
|
||||
PainterStateSaver saver(painter);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue