| 11 | { |
| 12 | |
| 13 | NotNull<Widget*> CounterState::build(NotNull<IBuildContext*> context) SKR_NOEXCEPT |
| 14 | { |
| 15 | if (!_click_gesture) |
| 16 | { |
| 17 | // TODO. pass input manager by setter |
| 18 | _click_gesture = SkrNew<ClickGestureRecognizer>(context->build_owner()->input_manager()); |
| 19 | _click_gesture->on_click = [this]() { |
| 20 | set_state([this]() { |
| 21 | ++count; |
| 22 | }); |
| 23 | }; |
| 24 | } |
| 25 | |
| 26 | return SNewWidget(Flex) |
| 27 | { |
| 28 | p.flex_direction = EFlexDirection::Column; |
| 29 | p.children += SNewWidget(Text) |
| 30 | { |
| 31 | p.text = skr::format(u8"count: {}", count); |
| 32 | }; |
| 33 | // for (int32_t i = 0; i < count; ++i) |
| 34 | // { |
| 35 | // p.children += SNewWidget(ColoredBox) |
| 36 | // { |
| 37 | // p.color = { 0, 0, 1, 1 }; |
| 38 | // p.child = SNewWidget(Text) |
| 39 | // { |
| 40 | // p.text = skr::format(u8"count {}", i); |
| 41 | // }; |
| 42 | // }; |
| 43 | // }; |
| 44 | |
| 45 | p.children += SNewWidget(MouseRegin) |
| 46 | { |
| 47 | p.on_down = [this](PointerDownEvent* event) { |
| 48 | if (event->phase != EEventRoutePhase::BubbleUp) return false; |
| 49 | if (event->button == EPointerButton::Left) |
| 50 | { |
| 51 | _click_gesture->add_pointer(event); |
| 52 | return true; |
| 53 | } |
| 54 | return false; |
| 55 | }; |
| 56 | p.on_up = [this](PointerUpEvent* event) { |
| 57 | if (event->phase != EEventRoutePhase::BubbleUp) return false; |
| 58 | if (event->button == EPointerButton::Left) |
| 59 | { |
| 60 | _click_gesture->handle_event_from_widget(event); |
| 61 | return true; |
| 62 | } |
| 63 | return false; |
| 64 | }; |
| 65 | |
| 66 | p.child = SNewWidget_S(ColoredBox) |
| 67 | { |
| 68 | p.color = { 1, 0, 0, 1 }; |
| 69 | p.child = SNewWidget_S(Text) |
| 70 | { |
no test coverage detected