AUI Framework  develop
Cross-platform base for C++ UI apps
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Modules Pages Concepts
ADrawableView.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//
   13// Created by alex2 on 23.10.2020.
   14//
   15
   16#pragma once
   17
   18#include <AUI/Image/IDrawable.h>
   19#include <AUI/Util/Declarative.h>
   20#include "AView.h"
   21
   45class API_AUI_VIEWS ADrawableView : public AView {
   46public:
   51    explicit ADrawableView(const AUrl& url);
   52
   56    auto drawable() const {
   57        return APropertyDef {
   58            this,
   59            &ADrawableView::getDrawable,
   60            &ADrawableView::setDrawable,
   61            mDrawableChanged,
   62        };
   63    }
   64
   70    ADrawableView();
   71    ~ADrawableView() override = default;
   72    void render(ARenderContext context) override;
   73
   74    void setDrawable(const _<IDrawable>& drawable) {
   75        mDrawable = drawable;
   76        redraw();
   77    }
   78
   79    [[nodiscard]]
   80    const _<IDrawable>& getDrawable() const noexcept {
   81        return mDrawable;
   82    }
   83
   84private:
   85    _<IDrawable> mDrawable;
   86    emits<_<IDrawable>> mDrawableChanged;
   87};
   88
   89template <aui::derived_from<ADrawableView> T>
   91public:
   92    static auto property(const _<ADrawableView>& view) { return view->drawable(); }
   93
   94    static void setup(const _<ADrawableView>& view) {}
   95
   96    static auto getSetter() { return &ADrawableView::setDrawable; }
   97};
   98
  100public:
  101    using ADrawableView::ADrawableView;
  102    ~ADrawableIconView() override = default;
  103};
  104
  105namespace declarative {
  106
  110struct Icon : aui::ui_building::view<ADrawableIconView> {
  111    using aui::ui_building::view<ADrawableIconView>::view;
  112};
  113}   // namespace declarative
Definition ADrawableView.h:99
ADrawableView(const AUrl &url)
Create an instance with the URL of a image resource.
auto drawable() const
Drawable property.
Definition ADrawableView.h:56
void render(ARenderContext context) override
Draws this AView. Noone should call this function except rendering routine.
ADrawableView(const AUrl &url)
Create an instance with the URL of a image resource.
ADrawableView(_< IDrawable > drawable)
Create an instance from the given drawable.
Uniform Resource Locator implementation.
Definition AUrl.h:31
void redraw()
Request window manager to redraw this AView.
An abstract image that determines itself how it is displayed. Essentially an abstraction from vector ...
Definition IDrawable.h:28
An std::weak_ptr with AUI extensions.
Definition SharedPtrTypes.h:179
ASignal< Args... > emits
A signal declaration.
Definition ASignal.h:572
Defines how View handles properties of FieldType type.
Definition ADataBinding.h:37
static void(View::*)(const FieldType &v) getSetter()
Returns setter for ADataBinding (deprecated)
Definition ADataBinding.h:63
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
Declarative view trait.
Definition Declarative.h:180
Declarative form of ADrawableView.
Definition ADrawableView.h:110