Line data Source code
1 : /**
2 : Copyright (c) 2023 Stappler LLC <admin@stappler.dev>
3 :
4 : Permission is hereby granted, free of charge, to any person obtaining a copy
5 : of this software and associated documentation files (the "Software"), to deal
6 : in the Software without restriction, including without limitation the rights
7 : to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 : copies of the Software, and to permit persons to whom the Software is
9 : furnished to do so, subject to the following conditions:
10 :
11 : The above copyright notice and this permission notice shall be included in
12 : all copies or substantial portions of the Software.
13 :
14 : THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 : IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 : FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 : AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 : LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 : OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 : THE SOFTWARE.
21 : **/
22 :
23 : #ifndef XENOLITH_RENDERER_MATERIAL2D_BASE_MATERIALSURFACESTYLE_H_
24 : #define XENOLITH_RENDERER_MATERIAL2D_BASE_MATERIALSURFACESTYLE_H_
25 :
26 : #include "MaterialColorScheme.h"
27 :
28 : namespace STAPPLER_VERSIONIZED stappler::xenolith::material2d {
29 :
30 : class StyleContainer;
31 : class SurfaceInterior;
32 :
33 : enum class Elevation {
34 : Level0, // 0dp
35 : Level1, // 1dp 5%
36 : Level2, // 3dp 8%
37 : Level3, // 6dp 11%
38 : Level4, // 8dp 12%
39 : Level5, // 12dp 14%
40 : };
41 :
42 : enum class ShapeFamily {
43 : RoundedCorners,
44 : CutCorners,
45 : };
46 :
47 : enum class ShapeStyle {
48 : None, // 0dp
49 : ExtraSmall, // 4dp
50 : Small, // 8dp
51 : Medium, // 12dp
52 : Large, // 16dp
53 : ExtraLarge, // 28dp
54 : Full // .
55 : };
56 :
57 : enum class NodeStyle {
58 : SurfaceTonal,
59 : SurfaceTonalElevated,
60 : Elevated,
61 : Filled,
62 : FilledElevated,
63 : FilledTonal,
64 : FilledTonalElevated,
65 : Outlined,
66 : Text
67 : };
68 :
69 : enum class ActivityState {
70 : Enabled,
71 : Disabled,
72 : Hovered,
73 : Focused,
74 : Pressed
75 : };
76 :
77 : struct SurfaceStyleData;
78 :
79 : struct SurfaceStyle {
80 : static SurfaceStyle Background;
81 : static constexpr uint32_t PrimarySchemeTag = maxOf<uint32_t>();
82 :
83 612 : constexpr SurfaceStyle() = default;
84 :
85 : template<typename ... Args>
86 512 : constexpr SurfaceStyle(Args && ... args) {
87 512 : define(std::forward<Args>(args)...);
88 512 : }
89 :
90 : constexpr void setup(const SurfaceStyle &value) { *this = value; }
91 146 : constexpr void setup(uint32_t value) { schemeTag = value; }
92 116 : constexpr void setup(ColorRole value) { colorRole = value; }
93 60 : constexpr void setup(Elevation value) { elevation = value; }
94 8 : constexpr void setup(ShapeFamily value) { shapeFamily = value; }
95 52 : constexpr void setup(ShapeStyle value) { shapeStyle = value; }
96 124 : constexpr void setup(NodeStyle value) { nodeStyle = value; }
97 2 : constexpr void setup(ActivityState value) { activityState = value; }
98 :
99 : template <typename T>
100 : constexpr void setup(const T &) { static_assert("Invalid type"); }
101 :
102 :
103 : template <typename T>
104 892 : constexpr void define(T && t) {
105 892 : setup(std::forward<T>(t));
106 892 : }
107 :
108 : template <typename T, typename ... Args>
109 1084 : constexpr void define(T && t, Args && ... args) {
110 1084 : define(std::forward<T>(t));
111 1084 : define(std::forward<Args>(args)...);
112 1084 : }
113 :
114 : bool apply(SurfaceStyleData &data, const Size2 &contentSize, const StyleContainer *, const SurfaceInterior *interior);
115 :
116 713 : constexpr bool operator==(const SurfaceStyle &) const = default;
117 707 : constexpr bool operator!=(const SurfaceStyle &) const = default;
118 :
119 713 : uint32_t schemeTag = PrimarySchemeTag;
120 713 : ColorRole colorRole = ColorRole::Primary;
121 703 : Elevation elevation = Elevation::Level0;
122 583 : ShapeFamily shapeFamily = ShapeFamily::RoundedCorners;
123 583 : ShapeStyle shapeStyle = ShapeStyle::None;
124 463 : NodeStyle nodeStyle = NodeStyle::SurfaceTonal;
125 403 : ActivityState activityState = ActivityState::Enabled;
126 : };
127 :
128 : struct SurfaceStyleData {
129 : static SurfaceStyleData progress(const SurfaceStyleData &, const SurfaceStyleData &, float p);
130 :
131 4721 : uint32_t schemeTag = SurfaceStyle::PrimarySchemeTag;
132 4721 : ShapeFamily shapeFamily = ShapeFamily::RoundedCorners;
133 4721 : ThemeType themeType = ThemeType::LightTheme;
134 4721 : Color4F colorScheme;
135 4721 : Color4F colorElevation;
136 4721 : ColorHCT colorHCT;
137 4721 : ColorHCT colorBackground;
138 4721 : ColorHCT colorOn;
139 4721 : float cornerRadius = 0.0f;
140 4721 : float elevationValue = 0.0f;
141 4721 : float shadowValue = 0.0f;
142 4721 : float outlineValue = 0.0f;
143 :
144 4721 : bool operator==(const SurfaceStyleData &) const = default;
145 4721 : bool operator!=(const SurfaceStyleData &) const = default;
146 : };
147 :
148 : }
149 :
150 : namespace STAPPLER_VERSIONIZED stappler {
151 :
152 1551 : inline auto progress(const xenolith::material2d::SurfaceStyleData &l, const xenolith::material2d::SurfaceStyleData &r, float p) {
153 1551 : return xenolith::material2d::SurfaceStyleData::progress(l, r, p);
154 : }
155 :
156 : }
157 :
158 : #endif /* XENOLITH_RENDERER_MATERIAL2D_BASE_MATERIALSURFACESTYLE_H_ */
|