AUI Framework  master
Cross-platform module-based framework for developing C++20 desktop applications
ACheckBox.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 "ALabel.h"
15#include "AViewContainer.h"
16#include <AUI/ASS/Selector/Selected.h>
17
18
27class API_AUI_VIEWS ACheckBox : public AView, public ass::ISelectable {
28private:
29 bool mChecked = false;
30protected:
31 bool selectableIsSelectedImpl() override;
32
33public:
34 ACheckBox();
35
36 void toggle() {
37 setChecked(!isChecked());
38 }
39
40 [[nodiscard]] bool isChecked() const {
41 return mChecked;
42 }
43
44 void check() {
45 setChecked(true);
46 }
47
48 void uncheck() {
49 setChecked(false);
50 }
51
52 void setChecked(bool checked = true) {
53 mChecked = checked;
54 emit customCssPropertyChanged();
55 emit ACheckBox::checked(checked);
56 }
57
58 void setUnchecked(bool unchecked = true) {
59 setChecked(!unchecked);
60 }
61
62 bool consumesClick(const glm::ivec2& pos) override;
63
64
65signals:
66 emits<bool> checked;
67};
68
69
74class API_AUI_VIEWS ACheckBoxWrapper: public AViewContainerBase {
75public:
76 explicit ACheckBoxWrapper(const _<AView>& viewToWrap);
77
78 void toggle() {
79 setChecked(!isChecked());
80 }
81
82 [[nodiscard]] bool isChecked() const {
83 return mCheckBox->isChecked();
84 }
85
86 void check() {
87 setChecked(true);
88 }
89
90 void uncheck() {
91 setChecked(false);
92 }
93
94 void setChecked(bool checked = true) {
95 mCheckBox->setChecked(checked);
96 }
97
98 void setUnchecked(bool unchecked = true) {
99 setChecked(!unchecked);
100 }
101
102private:
103 _<ACheckBox> mCheckBox;
104
105signals:
106 emits<bool> checked;
107};
108
109
110template<>
112public:
113 static void setup(const _<ACheckBox>& view) {}
114
115 static auto getGetter() {
116 return &ACheckBox::checked;
117 }
118
119 static auto getSetter() {
120 return &ACheckBox::setChecked;
121 }
122};
123
124
125template<>
127public:
128 static void setup(const _<ACheckBoxWrapper>& view) {}
129
130 static auto getGetter() {
131 return &ACheckBoxWrapper::checked;
132 }
133
134 static auto getSetter() {
135 return &ACheckBoxWrapper::setChecked;
136 }
137};
138
139namespace declarative {
140 using CheckBox = aui::ui_building::view<ACheckBox>;
141 using CheckBoxWrapper = aui::ui_building::view<ACheckBoxWrapper>;
142}
View container with a checkbox.
Definition: ACheckBox.h:74
A check box (without label).
Definition: ACheckBox.h:27
A view that represents a set of views.
Definition: AViewContainerBase.h:68
Base class of all UI objects.
Definition: AView.h:77
virtual bool consumesClick(const glm::ivec2 &pos)
Determines whether this AView processes this click or passes it thru.
Definition: AView.cpp:534
An std::weak_ptr with AUI extensions.
Definition: SharedPtrTypes.h:177
Definition: Selected.h:18
#define emit
emits the specified signal in context of this object.
Definition: AObject.h:196
Definition: ADataBinding.h:24
static void setup(const _< View > &view)
Definition: ADataBinding.h:30
Definition: Declarative.h:91