AUI Framework  master
Cross-platform module-based framework for developing C++20 desktop applications
ANumberPicker.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/Traits/values.h>
15#include <AUI/Util/ADataBinding.h>
16
17#include "AAbstractTextField.h"
18#include "AViewContainer.h"
19
24class API_AUI_VIEWS ANumberPicker : public AViewContainerBase {
25private:
26 class ANumberPickerField : public AAbstractTextField {
27 private:
28 ANumberPicker& mPicker;
29
30 public:
31 ANumberPickerField(::ANumberPicker& picker) : mPicker(picker) {}
32
33 virtual ~ANumberPickerField() = default;
34
35 void onKeyRepeat(AInput::Key key) override;
36
37 protected:
38 bool isValidText(const AString& text) override;
39 };
40
41 _<ANumberPickerField> mTextField;
42
43 int64_t mMin = 0;
44 int64_t mMax = 100;
45
46public:
48
49 void setValue(int64_t v);
50
51 int64_t getValue() const;
52
53 void setSuffix(const AString& suffix);
54
55 [[nodiscard]] const AString& text() const noexcept { return mTextField->text(); }
56
57 void increase();
58
59 void decrease();
60
61 void changeBy(int64_t v);
62
63 [[nodiscard]] int64_t getMin() const { return mMin; }
64
65 [[nodiscard]] int64_t getMax() const { return mMax; }
66
67 void setMin(int64_t min);
68
69 void setMax(int64_t max);
70
71signals:
76
81};
82
83namespace aui::impl {
84 template<typename Num>
86 public:
87 static void setup(const _<ANumberPicker>& view) {}
88
89 static auto getGetter() { return &ANumberPicker::valueChanged; }
90
91 static auto getSetter() { return &ANumberPicker::setValue; }
92 };
93
94 template<aui::arithmetic UnderlyingType, auto min, auto max> requires
95 aui::convertible_to<decltype(min), UnderlyingType> && aui::convertible_to<decltype(max), UnderlyingType>
97 public:
98 static void setup(const _<ANumberPicker>& view) {
101 }
102
103 static auto getGetter() { return &ANumberPicker::valueChanged; }
104
105 static auto getSetter() { return &ANumberPicker::setValue; }
106 };
107} // namespace aui::impl
108
109template<>
111};
112
113template<>
115};
116
117template<>
119};
120
121template<>
123};
124
125template<>
127};
128
129template<>
131};
132
133template<>
135};
136
137template<aui::arithmetic UnderlyingType, auto min, auto max> requires
138aui::convertible_to<decltype(min), UnderlyingType> && aui::convertible_to<decltype(max), UnderlyingType>
139struct ADataBindingDefault<ANumberPicker, aui::ranged_number<UnderlyingType, min, max>>
140 : aui::impl::ADataBindingRangedNumberPicker<UnderlyingType, min, max> {
141};
Text field implementation.
Definition: AAbstractTextField.h:26
A text field for numbers with increase/decrease buttons.
Definition: ANumberPicker.h:24
emits valueChanging
Number is changing.
Definition: ANumberPicker.h:80
emits< int64_t > valueChanged
Number changed.
Definition: ANumberPicker.h:75
Represents a Unicode character string.
Definition: AString.h:37
A view that represents a set of views.
Definition: AViewContainerBase.h:68
An std::weak_ptr with AUI extensions.
Definition: SharedPtrTypes.h:177
Definition: ADataBinding.h:24
Definition: Text.h:21
Definition: ANumberPicker.h:85
Definition: ANumberPicker.h:96
Clamps the possible values for a number to the specified range: [min;max].
Definition: values.h:452