mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 06:27:45 +00:00
WindowServer+LibGUI+Taskbar: Store window progress as Optional<int>
We were previously using the magical constant -1 to signify that a window had no progress state. Be more explicit an use an Optional. :^)
This commit is contained in:
parent
8af7cda17a
commit
cc6db526a6
9 changed files with 20 additions and 21 deletions
|
@ -103,8 +103,6 @@ void TaskbarButton::paint_event(GUI::PaintEvent& event)
|
|||
if (text().is_empty())
|
||||
return;
|
||||
|
||||
bool has_progress = window.progress() >= 0 && window.progress() <= 100;
|
||||
|
||||
auto content_rect = rect().shrunken(8, 2);
|
||||
auto icon_location = content_rect.center().translated(-(icon.width() / 2), -(icon.height() / 2));
|
||||
if (!text().is_empty())
|
||||
|
@ -125,12 +123,12 @@ void TaskbarButton::paint_event(GUI::PaintEvent& event)
|
|||
icon_location.move_by(1, 1);
|
||||
}
|
||||
|
||||
if (has_progress) {
|
||||
if (window.progress().has_value()) {
|
||||
auto adjusted_rect = rect().shrunken(4, 4);
|
||||
if (is_being_pressed() || is_checked()) {
|
||||
adjusted_rect.set_height(adjusted_rect.height() + 1);
|
||||
}
|
||||
paint_custom_progressbar(painter, adjusted_rect, text_rect, palette(), 0, 100, window.progress(), text(), font, text_alignment());
|
||||
paint_custom_progressbar(painter, adjusted_rect, text_rect, palette(), 0, 100, window.progress().value(), text(), font, text_alignment());
|
||||
}
|
||||
|
||||
if (is_enabled()) {
|
||||
|
@ -142,6 +140,6 @@ void TaskbarButton::paint_event(GUI::PaintEvent& event)
|
|||
painter.blit_disabled(icon_location, icon, icon.rect(), palette());
|
||||
}
|
||||
|
||||
if (!has_progress)
|
||||
if (!window.progress().has_value())
|
||||
paint_text(painter, text_rect, font, text_alignment());
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ public:
|
|||
void set_modal(bool modal) { m_modal = modal; }
|
||||
bool is_modal() const { return m_modal; }
|
||||
|
||||
void set_progress(int progress)
|
||||
void set_progress(Optional<int> progress)
|
||||
{
|
||||
if (m_progress == progress)
|
||||
return;
|
||||
|
@ -57,7 +57,7 @@ public:
|
|||
m_button->update();
|
||||
}
|
||||
|
||||
int progress() const { return m_progress; }
|
||||
Optional<int> progress() const { return m_progress; }
|
||||
|
||||
const Gfx::Bitmap* icon() const { return m_icon.ptr(); }
|
||||
|
||||
|
@ -71,7 +71,7 @@ private:
|
|||
bool m_active { false };
|
||||
bool m_minimized { false };
|
||||
bool m_modal { false };
|
||||
int m_progress { -1 };
|
||||
Optional<int> m_progress;
|
||||
};
|
||||
|
||||
class WindowList {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue