From 156d8763646af0e46eb8e1aa69c0855302697f72 Mon Sep 17 00:00:00 2001 From: hippoz <10706925-hippoz@users.noreply.gitlab.com> Date: Tue, 29 Mar 2022 09:53:58 +0300 Subject: [PATCH] make widgets inherit background color, making for a cleaner demo program --- src/Widget.cpp | 6 ++++++ src/Widget.hpp | 2 +- src/main.cpp | 10 ++++------ 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/Widget.cpp b/src/Widget.cpp index 45e4f60..083df8e 100644 --- a/src/Widget.cpp +++ b/src/Widget.cpp @@ -160,4 +160,10 @@ void Widget::dispatch_event(Event &event) { } } +void Widget::on_init() { + set_background_fill_color(get_styles()->get_background_color()); + set_do_background_fill(true); + set_did_init(true); +} + } \ No newline at end of file diff --git a/src/Widget.hpp b/src/Widget.hpp index 419acd1..e7fe5cd 100644 --- a/src/Widget.hpp +++ b/src/Widget.hpp @@ -65,7 +65,7 @@ public: virtual ~Widget() {}; protected: - virtual void on_init() { set_did_init(true); } + virtual void on_init(); virtual void on_mouse_button(MouseButtonEvent &event) {} virtual void on_mouse_move(MouseMoveEvent &event) {} virtual void on_focus_update(FocusUpdateEvent &event) {} diff --git a/src/main.cpp b/src/main.cpp index 9bc0d9c..60e5bad 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,23 +6,20 @@ #include "Label.hpp" int main() { - int times_clicked = 0; - Raven::Window window {}; Raven::Widget main_widget {}; Raven::Button button {"click meeeeeeeeeeee"}; Raven::Label label {"click it!"}; + int times_clicked = 0; + window.spawn_window(); button.set_current_geometry(Raven::Box(10, 10, 100, 30)); label.set_current_geometry(Raven::Box(10, 45, 100, 20)); - - main_widget.set_background_fill_color(window.get_top_level_styles()->get_background_color()); - main_widget.set_do_background_fill(true); window.set_main_widget(&main_widget); - button.on_click = [&label, ×_clicked]() { + button.on_click = [&]() { times_clicked++; label.set_text(std::to_string(times_clicked)); }; @@ -30,6 +27,7 @@ int main() { main_widget.add_child(&button); main_widget.add_child(&label); + window.run(true); return 0; } \ No newline at end of file