add a simpler example program
This commit is contained in:
parent
c96fc98f37
commit
2a5ae1f100
1 changed files with 22 additions and 27 deletions
49
src/main.cpp
49
src/main.cpp
|
@ -11,45 +11,40 @@
|
||||||
#include "src/Styles.hpp"
|
#include "src/Styles.hpp"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
void update_count_label_text(std::shared_ptr<Raven::Label> label, int number) {
|
||||||
|
std::stringstream text;
|
||||||
|
text << "you have clicked the button " << std::to_string(number) << " times";
|
||||||
|
label->set_text(text.str());
|
||||||
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
Raven::Window window {};
|
Raven::Window window {};
|
||||||
|
int number = 0;
|
||||||
|
|
||||||
window.spawn_window();
|
window.spawn_window();
|
||||||
|
|
||||||
auto main_widget = window.set_main_widget<Raven::Widget>();
|
auto main_widget = window.set_main_widget<Raven::Widget>();
|
||||||
main_widget->set_layout<Raven::DocumentLayout>(10.0);
|
main_widget->set_layout<Raven::DocumentLayout>(10.0);
|
||||||
|
|
||||||
auto second_widget = main_widget->add<Raven::Widget>();
|
auto count_label = main_widget->add<Raven::Label>("you have clicked the button 0 times");
|
||||||
second_widget->set_layout<Raven::DocumentLayout>(20.0);
|
|
||||||
second_widget->resize(800, 800);
|
|
||||||
|
|
||||||
auto inner_widget = second_widget->add<Raven::Widget>();
|
main_widget->add<Raven::Widget>(Raven::ControlWidgetType::NewRow);
|
||||||
inner_widget->set_layout<Raven::DocumentLayout>(8.0);
|
|
||||||
inner_widget->resize(600, 600);
|
|
||||||
|
|
||||||
int number = 0;
|
auto increment_button = main_widget->add<Raven::Button>("click me");
|
||||||
|
increment_button->set_style(&Raven::accent_button_style);
|
||||||
for (int i = 0; i < 250; i++) {
|
increment_button->on_click = [&]() {
|
||||||
auto button = inner_widget->add<Raven::Button>("click me");
|
number++;
|
||||||
button->set_style(&Raven::accent_button_style);
|
update_count_label_text(count_label, number);
|
||||||
auto label = inner_widget->add<Raven::Label>("click one of the buttons!");
|
};
|
||||||
button->on_click = [&]() {
|
|
||||||
number += 10;
|
auto reset_button = main_widget->add<Raven::Button>("reset");
|
||||||
|
reset_button->on_click = [&]() {
|
||||||
window.start_batch();
|
number = 0;
|
||||||
auto& children = inner_widget->children();
|
update_count_label_text(count_label, number);
|
||||||
for (auto& child : children) {
|
|
||||||
if (child->type() == Raven::WidgetType::Button) {
|
|
||||||
std::static_pointer_cast<Raven::Button>(child)->set_text(std::to_string(number));
|
|
||||||
}
|
|
||||||
if (child->type() == Raven::WidgetType::Label) {
|
|
||||||
std::static_pointer_cast<Raven::Label>(child)->set_text(std::to_string(number));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
window.end_batch();
|
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
window.run(true);
|
window.run(true);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in a new issue