AUI Framework  develop
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
BackgroundImage.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 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
   64
   70
   78
   83};
   84
   89struct BackgroundImage {
   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 <>
  145struct API_AUI_VIEWS Property<BackgroundImage> : IPropertyBase, IStringable {
  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:38
Base class of all UI objects.
Definition AView.h:78
Object that can be converted to string.
Definition IStringable.h:29
An std::weak_ptr with AUI extensions.
Definition SharedPtrTypes.h:179
Sizing
Determines sizing rules of a background texture (BackgroundImage).
Definition BackgroundImage.h:27
@ FIT
Resize image to view's area without keeping aspect ratio.
Definition BackgroundImage.h:36
@ FIT_PADDING
Resize image to view's content area without keeping aspect ratio.
Definition BackgroundImage.h:51
@ CONTAIN
Resize image to view's area keeping aspect ratio and keeping space not covered by the image....
Definition BackgroundImage.h:63
@ COVER
Resize image to view's area keeping aspect ratio and cutting of excess parts. Matches CSS background-...
Definition BackgroundImage.h:57
@ CROPPED
Texture is cropped by BackgroundCropping rule.
Definition BackgroundImage.h:82
@ CONTAIN_PADDING
Resize image to view's content area keeping aspect ratio and keeping space not covered by the image....
Definition BackgroundImage.h:69
@ SPLIT_2X2
Texture divided by 4 parts of the same size, keeping their original size. Useful for textured buttons...
Definition BackgroundImage.h:77
@ NONE
Image is kept in it's original size.
Definition BackgroundImage.h:31
@ CENTER
Center the image.
Definition BackgroundImage.h:41
@ TILE
Tile texture. Use with Repeat::X_y.
Definition BackgroundImage.h:46
#define AUI_ENUM_VALUES(enum_t,...)
Defines all enum values for AEnumerate.
Definition AEnumerate.h:208
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:50
AString toString() const override
Definition unset.h:28