AUI Framework  develop
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
ADrawableView.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//
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
42class API_AUI_VIEWS ADrawableView: public AView {
43public:
48 explicit ADrawableView(const AUrl& url);
49
53 auto drawable() const {
54 return APropertyDef {
55 this,
56 &ADrawableView::getDrawable,
57 &ADrawableView::setDrawable,
58 mDrawableChanged,
59 };
60 }
61
66 explicit ADrawableView(_<IDrawable> drawable);
68 void render(ARenderContext context) override;
69
70 void setDrawable(const _<IDrawable>& drawable) {
71 mDrawable = drawable;
72 redraw();
73 }
74
75 [[nodiscard]]
76 const _<IDrawable>& getDrawable() const noexcept {
77 return mDrawable;
78 }
79
80private:
81 _<IDrawable> mDrawable;
82 emits<_<IDrawable>> mDrawableChanged;
83};
84
85template<>
87public:
88 static auto property(const _<ADrawableView>& view) {
89 return view->drawable();
90 }
91
92 static void setup(const _<ADrawableView>& view) {
93 }
94
95 static auto getSetter() { return &ADrawableView::setDrawable; }
96};
97
98namespace declarative {
100}
Simple view to draw an IDrawable.
Definition ADrawableView.h:42
auto drawable() const
Drawable property.
Definition ADrawableView.h:53
ADrawableView(const AUrl &url)
Create an instance with the URL of a image resource.
Definition ADrawableView.cpp:36
Uniform Resource Locator implementation.
Definition AUrl.h:31
void redraw()
Request window manager to redraw this AView.
Definition AView.cpp:68
virtual void render(ARenderContext ctx)
Draws this AView. Noone should call this function except rendering routine.
Definition AView.cpp:142
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:178
ASignal< Args... > emits
A signal declaration.
Definition ASignal.h:348
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:308
Render context passed to AView::render.
Definition ARenderContext.h:43
Declarative view trait.
Definition Declarative.h:170