test many widgets at the same time
This commit is contained in:
parent
3039646b6b
commit
fcb4556a4e
4 changed files with 21 additions and 20 deletions
|
@ -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<void()> on_click { [](){} };
|
||||
protected:
|
||||
WidgetType m_type { WidgetType::Button };
|
||||
|
||||
void on_paint();
|
||||
void on_init();
|
||||
void on_focus_update(FocusUpdateEvent &event);
|
||||
|
|
|
@ -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();
|
||||
};
|
||||
|
|
|
@ -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<typename T, class... Args>
|
||||
std::shared_ptr<T> add_child(Args&&... args) {
|
||||
std::shared_ptr<T> add(Args&&... args) {
|
||||
std::shared_ptr<T> child = std::make_shared<T>(std::forward<Args>(args)...);
|
||||
add_child(child);
|
||||
return child;
|
||||
|
|
24
src/main.cpp
24
src/main.cpp
|
@ -6,6 +6,9 @@
|
|||
#include "Label.hpp"
|
||||
#include "Layout.hpp"
|
||||
#include "src/DocumentLayout.hpp"
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
int main() {
|
||||
Raven::Window window {};
|
||||
|
@ -13,22 +16,21 @@ int main() {
|
|||
auto main_widget = window.set_main_widget<Raven::Widget>();
|
||||
main_widget->set_layout<Raven::DocumentLayout>(6.0);
|
||||
|
||||
auto add_button = main_widget->add_child<Raven::Button>("add");
|
||||
auto subtract_button = main_widget->add_child<Raven::Button>("subtract");
|
||||
main_widget->add_child<Raven::Widget>(Raven::ControlWidgetType::NewRow);
|
||||
auto label = main_widget->add_child<Raven::Label>("0");
|
||||
|
||||
int number = 0;
|
||||
|
||||
add_button->on_click = [&]() {
|
||||
for (int i = 0; i < 100; i++) {
|
||||
auto button = main_widget->add<Raven::Button>("0");
|
||||
button->on_click = [&]() {
|
||||
number++;
|
||||
label->set_text(std::to_string(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<Raven::Button>(c);
|
||||
button_child->set_text(std::to_string(number));
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
window.spawn_window();
|
||||
window.run(true);
|
||||
|
|
Loading…
Reference in a new issue