AUI Framework  develop
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
AProgressBar.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/View/AViewContainer.h>
   15#include <AUI/Traits/values.h>
   16#include <AUI/Util/ADataBinding.h>
   17
   25class API_AUI_VIEWS AProgressBar: public AViewContainerBase {
   26public:
   27    class Inner: public AView {
   28    public:
   29        ~Inner() override;
   30    };
   31    ~AProgressBar() override;
   32
   37    void setValue(aui::float_within_0_1 value) {
   38        mValue = value;
   39        updateInnerWidth();
   40        redraw();
   41
   42        emit mValueChanged(value);
   43    }
   44
   45    [[nodiscard]]
   46    auto value() const noexcept {
   47        return APropertyDef {
   48            this,
   49            &AProgressBar::mValue,
   50            &AProgressBar::setValue,
   51            mValueChanged,
   52        };
   53    }
   54
   55    [[nodiscard]]
   56    const _<Inner>& innerView() const noexcept {
   57        return mInner;
   58    }
   59
   60public:
   61    AProgressBar();
   62
   63    void setSize(glm::ivec2 size) override;
   64    void render(ARenderContext context) override;
   65
   66private:
   67    aui::float_within_0_1 mValue = 0.f;
   68    emits<aui::float_within_0_1> mValueChanged;
   69    void updateInnerWidth();
   70    _<Inner> mInner;
   71};
   72
   73template<>
   74struct ADataBindingDefault<AProgressBar, aui::float_within_0_1> {
   75public:
   76    static auto property(const _<AProgressBar>& view) {
   77        return view->value();
   78    }
   79    static void setup(const _<AProgressBar>& view) {}
   80};
Definition AProgressBar.h:27
A progress bar.
Definition AProgressBar.h:25
void render(ARenderContext context) override
Draws this AView. Noone should call this function except rendering routine.
void setValue(aui::float_within_0_1 value)
Definition AProgressBar.h:37
void redraw()
Request window manager to redraw this AView.
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
#define emit
emits the specified signal in context of this object.
Definition AObject.h:343
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
Property implementation to use with custom getter/setter.
Definition AProperty.h:234
Render context passed to AView::render.
Definition ARenderContext.h:43