make widgets inherit background color, making for a cleaner demo program
This commit is contained in:
parent
992ef1e3d6
commit
156d876364
3 changed files with 11 additions and 7 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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) {}
|
||||
|
|
10
src/main.cpp
10
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;
|
||||
}
|
Loading…
Reference in a new issue