diff --git a/src/Button.hpp b/src/Button.hpp index 3b880ad..38292c0 100644 --- a/src/Button.hpp +++ b/src/Button.hpp @@ -14,7 +14,7 @@ private: std::string m_text; public: Button(std::string text) - : Widget() + : Widget(WidgetType::Button) , m_text(text) {} void set_text(std::string text) { m_text = text; wants_repaint(); } @@ -22,8 +22,6 @@ public: std::function on_click { [](){} }; protected: - WidgetType m_type { WidgetType::Button }; - void on_paint(); void on_init(); void on_focus_update(FocusUpdateEvent &event); diff --git a/src/Label.hpp b/src/Label.hpp index 6cf6ad5..4665a9f 100644 --- a/src/Label.hpp +++ b/src/Label.hpp @@ -10,7 +10,7 @@ private: std::string m_text; public: Label(std::string text) - : Widget() + : Widget(WidgetType::Label) , m_text(text) {} ~Label() {} @@ -18,8 +18,6 @@ public: std::string &text() { return m_text; } void set_text(std::string text) { m_text = text; wants_repaint(); } protected: - WidgetType m_type { WidgetType::Label }; - void on_paint(); void on_init(); }; diff --git a/src/Widget.hpp b/src/Widget.hpp index 2675932..7d36dd1 100644 --- a/src/Widget.hpp +++ b/src/Widget.hpp @@ -48,6 +48,9 @@ private: public: Widget() {} + Widget(WidgetType type) + : m_type(type) {} + Widget(ControlWidgetType type) : m_control_type(type) { m_type = WidgetType::Control; @@ -107,7 +110,7 @@ public: } template - std::shared_ptr add_child(Args&&... args) { + std::shared_ptr add(Args&&... args) { std::shared_ptr child = std::make_shared(std::forward(args)...); add_child(child); return child; diff --git a/src/main.cpp b/src/main.cpp index 1faa54a..56caa7d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,6 +6,9 @@ #include "Label.hpp" #include "Layout.hpp" #include "src/DocumentLayout.hpp" +#include +#include +#include int main() { Raven::Window window {}; @@ -13,22 +16,21 @@ int main() { auto main_widget = window.set_main_widget(); main_widget->set_layout(6.0); - auto add_button = main_widget->add_child("add"); - auto subtract_button = main_widget->add_child("subtract"); - main_widget->add_child(Raven::ControlWidgetType::NewRow); - auto label = main_widget->add_child("0"); - int number = 0; - add_button->on_click = [&]() { - number++; - label->set_text(std::to_string(number)); - }; + for (int i = 0; i < 100; i++) { + auto button = main_widget->add("0"); + button->on_click = [&]() { + number++; - subtract_button->on_click = [&]() { - number--; - label->set_text(std::to_string(number)); - }; + for (auto& c : main_widget->children()) { + if (c->type() == Raven::WidgetType::Button) { + auto button_child = std::static_pointer_cast(c); + button_child->set_text(std::to_string(number)); + } + } + }; + } window.spawn_window(); window.run(true);