18
18
19
19
namespace cycfi ::elements
20
20
{
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
+ */
24
32
struct button_styler_base : element, basic_receiver<button_state>
25
33
{
26
34
bool cursor (context const & ctx, point p, cursor_tracking status) override ;
27
35
bool wants_control () const override ;
28
36
};
29
37
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
+ */
30
52
struct default_button_styler : button_styler_base, text_reader
31
53
{
32
54
public:
@@ -65,6 +87,7 @@ namespace cycfi::elements
65
87
concept ButtonStyler = std::is_base_of_v<default_button_styler, std::decay_t <T>>;
66
88
}
67
89
90
+
68
91
template <concepts::ButtonStyler Base>
69
92
struct basic_button_styler_base : Base, text_writer
70
93
{
@@ -83,6 +106,16 @@ namespace cycfi::elements
83
106
std::string _text;
84
107
};
85
108
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
+ */
86
119
template <concepts::ButtonStyler Base>
87
120
struct button_styler_with_size : Base
88
121
{
@@ -100,6 +133,13 @@ namespace cycfi::elements
100
133
float _size;
101
134
};
102
135
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
+ */
103
143
template <concepts::ButtonStyler Base>
104
144
struct button_styler_with_body_color : Base
105
145
{
@@ -117,6 +157,13 @@ namespace cycfi::elements
117
157
color _color;
118
158
};
119
159
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
+ */
120
167
template <concepts::ButtonStyler Base>
121
168
struct button_styler_with_active_body_color : Base
122
169
{
@@ -134,6 +181,13 @@ namespace cycfi::elements
134
181
color _color;
135
182
};
136
183
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
+ */
137
191
template <concepts::ButtonStyler Base>
138
192
struct button_styler_with_text_color : Base
139
193
{
@@ -151,6 +205,13 @@ namespace cycfi::elements
151
205
color _color;
152
206
};
153
207
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
+ */
154
215
template <concepts::ButtonStyler Base>
155
216
struct button_styler_with_icon : Base
156
217
{
@@ -171,6 +232,13 @@ namespace cycfi::elements
171
232
icon_placement _icon_placement;
172
233
};
173
234
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
+ */
174
242
template <concepts::ButtonStyler Base>
175
243
struct button_styler_with_icon_placement : Base
176
244
{
@@ -191,6 +259,13 @@ namespace cycfi::elements
191
259
icon_placement _icon_placement;
192
260
};
193
261
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
+ */
194
269
template <concepts::ButtonStyler Base>
195
270
struct button_styler_with_icon_color : Base
196
271
{
@@ -208,6 +283,13 @@ namespace cycfi::elements
208
283
color _color;
209
284
};
210
285
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
+ */
211
293
template <concepts::ButtonStyler Base>
212
294
struct button_styler_with_label_alignment : Base
213
295
{
@@ -220,14 +302,22 @@ namespace cycfi::elements
220
302
221
303
label_alignment get_label_alignment () const override ;
222
304
void set_label_alignment (label_alignment alignment);
223
- void align_right ();
224
305
void align_left ();
306
+ void align_center ();
307
+ void align_right ();
225
308
226
309
private:
227
310
228
311
label_alignment _label_alignment;
229
312
};
230
313
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
+ */
231
321
template <concepts::ButtonStyler Base>
232
322
struct button_styler_with_margin : Base
233
323
{
@@ -245,6 +335,13 @@ namespace cycfi::elements
245
335
rect _margin;
246
336
};
247
337
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
+ */
248
345
template <concepts::ButtonStyler Base>
249
346
struct button_styler_with_corner_radius : Base
250
347
{
@@ -263,6 +360,23 @@ namespace cycfi::elements
263
360
float _radius;
264
361
};
265
362
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
+ */
266
380
template <concepts::ButtonStyler Base, default_button_styler::direction Direction>
267
381
struct button_styler_rounded_half : Base
268
382
{
@@ -278,6 +392,7 @@ namespace cycfi::elements
278
392
virtual float get_corner_radius_top_right () const override ;
279
393
virtual float get_corner_radius_bottom_left () const override ;
280
394
virtual float get_corner_radius_bottom_right () const override ;
395
+ void set_corner_radius (float r);
281
396
282
397
private:
283
398
@@ -309,13 +424,15 @@ namespace cycfi::elements
309
424
constexpr static bool has_default_corner_radius = false ;
310
425
311
426
button_styler_rounded_corner (Base base, float r)
312
- : Base(std::move(base)), _radius(r)
427
+ : Base(std::move(base))
428
+ , _radius(r)
313
429
{}
314
430
315
431
virtual float get_corner_radius_top_left () const override ;
316
432
virtual float get_corner_radius_top_right () const override ;
317
433
virtual float get_corner_radius_bottom_left () const override ;
318
434
virtual float get_corner_radius_bottom_right () const override ;
435
+ void set_corner_radius (float r);
319
436
320
437
private:
321
438
@@ -334,17 +451,24 @@ namespace cycfi::elements
334
451
float top_right,
335
452
float bottom_right,
336
453
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)
342
460
{}
343
461
344
462
virtual float get_corner_radius_top_left () const override ;
345
463
virtual float get_corner_radius_top_right () const override ;
346
464
virtual float get_corner_radius_bottom_left () const override ;
347
465
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
+ );
348
472
349
473
private:
350
474
@@ -812,15 +936,21 @@ namespace cycfi::elements
812
936
}
813
937
814
938
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 ()
816
940
{
817
- _label_alignment = label_alignment::align_right ;
941
+ _label_alignment = label_alignment::align_left ;
818
942
}
819
943
820
944
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 ()
822
946
{
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;
824
954
}
825
955
826
956
template <concepts::ButtonStyler Base>
@@ -891,6 +1021,12 @@ namespace cycfi::elements
891
1021
return 0 .0f ;
892
1022
}
893
1023
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
+
894
1030
template <concepts::ButtonStyler Base, default_button_styler::direction Direction>
895
1031
inline float button_styler_rounded_half_default<Base, Direction>::get_corner_radius_top_left() const
896
1032
{
@@ -979,6 +1115,12 @@ namespace cycfi::elements
979
1115
return 0 .0f ;
980
1116
}
981
1117
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
+
982
1124
template <concepts::ButtonStyler Base>
983
1125
inline float button_styler_with_individual_corner_radii<Base>::get_corner_radius_top_left() const
984
1126
{
@@ -1003,6 +1145,20 @@ namespace cycfi::elements
1003
1145
return _bottom_right;
1004
1146
}
1005
1147
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
+
1006
1162
template <concepts::ButtonStyler Base>
1007
1163
inline typename button_styler_gen<Base>::gen_size
1008
1164
button_styler_gen<Base>::size(float size) const
0 commit comments