Simple GUI Library
default_skins.h
Go to the documentation of this file.
1/**
2 * @author Nikita Mochalov (github.com/tralf-strues)
3 * @file default_skins.h
4 * @date 2021-11-08
5 *
6 * @copyright Copyright (c) 2021
7 */
8
9#pragma once
10
11#include "sml/events/listener_notifier.h"
12#include "../image_view.h"
13#include "../shapes/text.h"
14#include "../shapes/rectangle.h"
15#include "../../paint/background.h"
16#include "../../paint/border.h"
17#include "../../paint/insets.h"
18#include "../../paint/shadow.h"
19#include "skin.h"
20
21namespace Sgl
22{
23 class Button;
24 class Slider;
25 class ScrollBar;
26 class BoxContainer;
27 class ScrollPane;
28
29namespace DefaultSkins
30{
31 extern Sml::Font* g_DefaultFont;
32
33 //------------------------------------------------------------------------------
34 // ButtonBaseSkin
35 //------------------------------------------------------------------------------
36 class ButtonBaseSkinEventListener;
37
38 class ButtonBaseSkin : public Sgl::BaseSkin<Button>
39 {
40 public:
42 {
43 Insets paddingLabelOnly{0};
44 Insets paddingIconOnly{0};
45 Insets paddingIconAndLabel{0};
46 int32_t margin = 0;
47 Border border{0, Sml::COLOR_BLACK};
48
49 StaticStyle(const Insets& padding, int32_t margin, const Border& border);
50
51 StaticStyle(const Insets& paddingLabelOnly,
52 const Insets& paddingIconOnly,
53 const Insets& paddingIconAndLabel,
54 int32_t margin,
55 const Border& border);
56 };
57
59 {
60 enum class Type
61 {
62 IDLE,
63 HOVERED,
64 PRESSED
65 };
66
67 Sml::Color foreground;
68 const Background* background;
69 };
70
71 public:
73 const StaticStyle* staticStyle,
74 const InteractionStyle* idleStyle,
75 const InteractionStyle* hoveredStyle,
76 const InteractionStyle* pressedStyle);
77
78 ButtonBaseSkin(const StaticStyle* staticStyle,
79 const InteractionStyle* idleStyle,
80 const InteractionStyle* hoveredStyle,
81 const InteractionStyle* pressedStyle);
82
83 virtual void dispose() override;
84 virtual void attach(Button* button) override;
85
86 virtual void prerenderControl() override;
87
88 virtual const Control* getControl() const override;
89 virtual Control* getModifiableControl() override;
90
91 virtual int32_t computePrefHeight(int32_t width = -1) const override;
92 virtual int32_t computePrefWidth(int32_t height = -1) const override;
93
94 virtual void layoutChildren() override;
95
96 void applyInteractionStyle(InteractionStyle::Type type);
97
98 protected:
99 const StaticStyle* m_StaticStyle = nullptr;
100
101 const InteractionStyle* m_IdleStyle = nullptr;
102 const InteractionStyle* m_HoveredStyle = nullptr;
103 const InteractionStyle* m_PressedStyle = nullptr;
104
105 Sgl::Button* m_Button = nullptr;
106 ButtonBaseSkinEventListener* m_Handler = nullptr;
107
108 Sgl::Text m_Text;
109 Sgl::ImageView m_Icon;
110
111 int32_t getMargin() const;
112
113 void applyStaticStyle();
114 };
115
116 //------------------------------------------------------------------------------
117 // ButtonPlaneSkin
118 //------------------------------------------------------------------------------
120 {
121 public:
124 };
125
126 //------------------------------------------------------------------------------
127 // ButtonSkin
128 //------------------------------------------------------------------------------
130 {
131 public:
132 static const Insets PADDING_LABEL_ONLY;
133 static const Insets PADDING_ICON_ONLY;
134 static const Insets PADDING_LABEL_AND_ICON;
135 static const int32_t MARGIN;
136 static const Border BORDER;
137 static const StaticStyle STATIC_STYLE;
138
139 static const Sml::Color IDLE_FOREGROUND;
140 static const ColorFill IDLE_BACKGROUND_FILL;
141 static const Background IDLE_BACKGROUND;
142 static const InteractionStyle IDLE_STYLE;
143
144 static const Sml::Color HOVERED_FOREGROUND;
145 static const ColorFill HOVERED_BACKGROUND_FILL;
146 static const Background HOVERED_BACKGROUND;
147 static const InteractionStyle HOVERED_STYLE;
148
149 public:
150 ButtonSkin();
151 ButtonSkin(Sgl::Button* button);
152 };
153
154 //------------------------------------------------------------------------------
155 // MenuItemSkin
156 //------------------------------------------------------------------------------
158 {
159 public:
160 static const Insets PADDING;
161 static const int32_t MARGIN;
162 static const Border BORDER;
163 static const StaticStyle STATIC_STYLE;
164
165 static const Sml::Color IDLE_FOREGROUND;
166 static const ColorFill IDLE_BACKGROUND_FILL;
167 static const Background IDLE_BACKGROUND;
168 static const InteractionStyle IDLE_STYLE;
169
170 static const Sml::Color HOVERED_FOREGROUND;
171 static const ColorFill HOVERED_BACKGROUND_FILL;
172 static const Background HOVERED_BACKGROUND;
173 static const InteractionStyle HOVERED_STYLE;
174
175 public:
176 MenuItemSkin();
177 MenuItemSkin(Sgl::Button* button);
178 };
179
180 //------------------------------------------------------------------------------
181 // SliderSkin
182 //------------------------------------------------------------------------------
185
186 class SliderSkin : public Sgl::BaseSkin<Slider>
187 {
188 public:
189 static const ShadowSpecification KNOB_SHADOW;
190 static const ColorFill NOT_SELECTED_FILL;
191 static const ColorFill SELECTED_FILL;
192 static const Sml::Color KNOB_COLOR;
193 static const int32_t THICKNESS;
194 static const int32_t KNOB_SIZE_ALONG;
195 static const int32_t KNOB_SIZE_ACROSS;
196
197 public:
198 SliderSkin(const Fill* notSelectedFill,
199 const Fill* selectedFill,
200 Sml::Color knobColor = KNOB_COLOR,
201 int32_t thickness = THICKNESS,
202 int32_t knobSizeAlong = KNOB_SIZE_ALONG,
203 int32_t knobSizeAcross = KNOB_SIZE_ACROSS);
204
205 SliderSkin(Slider* slider);
206
207 virtual void dispose() override;
208 virtual void attach(Slider* slider) override;
209
210 virtual Component* getHitComponent(int32_t x, int32_t y) override;
211 virtual void prerenderControl() override;
212
213 virtual const Control* getControl() const override;
214 virtual Control* getModifiableControl() override;
215
216 virtual int32_t computePrefWidth(int32_t height = -1) const override;
217 virtual int32_t computePrefHeight(int32_t width = -1) const override;
218
219 virtual void layoutChildren() override;
220
221 int32_t getThickness() const;
222 void setThickness(int32_t thickness);
223
224 int32_t getKnobSizeAlong() const;
225 void setKnobSizeAlong(int32_t knobWidth);
226
227 int32_t getKnobSizeAcross() const;
228 void setKnobSizeAcross(int32_t knobSizeAcross);
229
230 void setKnobShadow(const ShadowSpecification* shadow);
231
232 Sml::Rectangle<int32_t> getLineRect();
233 Sml::Rectangle<int32_t> getKnobRect();
234 float getPercentage();
235
236 private:
237 Slider* m_Slider = nullptr;
238 SliderSkinDragListener* m_DragListener = nullptr;
239 SliderSkinMousePressListener* m_MousePressListener = nullptr;
240
241 const Fill* m_NotSelectedFill = nullptr;
242 const Fill* m_SelectedFill = nullptr;
243
244 int32_t m_Thickness = 0;
245 int32_t m_KnobSizeAlong = 0;
246 int32_t m_KnobSizeAcross = 0;
247
248 Rectangle* m_KnobRect = nullptr;
249 };
250
251 //------------------------------------------------------------------------------
252 // ScrollBarSkin
253 //------------------------------------------------------------------------------
254 class ScrollBarSkin : public Sgl::BaseSkin<ScrollBar>
255 {
256 public:
257 static const Sml::Color KNOB_COLOR;
258 static const ShadowSpecification KNOB_SHADOW;
259
260 public:
261 ScrollBarSkin(ScrollBar* scrollBar);
262
263 virtual void dispose() override;
264 virtual void attach(ScrollBar* scrollBar) override;
265
266 virtual const Control* getControl() const override;
267 virtual Control* getModifiableControl() override;
268
269 virtual void layoutChildren() override;
270
271 private:
272 ScrollBar* m_ScrollBar = nullptr;
273
274 BoxContainer* m_Box = nullptr;
275 SliderSkin* m_SliderSkin = nullptr;
276 Slider* m_Slider = nullptr;
277 Button* m_DecrementButton = nullptr;
278 Button* m_IncrementButton = nullptr;
279 };
280
281 //------------------------------------------------------------------------------
282 // ScrollPaneSkin
283 //------------------------------------------------------------------------------
284 class ScrollPaneSkin : public Sgl::BaseSkin<ScrollPane>
285 {
286 public:
287 ScrollPaneSkin(ScrollPane* scrollPane);
288
289 virtual void dispose() override;
290 virtual void attach(ScrollPane* scrollPane) override;
291
292 virtual Component* getHitComponent(int32_t x, int32_t y) override;
293
294 virtual void prerenderControl() override;
295
296 virtual const Control* getControl() const override;
297 virtual Control* getModifiableControl() override;
298
299 virtual int32_t computePrefWidth(int32_t height = -1) const override;
300 virtual int32_t computePrefHeight(int32_t width = -1) const override;
301
302 virtual void layoutChildren() override;
303
304 private:
305 ScrollPane* m_ScrollPane = nullptr;
306 Component* m_PrevContent = nullptr;
307
308 ScrollBar* m_HorizontalScrollBar = nullptr;
309 ScrollBar* m_VerticalScrollBar = nullptr;
310
311 Sml::Texture* m_RenderedContentTexture = nullptr;
312
313 // Sml::PropertyChangeListener<float>* m_HorizontalScrollListener = nullptr;
314 // Sml::PropertyChangeListener<float>* m_VerticalScrollListener = nullptr;
315
316 Sml::Rectangle<int32_t> computeContentRegion() const;
317 void updateRenderedContentTexture();
318 };
319}
320}
Basic list-like container which lays out children in a line one after another.
Definition: box_container.h:26
virtual void dispose() override
Should be called by Control when this skin is replaced.
virtual void dispose() override
Should be called by Control when this skin is replaced.
virtual void dispose() override
Should be called by Control when this skin is replaced.
virtual void dispose() override
Should be called by Control when this skin is replaced.
Definition: fill.h:19
Definition: text.h:17