AUI Framework  master
Cross-platform module-based framework for developing C++20 desktop applications
ARadioButton.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//
13// Created by alex2 on 21.09.2020.
14//
15
16#pragma once
17
18#include "ALabel.h"
19#include "AViewContainer.h"
20#include <AUI/Common/AMap.h>
21#include <AUI/ASS/Selector/Selected.h>
22
23
25{
26public:
27 ARadioButtonInner() = default;
28 virtual ~ARadioButtonInner() = default;
29
30 void update();
31};
32
33
44class API_AUI_VIEWS ARadioButton : public AViewContainerBase, public ass::ISelectable {
45private:
46 _<ALabel> mText;
47 bool mChecked = false;
48protected:
49 bool selectableIsSelectedImpl() override;
50
51public:
54
55 virtual ~ARadioButton();
56
57 void setText(const AString& text);
58
59
60 [[nodiscard]] bool isChecked() const {
61 return mChecked;
62 }
63
64 void setChecked(const bool checked) {
65 mChecked = checked;
66 emit customCssPropertyChanged();
67 emit ARadioButton::checked(checked);
68 }
69
70 void onPointerReleased(const APointerReleasedEvent& event) override;
71
72 class API_AUI_VIEWS Group: public AObject {
73 private:
75 _weak<ARadioButton> mSelectedRadio;
76 int mSelectedId = -1;
77
78 public:
79 Group() = default;
80 ~Group() override = default;
81
82 _<ARadioButton> addRadioButton(const _<ARadioButton>& radio, int id = -1);
83
84 [[nodiscard]] _<ARadioButton> getSelectedRadio() const;
85 [[nodiscard]] int getSelectedId() const;
86
87 void setSelectedId(int id);
88
89 [[nodiscard]] bool isSelected() const {
90 return mSelectedRadio.lock() != nullptr;
91 }
92
93 void uncheckAll() {
94 for (auto& b : mButtons) {
95 b.second->setChecked(false);
96 }
97 mSelectedId = -1;
98 }
99
100 signals:
101 emits<int> selectionChanged;
102 };
103
104signals:
105 emits<bool> checked;
106};
107
108namespace declarative {
109 using RadioButton = aui::ui_building::view<ARadioButton>;
110}
A std::map with AUI extensions.
Definition: AMap.h:218
A base object class.
Definition: AObject.h:49
Definition: ARadioButton.h:25
Definition: ARadioButton.h:72
A radio button.
Definition: ARadioButton.h:44
Represents a Unicode character string.
Definition: AString.h:37
A view that represents a set of views.
Definition: AViewContainerBase.h:68
void onPointerReleased(const APointerReleasedEvent &event) override
Called on pointer (mouse) released event.
Definition: AViewContainerBase.cpp:327
Base class of all UI objects.
Definition: AView.h:77
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
Pointing method press event.
Definition: APointerReleasedEvent.h:19
Definition: Text.h:21
An std::weak_ptr with AUI extensions.
Definition: SharedPtrTypes.h:51
Definition: Declarative.h:91