浏览代码

Userland: Add a simple GFrame testing window to guitest2.

Andreas Kling 6 年之前
父节点
当前提交
f939fb7eb7
共有 2 个文件被更改,包括 43 次插入13 次删除
  1. 5 13
      LibGUI/GFrame.cpp
  2. 38 0
      Userland/guitest2.cpp

+ 5 - 13
LibGUI/GFrame.cpp

@@ -19,18 +19,11 @@ void GFrame::paint_event(GPaintEvent& event)
     GPainter painter(*this);
     painter.set_clip_rect(event.rect());
 
-    auto rect = this->rect();
-
     Color top_left_color;
     Color bottom_right_color;
-
-    Color dark_shade = Color::from_rgb(0x808080);
+    Color dark_shade = m_shape == Shape::Container ? Color::from_rgb(0x404040) : Color::from_rgb(0x808080);
     Color light_shade = Color::from_rgb(0xffffff);
 
-    if (m_shape == Shape::Container) {
-        dark_shade = Color::from_rgb(0x404040);
-    }
-
     if (m_shadow == Shadow::Raised) {
         top_left_color = light_shade;
         bottom_right_color = dark_shade;
@@ -42,9 +35,8 @@ void GFrame::paint_event(GPaintEvent& event)
         bottom_right_color = dark_shade;
     }
 
-    painter.draw_line(rect.top_left(), rect.top_right(), top_left_color);
-    painter.draw_line(rect.bottom_left(), rect.bottom_right(), bottom_right_color);
-
-    painter.draw_line(rect.top_left().translated(0, 1), rect.bottom_left().translated(0, -1), top_left_color);
-    painter.draw_line(rect.top_right(), rect.bottom_right().translated(0, -1), bottom_right_color);
+    painter.draw_line(rect().top_left(), rect().top_right(), top_left_color);
+    painter.draw_line(rect().bottom_left(), rect().bottom_right(), bottom_right_color);
+    painter.draw_line(rect().top_left().translated(0, 1), rect().bottom_left().translated(0, -1), top_left_color);
+    painter.draw_line(rect().top_right(), rect().bottom_right().translated(0, -1), bottom_right_color);
 }

+ 38 - 0
Userland/guitest2.cpp

@@ -22,6 +22,7 @@
 
 static GWindow* make_launcher_window();
 static GWindow* make_progress_window();
+static GWindow* make_frames_window();
 
 void handle_sigchld(int)
 {
@@ -44,6 +45,9 @@ int main(int argc, char** argv)
     auto* progress_window = make_progress_window();
     progress_window->show();
 
+    auto* frames_window = make_frames_window();
+    frames_window->show();
+
     return app.exec();
 }
 
@@ -149,3 +153,37 @@ static GWindow* make_progress_window()
 
     return window;
 }
+
+static GWindow* make_frames_window()
+{
+    auto* window = new GWindow;
+    window->set_title("GFrame styles test");
+    window->set_rect({ 100, 400, 240, 80 });
+
+    auto* widget = new GWidget;
+    widget->set_fill_with_background_color(true);
+    window->set_main_widget(widget);
+
+    widget->set_layout(make<GBoxLayout>(Orientation::Vertical));
+
+    widget->layout()->set_margins({ 8, 8, 8, 8 });
+    widget->layout()->set_spacing(8);
+
+    auto add_label = [widget] (const String& text, GFrame::Shape shape, GFrame::Shadow shadow) {
+        auto* label = new GLabel(text, widget);
+        label->set_size_policy(SizePolicy::Fill, SizePolicy::Fill);
+        label->set_frame_shape(shape);
+        label->set_frame_shadow(shadow);
+        if (shape == GFrame::Shape::Container) {
+            label->set_fill_with_background_color(true);
+            label->set_background_color(Color::White);
+        }
+    };
+
+    add_label("Panel + Raised", GFrame::Shape::Panel, GFrame::Shadow::Raised);
+    add_label("Panel + Sunken", GFrame::Shape::Panel, GFrame::Shadow::Sunken);
+    add_label("Container + Raised", GFrame::Shape::Container, GFrame::Shadow::Raised);
+    add_label("Container + Sunken", GFrame::Shape::Container, GFrame::Shadow::Sunken);
+
+    return window;
+}