AUI Framework  develop
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
ASlider.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
   15#include "AViewContainer.h"
   16#include "AProgressBar.h"
   17
   22class API_AUI_VIEWS ASlider: public AViewContainerBase {
   23public:
   24    class Handle: public AView {}; // embed class for styling
   25
   26    ASlider();
   27    void onPointerMove(glm::vec2 pos, const APointerMoveEvent& event) override;
   28    void onPointerPressed(const APointerPressedEvent& event) override;
   29    void onPointerReleased(const APointerReleasedEvent& event) override;
   30    void applyGeometryToChildren() override;
   31    bool capturesFocus() override;
   32
   33    [[nodiscard]]
   34    bool isDragging() const noexcept {
   35        return isPressed();
   36    }
   37
   38    void setValue(aui::float_within_0_1 value) {
   39        mProgress->setValue(value);
   40    }
   41
   42    [[nodiscard]]
   43    auto value() const noexcept {
   44        return APropertyDef {
   45            this,
   46            &ASlider::getValue,
   47            &ASlider::setValue,
   48            valueChanging,
   49        };
   50    }
   51
   52    [[nodiscard]]
   53    const _<Handle>& handle() const noexcept {
   54        return mHandle;
   55    }
   56
   57    [[nodiscard]]
   58    const _<AProgressBar>& progressbar() const noexcept {
   59        return mProgress;
   60    }
   61
   62signals:
   63    emits<aui::float_within_0_1> valueChanging;
   64    emits<aui::float_within_0_1> valueChanged;
   65
   66private:
   67    _<Handle> mHandle;
   68    _<AProgressBar> mProgress;
   69
   70    [[nodiscard]]
   71    aui::float_within_0_1 getValue() const noexcept {
   72        return mProgress->value();
   73    }
   74
   75    void updateSliderWithPosition(glm::ivec2 pointerPosition);
   76
   77    void updateHandlePosition();
   78};
   79
   80template<>
   81struct ADataBindingDefault<ASlider, aui::float_within_0_1> {
   82public:
   83    static auto property(const _<ASlider>& view) {
   84        return view->value();
   85    }
   86    static void setup(const _<ASlider>& view) {}
   87};
Definition ASlider.h:24
Slider control.
Definition ASlider.h:22
void onPointerMove(glm::vec2 pos, const APointerMoveEvent &event) override
Handles pointer hover events.
bool capturesFocus() override
void onPointerReleased(const APointerReleasedEvent &event) override
Called on pointer (mouse) released event.
void onPointerPressed(const APointerPressedEvent &event) override
Called on pointer (mouse) released event.
An std::weak_ptr with AUI extensions.
Definition SharedPtrTypes.h:179
std::add_lvalue_reference_t< T > value() const noexcept
Dereferences the stored pointer.
Definition SharedPtrTypes.h:294
ASignal< Args... > emits
A signal declaration.
Definition ASignal.h:572
Defines how View handles properties of FieldType type.
Definition ADataBinding.h:37
static void setup(const _< View > &view)
Called then view linked with field.
Definition ADataBinding.h:43
static auto property(const _< View > &view)
Returns property definition for FieldType.
Definition ADataBinding.h:49
Pointing method move event.
Definition APointerMoveEvent.h:21
Pointing method press event.
Definition APointerPressedEvent.h:21
Pointing method press event.
Definition APointerReleasedEvent.h:19