LibGfx+WindowServer: Add theme flag TitleButtonsIconOnly

With this flag set to true only the icon of the title button is painted.
This is useful for themes with a more non-serenity look such as
Coffee and Cupertino (that currently try to hide the button).
This commit is contained in:
MacDue 2022-04-23 15:23:22 +01:00 committed by Linus Groh
parent 5998e7f8a2
commit 9b30fe9864
Notes: sideshowbarker 2024-07-17 11:33:02 +09:00
5 changed files with 27 additions and 5 deletions

View file

@ -143,6 +143,7 @@ public:
Gfx::TextAlignment title_alignment() const { return alignment(AlignmentRole::TitleAlignment); }
bool is_dark() const { return flag(FlagRole::IsDark); }
bool title_buttons_icon_only() const { return flag(FlagRole::TitleButtonsIconOnly); }
int window_border_thickness() const { return metric(MetricRole::BorderThickness); }
int window_border_radius() const { return metric(MetricRole::BorderRadius); }

View file

@ -105,7 +105,8 @@ namespace Gfx {
C(TitleAlignment)
#define ENUMERATE_FLAG_ROLES(C) \
C(IsDark)
C(IsDark) \
C(TitleButtonsIconOnly)
#define ENUMERATE_METRIC_ROLES(C) \
C(BorderThickness) \

View file

@ -27,7 +27,9 @@ void Button::paint(Screen& screen, Gfx::Painter& painter)
auto palette = WindowManager::the().palette();
Gfx::PainterStateSaver saver(painter);
painter.translate(relative_rect().location());
Gfx::StylePainter::paint_button(painter, rect(), palette, Gfx::ButtonStyle::Normal, m_pressed, m_hovered);
if (m_style == Style::Normal)
Gfx::StylePainter::paint_button(painter, rect(), palette, Gfx::ButtonStyle::Normal, m_pressed, m_hovered);
if (m_icon) {
auto& bitmap = m_icon->bitmap(screen.scale_factor());

View file

@ -42,6 +42,13 @@ public:
void set_icon(RefPtr<MultiScaleBitmaps> const& icon) { m_icon = icon; }
enum class Style {
Normal,
IconOnly
};
void set_style(Style style) { m_style = style; }
private:
WindowFrame& m_frame;
Gfx::IntRect m_relative_rect;
@ -49,6 +56,7 @@ private:
bool m_pressed { false };
bool m_visible { true };
bool m_hovered { false };
Style m_style { Style::Normal };
};
}

View file

@ -120,12 +120,22 @@ void WindowFrame::set_button_icons()
if (m_window.is_frameless())
return;
if (m_window.is_closeable())
auto button_style = WindowManager::the().palette().title_buttons_icon_only()
? Button::Style::IconOnly
: Button::Style::Normal;
if (m_window.is_closeable()) {
m_close_button->set_icon(m_window.is_modified() ? *s_close_modified_icon : *s_close_icon);
if (m_window.is_minimizable())
m_close_button->set_style(button_style);
}
if (m_window.is_minimizable()) {
m_minimize_button->set_icon(s_minimize_icon);
if (m_window.is_resizable())
m_minimize_button->set_style(button_style);
}
if (m_window.is_resizable()) {
m_maximize_button->set_icon(m_window.is_maximized() ? *s_restore_icon : *s_maximize_icon);
m_maximize_button->set_style(button_style);
}
}
void WindowFrame::reload_config()