diff options
-rw-r--r-- | Userland/guitest.cpp | 5 | ||||
-rw-r--r-- | Widgets/Button.cpp | 6 | ||||
-rw-r--r-- | Widgets/Label.cpp | 3 | ||||
-rw-r--r-- | Widgets/Painter.cpp | 4 | ||||
-rw-r--r-- | Widgets/Widget.h | 6 |
5 files changed, 10 insertions, 14 deletions
diff --git a/Userland/guitest.cpp b/Userland/guitest.cpp index 80f8102926..597458c635 100644 --- a/Userland/guitest.cpp +++ b/Userland/guitest.cpp @@ -23,8 +23,7 @@ int main(int argc, char** argv) GUI_CreateWidgetParameters label_params; label_params.type = GUI_WidgetType::Label; label_params.rect = { 20, 20, 260, 20 }; - label_params.background_color = 0xffffff; - label_params.opaque = true; + label_params.opaque = false; strcpy(label_params.text, "Hello World!"); int label_id = syscall(SC_gui_create_widget, window_id, &label_params); if (label_id < 0) { @@ -35,8 +34,6 @@ int main(int argc, char** argv) GUI_CreateWidgetParameters button_params; button_params.type = GUI_WidgetType::Button; button_params.rect = { 60, 60, 120, 20 }; - button_params.background_color = 0xffffff; - button_params.opaque = true; strcpy(button_params.text, "I'm a button!"); int button_id = syscall(SC_gui_create_widget, window_id, &button_params); if (button_id < 0) { diff --git a/Widgets/Button.cpp b/Widgets/Button.cpp index 9f6bd54edb..26dc377cd9 100644 --- a/Widgets/Button.cpp +++ b/Widgets/Button.cpp @@ -4,6 +4,7 @@ Button::Button(Widget* parent) : Widget(parent) { + setFillWithBackgroundColor(false); } Button::~Button() @@ -26,11 +27,6 @@ void Button::paintEvent(PaintEvent&) Painter painter(*this); - painter.set_pixel({ 0, 0 }, backgroundColor()); - painter.set_pixel({ width() - 1, 0 }, backgroundColor()); - painter.set_pixel({ 0, height() - 1 }, backgroundColor()); - painter.set_pixel({ width() - 1, height() - 1 }, backgroundColor()); - painter.draw_line({ 1, 0 }, { width() - 2, 0 }, Color::Black); painter.draw_line({ 1, height() - 1 }, { width() - 2, height() - 1}, Color::Black); painter.draw_line({ 0, 1 }, { 0, height() - 2 }, Color::Black); diff --git a/Widgets/Label.cpp b/Widgets/Label.cpp index ac2896b793..3516514dd6 100644 --- a/Widgets/Label.cpp +++ b/Widgets/Label.cpp @@ -21,7 +21,8 @@ void Label::setText(String&& text) void Label::paintEvent(PaintEvent&) { Painter painter(*this); - painter.fill_rect({ 0, 0, width(), height() }, backgroundColor()); + if (fillWithBackgroundColor()) + painter.fill_rect({ 0, 0, width(), height() }, backgroundColor()); if (!text().is_empty()) painter.draw_text({ 4, 4, width(), height() }, text(), Painter::TextAlignment::TopLeft, foregroundColor()); } diff --git a/Widgets/Painter.cpp b/Widgets/Painter.cpp index fbd09f65e4..ac863cb8a2 100644 --- a/Widgets/Painter.cpp +++ b/Widgets/Painter.cpp @@ -25,7 +25,9 @@ Painter::Painter(Widget& widget) m_clip_rect = widget.relativeRect(); #ifdef DEBUG_WIDGET_UNDERDRAW - fill_rect(widget.rect(), Color::Red); + // If the widget is not opaque, let's not mess it up with debugging color. + if (widget.fillWithBackgroundColor()) + fill_rect(widget.rect(), Color::Red); #endif } diff --git a/Widgets/Widget.h b/Widgets/Widget.h index 02176c35d0..f209f169ad 100644 --- a/Widgets/Widget.h +++ b/Widgets/Widget.h @@ -90,10 +90,10 @@ private: Window* m_window { nullptr }; Rect m_relativeRect; - Color m_backgroundColor; - Color m_foregroundColor; + Color m_backgroundColor { 0xffffff }; + Color m_foregroundColor { 0x000000 }; RetainPtr<Font> m_font; bool m_hasPendingPaintEvent { false }; - bool m_fillWithBackgroundColor { false }; + bool m_fillWithBackgroundColor { true }; }; |