Skip to content

Commit 26cc733

Browse files
committed
ThemeEditor: Add window buttons (no bitmaps yet)
1 parent 690c736 commit 26cc733

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

Applications/ThemeEditor/PreviewWidget.cpp

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,36 @@ void PreviewWidget::paint_event(GUI::PaintEvent& event)
118118

119119
painter.fill_rect(frame_inner_rect(), m_preview_palette.desktop_background());
120120

121+
struct Button {
122+
Gfx::IntRect rect;
123+
};
124+
121125
auto paint_window = [&](auto& title, const Gfx::IntRect& rect, auto state, const Gfx::Bitmap& icon) {
122-
Gfx::IntRect leftmost_button_rect { 300, 4, 16, 16 };
123-
Gfx::PainterStateSaver saver(painter);
126+
int window_button_width = m_preview_palette.window_title_button_width();
127+
int window_button_height = m_preview_palette.window_title_button_height();
128+
auto title_bar_text_rect = Gfx::WindowTheme::current().title_bar_text_rect(Gfx::WindowTheme::WindowType::Normal, rect, m_preview_palette);
129+
int pos = title_bar_text_rect.right() + 1;
130+
131+
Vector<Button> buttons;
132+
buttons.append(Button { {} });
133+
buttons.append(Button { {} });
134+
buttons.append(Button { {} });
135+
136+
for (auto& button : buttons) {
137+
pos -= window_button_width;
138+
Gfx::IntRect rect { pos, 0, window_button_width, window_button_height };
139+
rect.center_vertically_within(title_bar_text_rect);
140+
button.rect = rect;
141+
}
142+
124143
auto frame_rect = Gfx::WindowTheme::current().frame_rect_for_window(Gfx::WindowTheme::WindowType::Normal, rect, m_preview_palette);
144+
Gfx::PainterStateSaver saver(painter);
125145
painter.translate(frame_rect.location());
126-
Gfx::WindowTheme::current().paint_normal_frame(painter, state, rect, title, icon, m_preview_palette, leftmost_button_rect);
146+
Gfx::WindowTheme::current().paint_normal_frame(painter, state, rect, title, icon, m_preview_palette, buttons.last().rect);
147+
148+
for (auto& button : buttons) {
149+
Gfx::StylePainter::paint_button(painter, button.rect, m_preview_palette, Gfx::ButtonStyle::Normal, false);
150+
}
127151
};
128152

129153
Gfx::IntRect active_rect { 0, 0, 320, 240 };

0 commit comments

Comments
 (0)