AUI Framework  master
Cross-platform module-based framework for developing C++20 desktop applications
Click.h
1/*
2 * AUI Framework - Declarative UI toolkit for modern C++20
3 * Copyright (C) 2020-2024 Alex2772 and Contributors
4 *
5 * SPDX-License-Identifier: MPL-2.0
6 *
7 * This Source Code Form is subject to the terms of the Mozilla Public
8 * License, v. 2.0. If a copy of the MPL was not distributed with this
9 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 */
11
12#pragma once
13
14#include <AUI/Platform/AWindow.h>
15
16
17template<AInput::Key Button = AInput::LBUTTON>
19 AOptional<glm::ivec2> position;
20 ViewActionMousePress() = default;
21
22 ViewActionMousePress(const glm::ivec2& position) : position(position) {}
23
24 void operator()(const _<AView>& view) {
25 auto coords = view->getPositionInWindow() + (position ? *position : (view->getSize() / 2));
26 auto window = view->getWindow();
27 AInput::overrideStateForTesting(Button, true);
28 window->onPointerPressed({coords, APointerIndex::button(Button)});
29 uitest::frame();
30 }
31};
32
33template<AInput::Key Button = AInput::LBUTTON>
35 AOptional<glm::ivec2> position;
36 ViewActionMouseRelease() = default;
37
38 ViewActionMouseRelease(const glm::ivec2& position) : position(position) {}
39
40 void operator()(const _<AView>& view) {
41 auto coords = view->getPositionInWindow() + (position ? *position : (view->getSize() / 2));
42 auto window = view->getWindow();
43 AInput::overrideStateForTesting(Button, false);
44 window->onPointerReleased({coords, APointerIndex::button(Button)});
45 uitest::frame();
46 }
47};
48
49
50template<AInput::Key Button = AInput::LBUTTON>
52 AOptional<glm::ivec2> position;
53 ViewActionClick() = default;
54
55 ViewActionClick(const glm::ivec2& position) : position(position) {}
56
57 void operator()(const _<AView>& view) {
58 auto coords = view->getPositionInWindow() + (position ? *position : (view->getSize() / 2));
59 auto window = view->getWindow();
60 AInput::overrideStateForTesting(Button, true);
61 window->onPointerPressed({coords, APointerIndex::button(Button)});
62 uitest::frame();
63 AInput::overrideStateForTesting(Button, false);
64 window->onPointerReleased({coords, APointerIndex::button(Button)});
65 uitest::frame();
66 }
67};
68
72
76
77
78struct ViewActionPointerPressed { // for the cases when mouse* actions is not enough
79 AOptional<glm::ivec2> position;
80 APointerIndex pointerIndex = APointerIndex::button(AInput::LBUTTON);
81
82 void operator()(const _<AView>& view) {
83 auto coords = view->getPositionInWindow() + (position ? *position : (view->getSize() / 2));
84 auto window = view->getWindow();
85 window->onPointerPressed({coords, pointerIndex});
86 uitest::frame();
87 }
88};
89
90struct ViewActionPointerReleased { // for the cases when mouse* actions is not enough
91 AOptional<glm::ivec2> position;
92 APointerIndex pointerIndex = APointerIndex::button(AInput::LBUTTON);
93
94 void operator()(const _<AView>& view) {
95 auto coords = view->getPositionInWindow() + (position ? *position : (view->getSize() / 2));
96 auto window = view->getWindow();
97 window->onPointerReleased({coords, pointerIndex});
98 uitest::frame();
99 }
100};
101
102struct ViewActionPointerMoved { // for the cases when mouse* actions is not enough
103 AOptional<glm::ivec2> position;
104 APointerIndex pointerIndex = APointerIndex::button(AInput::LBUTTON);
105
106 void operator()(const _<AView>& view) {
107 auto coords = view->getPositionInWindow() + (position ? *position : (view->getSize() / 2));
108 auto window = view->getWindow();
109 window->onPointerMove(coords, {pointerIndex});
110 uitest::frame();
111 }
112};
113
Utility wrapper implementing the stack-allocated (fast) optional idiom.
Definition: AOptional.h:32
Wrapper class that stores either mouse button index or finger index.
Definition: APointerIndex.h:21
AOptional< AInput::Key > button() const noexcept
Definition: APointerIndex.h:56
An std::weak_ptr with AUI extensions.
Definition: SharedPtrTypes.h:177
Definition: Click.h:51
Definition: Click.h:18
Definition: Click.h:34
Definition: Click.h:102
Definition: Click.h:78
Definition: Click.h:90