AUI Framework  master
Cross-platform module-based framework for developing C++20 desktop applications
BackgroundImage.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 3.12.2020.
14//
15
16#pragma once
17
18#include <AUI/Render/IRenderer.h>
19#include <AUI/Common/IStringable.h>
20#include "IProperty.h"
21
22namespace ass {
27enum class Sizing {
31 NONE,
32
36 FIT,
37
41 CENTER,
42
46 TILE,
47
52
57 COVER,
58
63 CONTAIN,
64
70
78
82 CROPPED,
83};
84
96
107
112
117
122
131
132 BackgroundImage() {}
133
134 BackgroundImage(std::nullptr_t) : image("") {}
135
136 BackgroundImage(
137 const unset_wrap<std::variant<AString, _<IDrawable>>>& url, const unset_wrap<AColor>& overlayColor = {},
138 const unset_wrap<Repeat>& rep = {}, const unset_wrap<Sizing>& sizing = {}, const unset_wrap<glm::vec2>& scale = {},
139 const unset_wrap<float>& dpiMargin = {})
141};
142
143namespace prop {
144template <>
146private:
147 BackgroundImage mInfo;
148
149public:
150 Property(const BackgroundImage& info) : mInfo(info) {}
151
152 void applyFor(AView* view) override;
153 void renderFor(AView* view, const ARenderContext& ctx) override;
154
155 PropertySlot getPropertySlot() const override;
156
157 [[nodiscard]]
158 const auto& value() const noexcept {
159 return mInfo;
160 }
161
162 AString toString() const override;
163
164 static void
165 draw(const ARenderContext& ctx, AView* view, const _<IDrawable>& drawable, const ass::BackgroundImage& info);
166};
167
168} // namespace prop
169} // namespace ass
170
Represents a Unicode character string.
Definition: AString.h:37
Base class of all UI objects.
Definition: AView.h:77
Object that can be converted to string.
Definition: IStringable.h:29
An std::weak_ptr with AUI extensions.
Definition: SharedPtrTypes.h:177
Sizing
Determines sizing rules of a background texture (BackgroundImage).
Definition: BackgroundImage.h:27
@ FIT
Resize image to view's area without keeping aspect ratio.
@ FIT_PADDING
Resize image to view's content area without keeping aspect ratio.
@ CONTAIN
Resize image to view's area keeping aspect ratio and keeping space not covered by the image....
@ COVER
Resize image to view's area keeping aspect ratio and cutting of excess parts. Matches CSS background-...
@ CROPPED
Texture is cropped by BackgroundCropping rule.
@ CONTAIN_PADDING
Resize image to view's content area keeping aspect ratio and keeping space not covered by the image....
@ SPLIT_2X2
Texture divided by 4 parts of the same size, keeping their original size. Useful for textured buttons...
@ NONE
Image is kept in it's original size.
@ CENTER
Center the image.
@ TILE
Tile texture. Use with Repeat::X_y.
AUI_ENUM_VALUES(ATextOverflow, ATextOverflow::ELLIPSIS, ATextOverflow::CLIP) enum class AOverflowMask
Controls the behaviour of the default AView::drawStencilMask() implementation.
Definition: AOverflow.h:55
Render context passed to AView::render.
Definition: ARenderContext.h:43
Represents textured (image) background.
Definition: BackgroundImage.h:89
unset_wrap< float > dpiMargin
DPI multiplier used to underscale or upperscale the icon.
Definition: BackgroundImage.h:130
unset_wrap< std::variant< AString, _< IDrawable > > > image
Url to the image.
Definition: BackgroundImage.h:95
unset_wrap< glm::vec2 > scale
Scale of the image by x and y axis. Default is { 1.0, 1.0 }.
Definition: BackgroundImage.h:121
unset_wrap< Repeat > rep
Repeating. See Repeat.
Definition: BackgroundImage.h:111
unset_wrap< Sizing > sizing
Sizing. See ass::Sizing.
Definition: BackgroundImage.h:116
unset_wrap< AColor > overlayColor
Multiply color filter to the image.
Definition: BackgroundImage.h:106
Base class for all properties.
Definition: IPropertyBase.h:49
AString toString() const override
Definition: IProperty.h:19
Definition: unset.h:28