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-2025 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
   41    _<ADoubleNumberPickerField> mTextField;
   42
   43    double mMin = 0;
   44    double mMax = 100;
   45
   46public:
   47    ADoubleNumberPicker();
   48
   49    auto value() {
   50        return APropertyDef {
   51            this,
   52            &ADoubleNumberPicker::getValue,
   53            &ADoubleNumberPicker::setValue,
   54            valueChanging,
   55        };
   56    }
   57
   58    void setValue(double v);
   59
   60    void setSuffix(const AString& suffix);
   61
   62    [[nodiscard]] const AString& text() const noexcept { return mTextField->text(); }
   63
   64    [[nodiscard]] double getValue() const { return mTextField->getText().toDouble().valueOr(0.0); }
   65
   66    [[nodiscard]] double getMin() const { return mMin; }
   67
   68    [[nodiscard]] double getMax() const { return mMax; }
   69
   70    void setMin(double min);
   71    void setMax(double max);
   72
   73    void increase();
   74    void decrease();
   75    void changeBy(double v);
   76
   77   signals:
   82
   87};
   88
   89namespace aui::impl {
   90template <typename Num>
   92   public:
   93    static void setup(const _<ADoubleNumberPicker>& view) {}
   94
   95    static auto getGetter() { return &ADoubleNumberPicker::valueChanged; }
   96
   97    static auto getSetter() { return &ADoubleNumberPicker::setValue; }
   98};
   99
  100template <aui::arithmetic UnderlyingType, auto min, auto max>
  101    requires aui::convertible_to<decltype(min), UnderlyingType> && aui::convertible_to<decltype(max), UnderlyingType>
  103   public:
  104    static void setup(const _<ADoubleNumberPicker>& view) {
  105        view->setMin(aui::ranged_number<UnderlyingType, min, max>::MIN);
  106        view->setMax(aui::ranged_number<UnderlyingType, min, max>::MAX);
  107    }
  108
  109    static auto getGetter() { return &ADoubleNumberPicker::valueChanged; }
  110
  111    static auto getSetter() { return &ADoubleNumberPicker::setValue; }
  112};
  113}   // namespace aui::impl
  114
  115template <>
  117
  118template <>
  120
  121template <aui::arithmetic UnderlyingType, auto min, auto max>
  122    requires aui::convertible_to<decltype(min), UnderlyingType> && aui::convertible_to<decltype(max), UnderlyingType>
  123struct ADataBindingDefault<ADoubleNumberPicker, aui::ranged_number<UnderlyingType, min, max>>
  124    : 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< double > valueChanging
Number is changing.
Definition ADoubleNumberPicker.h:86
emits< double > valueChanged
Number changed.
Definition ADoubleNumberPicker.h:81
Represents a Unicode character string.
Definition AString.h:38
AOptional< double > toDouble() const noexcept
Converts the string to a double number.
An std::weak_ptr with AUI extensions.
Definition SharedPtrTypes.h:179
Definition concepts.h:42
ASignal< Args... > emits
A signal declaration.
Definition ASignal.h:572
Defines how View handles properties of FieldType type.
Definition ADataBinding.h:37
Property implementation to use with custom getter/setter.
Definition AProperty.h:234
Definition ADoubleNumberPicker.h:91
Definition ADoubleNumberPicker.h:102