AUI Framework  develop
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
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:
47 ANumberPicker();
48
52 auto value() const {
53 return APropertyDef {
54 this,
55 &ANumberPicker::getValue,
56 &ANumberPicker::setValue,
58 };
59 }
60
61 void setValue(int64_t v);
62
63 int64_t getValue() const;
64
65 void setSuffix(const AString& suffix);
66
67 [[nodiscard]] const AString& text() const noexcept { return mTextField->text(); }
68
69 void increase();
70
71 void decrease();
72
73 void changeBy(int64_t v);
74
75 [[nodiscard]] int64_t getMin() const { return mMin; }
76
77 [[nodiscard]] int64_t getMax() const { return mMax; }
78
79 void setMin(int64_t min);
80
81 void setMax(int64_t max);
82
83signals:
88
93};
94
95namespace aui::impl {
96 template<typename Num>
98 public:
99 static auto property(const _<ANumberPicker>& view) {
100 return view->value();
101 }
102 static void setup(const _<ANumberPicker>& view) {}
103
104 static auto getGetter() { return &ANumberPicker::valueChanged; }
105
106 static auto getSetter() { return &ANumberPicker::setValue; }
107 };
108
109 template <aui::arithmetic UnderlyingType, auto min, auto max>
110 requires aui::convertible_to<decltype(min), UnderlyingType> &&
111 aui::convertible_to<decltype(max), UnderlyingType>
113 public:
114 static auto property(const _<ANumberPicker>& view) {
115 return view->value();
116 }
117 static void setup(const _<ANumberPicker>& view) {
118 view->setMin(aui::ranged_number<UnderlyingType, min, max>::MIN);
119 view->setMax(aui::ranged_number<UnderlyingType, min, max>::MAX);
120 }
121
122 static auto getGetter() { return &ANumberPicker::valueChanged; }
123
124 static auto getSetter() { return &ANumberPicker::setValue; }
125 };
126} // namespace aui::impl
127
128template<>
131
132template<>
135
136template<>
139
140template<>
143
144template<>
147
148template<>
151
152template<>
155
156template <aui::arithmetic UnderlyingType, auto min, auto max>
157 requires aui::convertible_to<decltype(min), UnderlyingType> && aui::convertible_to<decltype(max), UnderlyingType>
158struct ADataBindingDefault<ANumberPicker, aui::ranged_number<UnderlyingType, min, max>>
159 : aui::impl::ADataBindingRangedNumberPicker<UnderlyingType, min, max> {};
Text field implementation.
Definition AAbstractTextField.h:26
A text field for numbers with increase/decrease buttons.
Definition ANumberPicker.h:24
emits< int64_t > valueChanging
Number is changing.
Definition ANumberPicker.h:92
auto value() const
Value property.
Definition ANumberPicker.h:52
emits< int64_t > valueChanged
Number changed.
Definition ANumberPicker.h:87
Represents a Unicode character string.
Definition AString.h:37
An std::weak_ptr with AUI extensions.
Definition SharedPtrTypes.h:178
Definition concepts.h:42
ASignal< Args... > emits
A signal declaration.
Definition ASignal.h:348
Defines how View handles properties of FieldType type.
Definition ADataBinding.h:37
Property implementation to use with custom getter/setter.
Definition AProperty.h:308
Definition ANumberPicker.h:97
Definition ANumberPicker.h:112