AUI Framework  master
Cross-platform module-based framework for developing C++20 desktop applications
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 }
44 ~ARadioGroup() override;
45
46 void setViews(AVector<_<AView>> views) {
47 for (const _<AView>& v : views) {
48 if (auto rb = _cast<ARadioButton>(v)) {
49 mGroup->addRadioButton(rb);
50 addView(v);
51 }
52 }
53 }
54
55 void setModel(const _<IListModel<AString>>& model);
56
57 [[nodiscard]] bool isSelected() const {
58 return mGroup->isSelected();
59 }
60 [[nodiscard]] int getSelectedId() const {
61 return mGroup->getSelectedId();
62 }
63 void setSelectedId(int id) const;
64
65signals:
66 emits<AListModelIndex> selectionChanged;
67};
68
69
70namespace declarative {
71 struct RadioGroup: aui::ui_building::layouted_container_factory<AVerticalLayout, ARadioGroup> {
73 struct Horizontal: aui::ui_building::layouted_container_factory<AHorizontalLayout, ARadioGroup> {
75 };
76 };
77}
A group of radio buttons.
Definition: ARadioGroup.h:32
A std::vector with AUI extensions.
Definition: AVector.h:38
A trivial modifiable view that represents a set of views.
Definition: AViewContainer.h:33
void setViews(AVector< _< AView > > views)
Replace views.
Definition: AViewContainerBase.cpp:614
void setLayout(_unique< ALayout > layout)
Set new layout manager for this AViewContainerBase. DESTROYS OLD LAYOUT MANAGER WITH ITS VIEWS!...
Definition: AViewContainerBase.cpp:175
void addView(const _< AView > &view)
Add view to the container.
Definition: AViewContainerBase.cpp:143
Definition: IListModel.h:23
An std::weak_ptr with AUI extensions.
Definition: SharedPtrTypes.h:177
Definition: ARadioGroup.h:73
Definition: ARadioGroup.h:71