make widgets inherit background color, making for a cleaner demo program

This commit is contained in:
hippoz 2022-03-29 09:53:58 +03:00
parent 992ef1e3d6
commit 156d876364
No known key found for this signature in database
GPG key ID: 7C52899193467641
3 changed files with 11 additions and 7 deletions

View file

@ -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);
}
} }

View file

@ -65,7 +65,7 @@ public:
virtual ~Widget() {}; virtual ~Widget() {};
protected: protected:
virtual void on_init() { set_did_init(true); } virtual void on_init();
virtual void on_mouse_button(MouseButtonEvent &event) {} virtual void on_mouse_button(MouseButtonEvent &event) {}
virtual void on_mouse_move(MouseMoveEvent &event) {} virtual void on_mouse_move(MouseMoveEvent &event) {}
virtual void on_focus_update(FocusUpdateEvent &event) {} virtual void on_focus_update(FocusUpdateEvent &event) {}

View file

@ -6,23 +6,20 @@
#include "Label.hpp" #include "Label.hpp"
int main() { int main() {
int times_clicked = 0;
Raven::Window window {}; Raven::Window window {};
Raven::Widget main_widget {}; Raven::Widget main_widget {};
Raven::Button button {"click meeeeeeeeeeee"}; Raven::Button button {"click meeeeeeeeeeee"};
Raven::Label label {"click it!"}; Raven::Label label {"click it!"};
int times_clicked = 0;
window.spawn_window(); window.spawn_window();
button.set_current_geometry(Raven::Box(10, 10, 100, 30)); button.set_current_geometry(Raven::Box(10, 10, 100, 30));
label.set_current_geometry(Raven::Box(10, 45, 100, 20)); 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); window.set_main_widget(&main_widget);
button.on_click = [&label, &times_clicked]() { button.on_click = [&]() {
times_clicked++; times_clicked++;
label.set_text(std::to_string(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(&button);
main_widget.add_child(&label); main_widget.add_child(&label);
window.run(true); window.run(true);
return 0; return 0;
} }