Skip to content

Commit f939fb7

Browse files
committed
Userland: Add a simple GFrame testing window to guitest2.
1 parent 6edcf2f commit f939fb7

File tree

2 files changed

+43
-13
lines changed

2 files changed

+43
-13
lines changed

LibGUI/GFrame.cpp

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,11 @@ void GFrame::paint_event(GPaintEvent& event)
1919
GPainter painter(*this);
2020
painter.set_clip_rect(event.rect());
2121

22-
auto rect = this->rect();
23-
2422
Color top_left_color;
2523
Color bottom_right_color;
26-
27-
Color dark_shade = Color::from_rgb(0x808080);
24+
Color dark_shade = m_shape == Shape::Container ? Color::from_rgb(0x404040) : Color::from_rgb(0x808080);
2825
Color light_shade = Color::from_rgb(0xffffff);
2926

30-
if (m_shape == Shape::Container) {
31-
dark_shade = Color::from_rgb(0x404040);
32-
}
33-
3427
if (m_shadow == Shadow::Raised) {
3528
top_left_color = light_shade;
3629
bottom_right_color = dark_shade;
@@ -42,9 +35,8 @@ void GFrame::paint_event(GPaintEvent& event)
4235
bottom_right_color = dark_shade;
4336
}
4437

45-
painter.draw_line(rect.top_left(), rect.top_right(), top_left_color);
46-
painter.draw_line(rect.bottom_left(), rect.bottom_right(), bottom_right_color);
47-
48-
painter.draw_line(rect.top_left().translated(0, 1), rect.bottom_left().translated(0, -1), top_left_color);
49-
painter.draw_line(rect.top_right(), rect.bottom_right().translated(0, -1), bottom_right_color);
38+
painter.draw_line(rect().top_left(), rect().top_right(), top_left_color);
39+
painter.draw_line(rect().bottom_left(), rect().bottom_right(), bottom_right_color);
40+
painter.draw_line(rect().top_left().translated(0, 1), rect().bottom_left().translated(0, -1), top_left_color);
41+
painter.draw_line(rect().top_right(), rect().bottom_right().translated(0, -1), bottom_right_color);
5042
}

Userland/guitest2.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
static GWindow* make_launcher_window();
2424
static GWindow* make_progress_window();
25+
static GWindow* make_frames_window();
2526

2627
void handle_sigchld(int)
2728
{
@@ -44,6 +45,9 @@ int main(int argc, char** argv)
4445
auto* progress_window = make_progress_window();
4546
progress_window->show();
4647

48+
auto* frames_window = make_frames_window();
49+
frames_window->show();
50+
4751
return app.exec();
4852
}
4953

@@ -149,3 +153,37 @@ static GWindow* make_progress_window()
149153

150154
return window;
151155
}
156+
157+
static GWindow* make_frames_window()
158+
{
159+
auto* window = new GWindow;
160+
window->set_title("GFrame styles test");
161+
window->set_rect({ 100, 400, 240, 80 });
162+
163+
auto* widget = new GWidget;
164+
widget->set_fill_with_background_color(true);
165+
window->set_main_widget(widget);
166+
167+
widget->set_layout(make<GBoxLayout>(Orientation::Vertical));
168+
169+
widget->layout()->set_margins({ 8, 8, 8, 8 });
170+
widget->layout()->set_spacing(8);
171+
172+
auto add_label = [widget] (const String& text, GFrame::Shape shape, GFrame::Shadow shadow) {
173+
auto* label = new GLabel(text, widget);
174+
label->set_size_policy(SizePolicy::Fill, SizePolicy::Fill);
175+
label->set_frame_shape(shape);
176+
label->set_frame_shadow(shadow);
177+
if (shape == GFrame::Shape::Container) {
178+
label->set_fill_with_background_color(true);
179+
label->set_background_color(Color::White);
180+
}
181+
};
182+
183+
add_label("Panel + Raised", GFrame::Shape::Panel, GFrame::Shadow::Raised);
184+
add_label("Panel + Sunken", GFrame::Shape::Panel, GFrame::Shadow::Sunken);
185+
add_label("Container + Raised", GFrame::Shape::Container, GFrame::Shadow::Raised);
186+
add_label("Container + Sunken", GFrame::Shape::Container, GFrame::Shadow::Sunken);
187+
188+
return window;
189+
}

0 commit comments

Comments
 (0)