Skip to content

Commit 567cd70

Browse files
committed
Merge branch 'skia_2024'
2 parents a43c706 + 05d7ad2 commit 567cd70

File tree

1 file changed

+170
-14
lines changed

1 file changed

+170
-14
lines changed

lib/include/elements/element/style/button.hpp

+170-14
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,37 @@
1818

1919
namespace cycfi::elements
2020
{
21-
////////////////////////////////////////////////////////////////////////////
22-
// Buttons
23-
////////////////////////////////////////////////////////////////////////////
21+
/**
22+
* \brief Base class for button styling.
23+
*
24+
* The `button_styler_base` class is responsible for providing the basic
25+
* styling and behavior for buttons. It inherits from `element` and
26+
* `basic_receiver<button_state>`, allowing it to handle button states
27+
* and interact with the user interface.
28+
*
29+
* This class provides the foundational functionality for button styling,
30+
* including cursor handling and control requirements.
31+
*/
2432
struct button_styler_base : element, basic_receiver<button_state>
2533
{
2634
bool cursor(context const& ctx, point p, cursor_tracking status) override;
2735
bool wants_control() const override;
2836
};
2937

38+
/**
39+
* \brief
40+
* Default button styler class.
41+
*
42+
* The `default_button_styler` class provides the default styling and
43+
* behavior for buttons. It inherits from `button_styler_base` and
44+
* `text_reader_u8`, allowing it to handle button states and retrieve text
45+
* via the `get_text()` member function.
46+
*
47+
* This class includes various customization options for button
48+
* appearance, such as icon placement, label alignment, and corner radius.
49+
* It also provides functions to retrieve colors, scales, and margins for
50+
* the button.
51+
*/
3052
struct default_button_styler : button_styler_base, text_reader
3153
{
3254
public:
@@ -65,6 +87,7 @@ namespace cycfi::elements
6587
concept ButtonStyler = std::is_base_of_v<default_button_styler, std::decay_t<T>>;
6688
}
6789

90+
6891
template <concepts::ButtonStyler Base>
6992
struct basic_button_styler_base : Base, text_writer
7093
{
@@ -83,6 +106,16 @@ namespace cycfi::elements
83106
std::string _text;
84107
};
85108

109+
/**
110+
* \brief
111+
* Button styler with size.
112+
*
113+
* The `button_styler_with_size` class provides the ability to set the
114+
* size of a button. The size is relative to the default size of the
115+
* button. A size of 1.0 represents the default size, values greater
116+
* than 1.0 scale the button up, and values less than 1.0 scale the
117+
* button down.
118+
*/
86119
template <concepts::ButtonStyler Base>
87120
struct button_styler_with_size : Base
88121
{
@@ -100,6 +133,13 @@ namespace cycfi::elements
100133
float _size;
101134
};
102135

136+
/**
137+
* \brief
138+
* Button styler with body color.
139+
*
140+
* The `button_styler_with_body_color` class provides the ability to
141+
* set the body color of a button.
142+
*/
103143
template <concepts::ButtonStyler Base>
104144
struct button_styler_with_body_color : Base
105145
{
@@ -117,6 +157,13 @@ namespace cycfi::elements
117157
color _color;
118158
};
119159

160+
/**
161+
* \brief
162+
* Button styler with active body color.
163+
*
164+
* The `button_styler_with_active_body_color` class provides the
165+
* ability to set the active body color of a button.
166+
*/
120167
template <concepts::ButtonStyler Base>
121168
struct button_styler_with_active_body_color : Base
122169
{
@@ -134,6 +181,13 @@ namespace cycfi::elements
134181
color _color;
135182
};
136183

184+
/**
185+
* \brief
186+
* Button styler with text color.
187+
*
188+
* The `button_styler_with_text_color` class provides the ability to
189+
* set the text color of a button.
190+
*/
137191
template <concepts::ButtonStyler Base>
138192
struct button_styler_with_text_color : Base
139193
{
@@ -151,6 +205,13 @@ namespace cycfi::elements
151205
color _color;
152206
};
153207

208+
/**
209+
* \brief
210+
* Button styler with icon.
211+
*
212+
* The `button_styler_with_icon` class provides the ability to set the
213+
* icon of a button.
214+
*/
154215
template <concepts::ButtonStyler Base>
155216
struct button_styler_with_icon : Base
156217
{
@@ -171,6 +232,13 @@ namespace cycfi::elements
171232
icon_placement _icon_placement;
172233
};
173234

235+
/**
236+
* \brief
237+
* Button styler with icon placement.
238+
*
239+
* The `button_styler_with_icon_placement` class provides the ability
240+
* to set the icon placement of a button.
241+
*/
174242
template <concepts::ButtonStyler Base>
175243
struct button_styler_with_icon_placement : Base
176244
{
@@ -191,6 +259,13 @@ namespace cycfi::elements
191259
icon_placement _icon_placement;
192260
};
193261

262+
/**
263+
* \brief
264+
* Button styler with icon color.
265+
*
266+
* The `button_styler_with_icon_color` class provides the ability to
267+
* set the icon color of a button.
268+
*/
194269
template <concepts::ButtonStyler Base>
195270
struct button_styler_with_icon_color : Base
196271
{
@@ -208,6 +283,13 @@ namespace cycfi::elements
208283
color _color;
209284
};
210285

286+
/**
287+
* \brief
288+
* Button styler with label alignment.
289+
*
290+
* The `button_styler_with_label_alignment` class provides the ability
291+
* to set the label alignment of a button.
292+
*/
211293
template <concepts::ButtonStyler Base>
212294
struct button_styler_with_label_alignment : Base
213295
{
@@ -220,14 +302,22 @@ namespace cycfi::elements
220302

221303
label_alignment get_label_alignment() const override;
222304
void set_label_alignment(label_alignment alignment);
223-
void align_right();
224305
void align_left();
306+
void align_center();
307+
void align_right();
225308

226309
private:
227310

228311
label_alignment _label_alignment;
229312
};
230313

314+
/**
315+
* \brief
316+
* Button styler with margin.
317+
*
318+
* The `button_styler_with_margin` class provides the ability to set
319+
* the margin of a button.
320+
*/
231321
template <concepts::ButtonStyler Base>
232322
struct button_styler_with_margin : Base
233323
{
@@ -245,6 +335,13 @@ namespace cycfi::elements
245335
rect _margin;
246336
};
247337

338+
/**
339+
* \brief
340+
* Button styler with corner radius.
341+
*
342+
* The `button_styler_with_corner_radius` class provides the ability to
343+
* set the corner radius of a button.
344+
*/
248345
template <concepts::ButtonStyler Base>
249346
struct button_styler_with_corner_radius : Base
250347
{
@@ -263,6 +360,23 @@ namespace cycfi::elements
263360
float _radius;
264361
};
265362

363+
/**
364+
* \brief
365+
* Button styler with rounded corners on one half.
366+
*
367+
* The `button_styler_rounded_half` class provides styling for buttons
368+
* with rounded corners on one half, based on the specified direction.
369+
* This class allows customization of the corner radius for two corners
370+
* on the specified side of the button, as determined by the
371+
* `Direction`.
372+
*
373+
* \tparam Base
374+
* The base button styler class. Must conform to the `ButtonStyler`
375+
* concept.
376+
*
377+
* \tparam Direction
378+
* The direction specifying which half of the button has rounded corners.
379+
*/
266380
template <concepts::ButtonStyler Base, default_button_styler::direction Direction>
267381
struct button_styler_rounded_half : Base
268382
{
@@ -278,6 +392,7 @@ namespace cycfi::elements
278392
virtual float get_corner_radius_top_right() const override;
279393
virtual float get_corner_radius_bottom_left() const override;
280394
virtual float get_corner_radius_bottom_right() const override;
395+
void set_corner_radius(float r);
281396

282397
private:
283398

@@ -309,13 +424,15 @@ namespace cycfi::elements
309424
constexpr static bool has_default_corner_radius = false;
310425

311426
button_styler_rounded_corner(Base base, float r)
312-
: Base(std::move(base)), _radius(r)
427+
: Base(std::move(base))
428+
, _radius(r)
313429
{}
314430

315431
virtual float get_corner_radius_top_left() const override;
316432
virtual float get_corner_radius_top_right() const override;
317433
virtual float get_corner_radius_bottom_left() const override;
318434
virtual float get_corner_radius_bottom_right() const override;
435+
void set_corner_radius(float r);
319436

320437
private:
321438

@@ -334,17 +451,24 @@ namespace cycfi::elements
334451
float top_right,
335452
float bottom_right,
336453
float bottom_left
337-
) : Base(std::move(base)),
338-
_top_left(top_left),
339-
_top_right(top_right),
340-
_bottom_right(bottom_right),
341-
_bottom_left(bottom_left)
454+
)
455+
: Base(std::move(base)),
456+
_top_left(top_left),
457+
_top_right(top_right),
458+
_bottom_right(bottom_right),
459+
_bottom_left(bottom_left)
342460
{}
343461

344462
virtual float get_corner_radius_top_left() const override;
345463
virtual float get_corner_radius_top_right() const override;
346464
virtual float get_corner_radius_bottom_left() const override;
347465
virtual float get_corner_radius_bottom_right() const override;
466+
void set_corner_radius(
467+
float top_left,
468+
float top_right,
469+
float bottom_right,
470+
float bottom_left
471+
);
348472

349473
private:
350474

@@ -812,15 +936,21 @@ namespace cycfi::elements
812936
}
813937

814938
template <concepts::ButtonStyler Base>
815-
inline void button_styler_with_label_alignment<Base>::align_right()
939+
inline void button_styler_with_label_alignment<Base>::align_left()
816940
{
817-
_label_alignment = label_alignment::align_right;
941+
_label_alignment = label_alignment::align_left;
818942
}
819943

820944
template <concepts::ButtonStyler Base>
821-
inline void button_styler_with_label_alignment<Base>::align_left()
945+
inline void button_styler_with_label_alignment<Base>::align_center()
822946
{
823-
_label_alignment = label_alignment::align_left;
947+
_label_alignment = label_alignment::align_center;
948+
}
949+
950+
template <concepts::ButtonStyler Base>
951+
inline void button_styler_with_label_alignment<Base>::align_right()
952+
{
953+
_label_alignment = label_alignment::align_right;
824954
}
825955

826956
template <concepts::ButtonStyler Base>
@@ -891,6 +1021,12 @@ namespace cycfi::elements
8911021
return 0.0f;
8921022
}
8931023

1024+
template <concepts::ButtonStyler Base, default_button_styler::direction Direction>
1025+
inline void button_styler_rounded_half<Base, Direction>::set_corner_radius(float r)
1026+
{
1027+
_radius = r;
1028+
}
1029+
8941030
template <concepts::ButtonStyler Base, default_button_styler::direction Direction>
8951031
inline float button_styler_rounded_half_default<Base, Direction>::get_corner_radius_top_left() const
8961032
{
@@ -979,6 +1115,12 @@ namespace cycfi::elements
9791115
return 0.0f;
9801116
}
9811117

1118+
template <concepts::ButtonStyler Base, default_button_styler::corner Corner>
1119+
inline void button_styler_rounded_corner<Base, Corner>::set_corner_radius(float r)
1120+
{
1121+
_radius = r;
1122+
}
1123+
9821124
template <concepts::ButtonStyler Base>
9831125
inline float button_styler_with_individual_corner_radii<Base>::get_corner_radius_top_left() const
9841126
{
@@ -1003,6 +1145,20 @@ namespace cycfi::elements
10031145
return _bottom_right;
10041146
}
10051147

1148+
template <concepts::ButtonStyler Base>
1149+
inline void button_styler_with_individual_corner_radii<Base>::set_corner_radius(
1150+
float top_left,
1151+
float top_right,
1152+
float bottom_right,
1153+
float bottom_left
1154+
)
1155+
{
1156+
_top_left = top_left;
1157+
_top_right = top_right;
1158+
_bottom_right = bottom_right;
1159+
_bottom_left = bottom_left;
1160+
}
1161+
10061162
template <concepts::ButtonStyler Base>
10071163
inline typename button_styler_gen<Base>::gen_size
10081164
button_styler_gen<Base>::size(float size) const

0 commit comments

Comments
 (0)