Implement property declarations for the C++ backend

This commit is contained in:
Simon Hausmann 2020-05-25 19:13:52 +02:00
parent 5a7a95dbc8
commit 0932953ac8
4 changed files with 88 additions and 13 deletions

View file

@ -77,7 +77,8 @@ Hello := Rectangle {
color: black;
}
}
counter := Text { x: 100; y: 300; text: "0"; color: black; }
property<int32> counter;
counter_label := Text { x: 100; y: 300; text: "0"; color: black; }
ButtonRectangle {
color: 4289374890;
x: 50;

View file

@ -4,24 +4,24 @@
int main() {
static Hello component;
static int counter = 0;
component._foobar.set_handler([](auto...){
std::cout << "Hello from C++" << std::endl;
});
component._plus_clicked.set_handler([](auto...){
counter += 1;
auto &counter = component.property_0_counter;
counter.set(counter.get() + 1);
// FIXME: this _13 is an internal detail and should be private anyway. We muse use some
// alias or way to expose the property (same for the _ before signals)
component.counter_13.text.set(std::string_view(std::to_string(counter)));
std::cout << "PLUS: " << std::string_view(component.counter_13.text.get()) << std::endl;
component.counter_label_13.text.set(std::string_view(std::to_string(counter.get())));
std::cout << "PLUS: " << std::string_view(component.counter_label_13.text.get()) << std::endl;
});
component._minus_clicked.set_handler([](auto...){
counter -= 1;
component.counter_13.text.set(std::string_view(std::to_string(counter)));
std::cout << "MINUS: " << std::string_view(component.counter_13.text.get()) << std::endl;
auto &counter = component.property_0_counter;
counter.set(counter.get() - 1);
component.counter_label_13.text.set(std::string_view(std::to_string(counter.get())));
std::cout << "MINUS: " << std::string_view(component.counter_label_13.text.get()) << std::endl;
});
sixtyfps::run(&component);