AUI Framework  develop
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
ADoubleNumberPicker.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 ADoubleNumberPicker : public AViewContainerBase {
25 private:
26 class ADoubleNumberPickerField : public AAbstractTextField {
27 private:
28 ADoubleNumberPicker& mPicker;
29
30 public:
31 ADoubleNumberPickerField(::ADoubleNumberPicker& picker) : mPicker(picker) {}
32
33 virtual ~ADoubleNumberPickerField() = default;
34
35 void onKeyRepeat(AInput::Key key) override;
36
37 protected:
38 bool isValidText(const AString& text) override;
39 };
40
42
43 double mMin = 0;
44 double mMax = 100;
45
46 public:
47 ADoubleNumberPicker();
48
49 void setValue(double v);
50
51 void setSuffix(const AString& suffix);
52
53 [[nodiscard]] const AString& text() const noexcept { return mTextField->text(); }
54
55 [[nodiscard]] double getValue() const { return mTextField->getText().toDouble().valueOr(0.0); }
56
57 [[nodiscard]] double getMin() const { return mMin; }
58
59 [[nodiscard]] double getMax() const { return mMax; }
60
61 void setMin(double min);
62 void setMax(double max);
63
64 void increase();
65 void decrease();
66 void changeBy(double v);
67
68 signals:
73
78};
79
80namespace aui::impl {
81template <typename Num>
83 public:
84 static void setup(const _<ADoubleNumberPicker>& view) {}
85
86 static auto getGetter() { return &ADoubleNumberPicker::valueChanged; }
87
88 static auto getSetter() { return &ADoubleNumberPicker::setValue; }
89};
90
91template <aui::arithmetic UnderlyingType, auto min, auto max>
92 requires aui::convertible_to<decltype(min), UnderlyingType> && aui::convertible_to<decltype(max), UnderlyingType>
94 public:
95 static void setup(const _<ADoubleNumberPicker>& view) {
96 view->setMin(aui::ranged_number<UnderlyingType, min, max>::MIN);
97 view->setMax(aui::ranged_number<UnderlyingType, min, max>::MAX);
98 }
99
100 static auto getGetter() { return &ADoubleNumberPicker::valueChanged; }
101
102 static auto getSetter() { return &ADoubleNumberPicker::setValue; }
103};
104} // namespace aui::impl
105
106template <>
108
109template <>
111
112template <aui::arithmetic UnderlyingType, auto min, auto max>
113 requires aui::convertible_to<decltype(min), UnderlyingType> && aui::convertible_to<decltype(max), UnderlyingType>
114struct ADataBindingDefault<ADoubleNumberPicker, aui::ranged_number<UnderlyingType, min, max>>
115 : aui::impl::ADataBindingRangedDoubleNumberPicker<UnderlyingType, min, max> {};
Text field implementation.
Definition AAbstractTextField.h:26
A text field for numbers with increase/decrease buttons.
Definition ADoubleNumberPicker.h:24
emits valueChanging
Number is changing.
Definition ADoubleNumberPicker.h:77
emits< double > valueChanged
Number changed.
Definition ADoubleNumberPicker.h:72
Represents a Unicode character string.
Definition AString.h:37
AOptional< double > toDouble() const noexcept
Converts the string to a double number.
Definition AString.cpp:1316
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
Definition ADoubleNumberPicker.h:82
Definition ADoubleNumberPicker.h:93