Skip to content

Commit 261a0f5

Browse files
committed
Merge branch 'skia_2024'
2 parents df74e77 + ffbe903 commit 261a0f5

File tree

4 files changed

+37
-13
lines changed

4 files changed

+37
-13
lines changed

lib/include/elements/element/button.hpp

+24-10
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,30 @@ namespace cycfi::elements
5656
bool enabled : 1;
5757
};
5858

59-
class basic_button
60-
: public proxy_base
61-
, public receiver<bool>
59+
/**
60+
* \class basic_button
61+
*
62+
* \brief
63+
* A class that represents a basic GUI button, acting as a proxy which
64+
* delegates the rendering to a "button styler".
65+
*
66+
* The `basic_button` class is a foundational class for creating a GUI
67+
* button. This class is a proxy which delegates the rendering of the
68+
* actual button to a button styler subject. This division of
69+
* responsibilities allows for more flexibility in dictating the
70+
* button's appearance and interaction. The `basic_button` class
71+
* handles user interactions, while the button styler manages the
72+
* button's visual presentation. With this pattern, different stylers
73+
* can be implemented for various visual representations, for instance,
74+
* plain buttons, radio buttons, slide switches, checkboxes, and more.
75+
*
76+
* The communication with the "button styler" is done via the
77+
* `receiver<button_state>` API. This API provides a means for the
78+
* `basic_button` to update the button styler about changes in button's
79+
* state (such as on/off value, highlight, enabled state etc.) enabling
80+
* the styler to adjust the visual representation accordingly.
81+
*/
82+
class basic_button : public proxy_base, public receiver<bool>
6283
{
6384
public:
6485

@@ -95,13 +116,6 @@ namespace cycfi::elements
95116
button_state _state;
96117
};
97118

98-
inline void basic_button::edit(view& view_, bool val)
99-
{
100-
if (on_click)
101-
on_click(val);
102-
receiver<bool>::notify_edit(view_);
103-
}
104-
105119
////////////////////////////////////////////////////////////////////////////
106120
// Toggle Button
107121
////////////////////////////////////////////////////////////////////////////

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -643,12 +643,12 @@ namespace cycfi::elements
643643

644644
inline color default_button_styler::get_body_color() const
645645
{
646-
return get_theme().default_button_color.level(0.9);
646+
return get_theme().default_button_color;
647647
}
648648

649649
inline color default_button_styler::get_active_body_color() const
650650
{
651-
return get_theme().default_button_color.opacity(0.5);
651+
return get_body_color();
652652
}
653653

654654
inline color default_button_styler::get_text_color() const

lib/src/element/button.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,13 @@ namespace cycfi::elements
126126
state(val);
127127
}
128128

129+
void basic_button::edit(view& view_, bool val)
130+
{
131+
if (on_click)
132+
on_click(val);
133+
receiver<bool>::notify_edit(view_);
134+
}
135+
129136
void basic_choice_click(context const& ctx, selectable& s)
130137
{
131138
auto [c, cctx] = find_composite(ctx);

lib/src/element/gallery/button.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ namespace cycfi::elements
6666
auto value = state.value;
6767
auto hilite = state.hilite;
6868
auto enabled = ctx.enabled;
69-
auto body_color = value? get_active_body_color() : get_body_color();
69+
auto body_color = value?
70+
get_active_body_color().opacity(0.5) :
71+
get_body_color().level(0.9)
72+
;
7073

7174
// Draw the body
7275
if (value)

0 commit comments

Comments
 (0)