Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct State
- {
- State()
- : counter(0)
- {
- }
- State with_counter(int counter) const
- {
- State copy(*this);
- copy.counter = counter;
- return copy;
- }
- const char *get_button_text() const
- {
- static char string[100];
- sprintf(string, "Value: %d", counter);
- return string;
- }
- int counter;
- };
- struct MyApplication : public Application<MyApplication, State, DefaultStyle>
- {
- static State increment_counter(const State &state)
- {
- return state.with_counter(state.counter + 1);
- }
- static State decrement_counter(const State &state)
- {
- return state.with_counter(state.counter - 1);
- }
- static auto layout(const State &state)
- {
- return Rectangle
- {
- Button
- {
- position = SDL_Point { 120, 100 - state.counter * 5 },
- size = SDL_Point { 100, 30 },
- on_clicked = &decrement_counter,
- text = state.get_button_text()
- },
- Button
- {
- position = SDL_Point { 10, 100 + state.counter * 5 },
- size = SDL_Point { 100, 30 },
- on_clicked = &increment_counter,
- text = state.get_button_text()
- },
- position = SDL_Point { 100, 10 },
- size = SDL_Point { 50, 50 },
- color = SDL_Color { 0xFF, 0x00, 0x00, 0xFF },
- };
- }
- };
- int main(int argc, char **argv)
- {
- QApplication application(argc, argv);
- MyApplication app;
- app.run();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement