AUI Framework  develop
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
ARadioGroup.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 "AViewContainer.h"
19#include "ARadioButton.h"
20#include "AUI/Model/AListModel.h"
21#include <AUI/Layout/AHorizontalLayout.h>
22#include <AUI/Layout/AVerticalLayout.h>
23#include <AUI/Model/IListModel.h>
24
32class API_AUI_VIEWS ARadioGroup: public AViewContainer {
33private:
36
37public:
38 template<typename... RadioButtons>
39 explicit ARadioGroup(RadioButtons&&... radioButtons): ARadioGroup() {
40 setLayout(std::make_unique<AVerticalLayout>());
41 setViews({ std::forward<RadioButtons>(radioButtons)... });
42 }
43 ARadioGroup();
44 ~ARadioGroup() override;
45
49 auto selectionId() const {
50 return APropertyDef {
51 this,
52 &ARadioGroup::getSelectedId,
53 &ARadioGroup::setSelectedId,
54 selectionChanged,
55 };
56 }
57
58 void setViews(AVector<_<AView>> views) {
59 for (const _<AView>& v : views) {
60 if (auto rb = _cast<ARadioButton>(v)) {
61 mGroup->addRadioButton(rb);
62 addView(v);
63 }
64 }
65 }
66
67 void setModel(const _<IListModel<AString>>& model);
68
69 [[nodiscard]] bool isSelected() const {
70 return mGroup->isSelected();
71 }
72 [[nodiscard]] int getSelectedId() const {
73 return mGroup->getSelectedId();
74 }
75 void setSelectedId(int id) const;
76
77signals:
78 emits<int> selectionChanged;
79};
80
81
82namespace declarative {
83 struct RadioGroup: aui::ui_building::view_container_layout<AVerticalLayout, ARadioGroup> {
84 using aui::ui_building::view_container_layout<AVerticalLayout, ARadioGroup>::layouted_container_factory;
85 struct Horizontal: aui::ui_building::view_container_layout<AHorizontalLayout, ARadioGroup> {
86 using aui::ui_building::view_container_layout<AHorizontalLayout, ARadioGroup>::layouted_container_factory;
87 };
88 };
89}
Places views in a row.
Definition AHorizontalLayout.h:42
A group of radio buttons.
Definition ARadioGroup.h:32
auto selectionId() const
Selected id property.
Definition ARadioGroup.h:49
A std::vector with AUI extensions.
Definition AVector.h:39
Places views in a column.
Definition AVerticalLayout.h:41
void setViews(AVector< _< AView > > views)
Replace views.
Definition AViewContainerBase.cpp:618
void setLayout(_unique< ALayout > layout)
Set new layout manager for this AViewContainerBase. DESTROYS OLD LAYOUT MANAGER WITH ITS VIEWS!...
Definition AViewContainerBase.cpp:177
void addView(const _< AView > &view)
Add view to the container.
Definition AViewContainerBase.cpp:145
An std::weak_ptr with AUI extensions.
Definition SharedPtrTypes.h:178
ASignal< Args... > emits
A signal declaration.
Definition ASignal.h:348
Property implementation to use with custom getter/setter.
Definition AProperty.h:308
Definition ARadioGroup.h:85
Definition ARadioGroup.h:83