AeonGUI
A portable video game graphic user interface library.
Loading...
Searching...
No Matches
Attribute.hpp
1/*
2Copyright (C) 2024-2026 Rodrigo Jose Hernandez Cordoba
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16#ifndef AEONGUI_ATTRIBUTE_H
17#define AEONGUI_ATTRIBUTE_H
18#include <string>
19#include <unordered_map>
20#include <variant>
21#include <cstdint>
22#include <cstddef>
23#include "aeongui/Platform.hpp"
24namespace AeonGUI
25{
30 struct ViewBox
31 {
32 double min_x{};
33 double min_y{};
34 double width{};
35 double height{};
36 };
37
44 {
45 public:
51 PreserveAspectRatio ( std::string_view aString );
53 enum MinMidMax : uint8_t
54 {
55 Min = 0x1,
56 Mid = 0x2,
57 Max = 0x3
58 };
59
60 enum Align : uint8_t
61 {
62 none = 0,
63 XMinYMin = Min << 4 | Min,
64 XMinYMid = Min << 4 | Mid,
65 XMinYMax = Min << 4 | Max,
66 XMidYMin = Mid << 4 | Min,
67 XMidYMid = Mid << 4 | Mid,
68 XMidYMax = Mid << 4 | Max,
69 XMaxYMin = Max << 4 | Min,
70 XMaxYMid = Max << 4 | Mid,
71 XMaxYMax = Max << 4 | Max
72 };
73
74 enum class MeetOrSlice
75 {
76 Meet,
77 Slice
78 };
79
82 Align GetAlign() const;
86 MinMidMax GetAlignX() const;
90 MinMidMax GetAlignY() const;
94 MeetOrSlice GetMeetOrSlice() const;
95 private:
96 Align mAlign{Align::XMidYMid};
97 MeetOrSlice mMeetOrSlice{MeetOrSlice::Meet};
98 };
99
105 template<typename T> T FromString ( const std::string_view aString )
106 {
107 return T{aString};
108 }
109
116 template<typename T> T FromString ( const char *aAttribute, const std::unordered_map<std::string, std::string>& aAttributes )
117 {
118 return T{FromString<T> ( aAttributes.find ( aAttribute ) != aAttributes.end() ? aAttributes.at ( aAttribute ) : "" ) };
119 }
120
125 template<> double FromString<double> ( const std::string_view aString );
126}
127#endif
Platform-specific DLL import/export macros and compiler helpers.
PreserveAspectRatio()=default
Default constructor. Initializes to xMidYMid meet.
Align
Combined X and Y alignment values for preserveAspectRatio.
Definition Attribute.hpp:61
@ XMaxYMid
Align X-max, Y-mid.
Definition Attribute.hpp:70
@ XMinYMid
Align X-min, Y-mid.
Definition Attribute.hpp:64
@ XMinYMin
Align X-min, Y-min.
Definition Attribute.hpp:63
@ XMaxYMax
Align X-max, Y-max.
Definition Attribute.hpp:71
@ none
Do not force uniform scaling.
Definition Attribute.hpp:62
@ XMidYMax
Align X-mid, Y-max.
Definition Attribute.hpp:68
@ XMidYMid
Align X-mid, Y-mid (default).
Definition Attribute.hpp:67
@ XMaxYMin
Align X-max, Y-min.
Definition Attribute.hpp:69
@ XMidYMin
Align X-mid, Y-min.
Definition Attribute.hpp:66
@ XMinYMax
Align X-min, Y-max.
Definition Attribute.hpp:65
MinMidMax
Axis alignment selector values.
Definition Attribute.hpp:54
@ Min
Align to the minimum (start) edge.
Definition Attribute.hpp:55
@ Mid
Align to the midpoint.
Definition Attribute.hpp:56
@ Max
Align to the maximum (end) edge.
Definition Attribute.hpp:57
MeetOrSlice
Meet-or-slice scaling strategy.
Definition Attribute.hpp:75
SVG viewBox attribute value.
Definition Attribute.hpp:31
double min_x
Minimum X coordinate of the viewport.
Definition Attribute.hpp:32
double height
Height of the viewport.
Definition Attribute.hpp:35
double width
Width of the viewport.
Definition Attribute.hpp:34
double min_y
Minimum Y coordinate of the viewport.
Definition Attribute.hpp:33