Skip to content

Commit b1e9700

Browse files
committed
Merge branch 'skia_2024'
2 parents a91be7c + 4df3fec commit b1e9700

File tree

22 files changed

+1691
-872
lines changed

22 files changed

+1691
-872
lines changed

examples/basic_sliders_and_knobs/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ slider_ptr hsliders[3];
3232
slider_ptr vsliders[3];
3333

3434
// We make three dials.
35-
using dial_ptr = std::shared_ptr<dial_base>;
35+
using dial_ptr = std::shared_ptr<basic_dial>;
3636
dial_ptr dials[3];
3737

3838
// We make linear slider markers that are placed below the sliders.

examples/custom_control/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ class my_app : public app
196196
private:
197197

198198
constexpr static float default_value = my_custom_control::default_value;
199-
using dial_ptr = std::shared_ptr<dial_base>;
199+
using dial_ptr = std::shared_ptr<basic_dial>;
200200
using label_ptr = decltype(share(label("")));
201201

202202
auto make_control();

examples/sprite_sliders_and_knobs/main.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ auto background = box(bkd_color);
1414
using slider_ptr = std::shared_ptr<basic_slider_base>;
1515
slider_ptr vsliders[3];
1616

17-
using dial_ptr = std::shared_ptr<dial_base>;
17+
using dial_ptr = std::shared_ptr<basic_dial>;
1818
dial_ptr dials[3];
1919

2020
template <bool is_vertical>
@@ -106,7 +106,7 @@ void link_control(int index, view& view_)
106106
vsliders[index]->on_change =
107107
[index, &view_](double val)
108108
{
109-
dials[index]->dial_base::value(val);
109+
dials[index]->basic_dial::value(val);
110110
view_.refresh(*dials[index]);
111111
};
112112

lib/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ set(ELEMENTS_SOURCES
2626
src/element/style/menu.cpp
2727
src/element/style/radio_button.cpp
2828
src/element/style/slide_switch.cpp
29+
src/element/style/slider.cpp
2930
src/element/style/thumbwheel.cpp
3031
src/element/grid.cpp
3132
src/element/image.cpp

lib/include/elements/base_view.hpp

+17
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,23 @@ namespace cycfi::elements
277277
int modifiers;
278278
};
279279

280+
/**
281+
* \struct drop_info
282+
*
283+
* \brief
284+
* A structure encapsulating information about a drag-and-drop
285+
* operation.
286+
*
287+
* The `drop_info` structure contains information about a drop
288+
* operation, including the payload data and the drop location.
289+
*
290+
* \var payload data
291+
* The payload that is being transferred during the drag-and-drop
292+
* operation (see payload for more info).
293+
*
294+
* \var mutable point where
295+
* The location where the drop operation takes place.
296+
*/
280297
struct drop_info
281298
{
282299
payload data;

lib/include/elements/element/dial.hpp

+76-196
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,58 @@
1414

1515
namespace cycfi::elements
1616
{
17+
/**
18+
* \enum dial_mode_enum
19+
*
20+
* \brief
21+
* Enumeration to specify the behavior of a dial when it's adjusted
22+
* using the mouse or trackpad. The preferred bahavior may be set via
23+
* `get_theme().dial_mode`.
24+
*
25+
* \details
26+
* `linear`: The dial's value adjusts up (increases) or down (decreases)
27+
* corresponding to a linear vertical or horizontal dragging of
28+
* the mouse or trackpad (This is the default).
29+
*
30+
* `radial`: The dial's value adjusts up or down corresponding to a circular
31+
* motion (clockwise or anti-clockwise) around the knob, using the
32+
* mouse or trackpad, emulating the behavior of a real-world dial.
33+
*/
1734
enum class dial_mode_enum : int
1835
{
1936
linear,
2037
radial,
2138
};
2239

23-
////////////////////////////////////////////////////////////////////////////
24-
// Dials
25-
////////////////////////////////////////////////////////////////////////////
26-
class dial_base : public tracker<proxy_base>, public receiver<double>
40+
/**
41+
* \class basic_dial
42+
*
43+
* \brief
44+
* A class representing a basic GUI dial, acting as a proxy that
45+
* delegates rendering and value management to a dial styler.
46+
*
47+
* The `basic_dial` class is a foundational class for creating a GUI
48+
* dial. It is a proxy which delegates rendering of the dial and
49+
* tracking of its value to a dial styler. This separation of concerns
50+
* allows for greater flexibility in dictating the dial's appearance,
51+
* interaction, and functionality. The `basic_dial` handles user
52+
* interaction (such as mouse drag) and management of the dial's current
53+
* value, while the dial styler handles the dial's visual presentation.
54+
* With this pattern, different stylers can be implemented for various
55+
* visual representations.
56+
*
57+
* Communication with the dial styler is done via the `receiver<double>`
58+
* API. This API allows the `basic_dial` to broadcast changes in the
59+
* dial's value to the dial styler. Consequently, the styler can update
60+
* the visual representation in response to these changes.
61+
*/
62+
class basic_dial : public tracker<proxy_base>, public receiver<double>
2763
{
2864
public:
2965

3066
using dial_function = std::function<void(double pos)>;
3167

32-
dial_base(double init_value = 0.0);
68+
basic_dial(double init_value = 0.0);
3369

3470
void prepare_subject(context& ctx) override;
3571
element* hit_test(context const& ctx, point p, bool leaf, bool control) override;
@@ -52,206 +88,50 @@ namespace cycfi::elements
5288
double _value;
5389
};
5490

55-
template <concepts::Element Subject>
56-
inline proxy<remove_cvref_t<Subject>, dial_base>
57-
dial(Subject&& subject, double init_value = 0.0)
58-
{
59-
return {std::forward<Subject>(subject), init_value};
91+
using dial_base [[deprecated("Use basic_dial instead.")]] = basic_dial;
92+
93+
/**
94+
* \brief
95+
* Template function for creating a stylable basic dial.
96+
*
97+
* \tparam Styler
98+
* A template parameter representing the stylizing Element.
99+
*
100+
* \param styler
101+
* The stylizing Element, a user interface element conforming to the
102+
* Element concept.
103+
*
104+
* \param init_value
105+
* An optional parameter representing the initial value of the basic
106+
* dial. Defaults to 0.0.
107+
*
108+
* \return
109+
* Returns stylable basic dial given a styler, with a given initial
110+
* value. Defaults to 0.0.
111+
*/
112+
template <concepts::Element Styler>
113+
inline proxy<remove_cvref_t<Styler>, basic_dial>
114+
dial(Styler&& styler, double init_value = 0.0)
115+
{
116+
return {std::forward<Styler>(styler), init_value};
60117
}
61118

62-
inline double dial_base::value() const
119+
/**
120+
* \brief
121+
* Returns the current value of the dial.
122+
*
123+
* \return
124+
* Returns a double representing the current value of the dial.
125+
*/
126+
inline double basic_dial::value() const
63127
{
64128
return _value;
65129
}
66130

67-
inline element* dial_base::hit_test(context const& ctx, point p, bool leaf, bool /*control*/)
131+
inline element* basic_dial::hit_test(context const& ctx, point p, bool leaf, bool /*control*/)
68132
{
69133
return element::hit_test(ctx, p, leaf, false); // accept non-control subjects
70134
}
71-
72-
////////////////////////////////////////////////////////////////////////////
73-
// Basic Knob (You can use this as the subject of dial)
74-
////////////////////////////////////////////////////////////////////////////
75-
template <std::size_t _size>
76-
class basic_knob_element : public element, public receiver<double>
77-
{
78-
public:
79-
80-
static std::size_t const size = _size;
81-
82-
basic_knob_element(color c = colors::black)
83-
: _color(c), _value(0)
84-
{}
85-
86-
view_limits limits(basic_context const& ctx) const override;
87-
void draw(context const& ctx) override;
88-
89-
double value() const override { return _value; }
90-
void value(double val) override;
91-
92-
private:
93-
94-
color _color;
95-
float _value;
96-
};
97-
98-
template <std::size_t size>
99-
inline view_limits basic_knob_element<size>::limits(basic_context const& /* ctx */) const
100-
{
101-
auto pt = point{float(size), float(size)};
102-
return view_limits{pt, pt};
103-
}
104-
105-
template <std::size_t size>
106-
inline void basic_knob_element<size>::draw(context const& ctx)
107-
{
108-
auto& thm = get_theme();
109-
auto& cnv = ctx.canvas;
110-
auto indicator_color = thm.indicator_color.level(1.5);
111-
auto cp = circle{center_point(ctx.bounds), ctx.bounds.width()/2};
112-
113-
draw_knob(cnv, cp, _color);
114-
draw_radial_indicator(cnv, cp, _value, indicator_color);
115-
}
116-
117-
template <std::size_t size>
118-
inline void basic_knob_element<size>::value(double val)
119-
{
120-
_value = val;
121-
}
122-
123-
template <std::size_t size>
124-
inline basic_knob_element<size> basic_knob(color c = colors::black)
125-
{
126-
return {c};
127-
}
128-
129-
////////////////////////////////////////////////////////////////////////////
130-
// Radial Element Base (common base class for radial elements)
131-
////////////////////////////////////////////////////////////////////////////
132-
template <std::size_t _size, concepts::Element Subject>
133-
class radial_element_base : public proxy<Subject>
134-
{
135-
public:
136-
137-
static std::size_t const size = _size;
138-
139-
using base_type = proxy<Subject>;
140-
141-
radial_element_base(Subject subject)
142-
: base_type(std::move(subject))
143-
{}
144-
145-
view_limits limits(basic_context const& ctx) const override;
146-
void prepare_subject(context& ctx) override;
147-
};
148-
149-
template <std::size_t size, concepts::Element Subject>
150-
inline view_limits
151-
radial_element_base<size, Subject>::limits(basic_context const& ctx) const
152-
{
153-
auto sl = this->subject().limits(ctx);
154-
155-
sl.min.x += size;
156-
sl.max.x += size;
157-
sl.min.y += size;
158-
sl.max.y += size;
159-
160-
clamp_max(sl.max.x, full_extent);
161-
clamp_max(sl.max.y, full_extent);
162-
return sl;
163-
}
164-
165-
template <std::size_t size, concepts::Element Subject>
166-
inline void
167-
radial_element_base<size, Subject>::prepare_subject(context& ctx)
168-
{
169-
auto size_div2 = size /2;
170-
ctx.bounds.top += size_div2;
171-
ctx.bounds.left += size_div2;
172-
ctx.bounds.bottom -= size_div2;
173-
ctx.bounds.right -= size_div2;
174-
}
175-
176-
////////////////////////////////////////////////////////////////////////////
177-
// Radial Marks (You can use this to place dial tick marks around dials)
178-
////////////////////////////////////////////////////////////////////////////
179-
template <std::size_t _size, concepts::Element Subject>
180-
class radial_marks_element : public radial_element_base<_size, Subject>
181-
{
182-
public:
183-
184-
static std::size_t const size = _size;
185-
using base_type = radial_element_base<_size, Subject>;
186-
using base_type::base_type;
187-
188-
void draw(context const& ctx) override;
189-
};
190-
191-
template <std::size_t size, concepts::Element Subject>
192-
inline void
193-
radial_marks_element<size, Subject>::draw(context const& ctx)
194-
{
195-
// Draw the subject
196-
base_type::draw(ctx);
197-
198-
// Draw radial lines
199-
auto cp = circle{center_point(ctx.bounds), ctx.bounds.width()/2};
200-
draw_radial_marks(ctx.canvas, cp, size-2, colors::light_gray);
201-
}
202-
203-
template <std::size_t size, concepts::Element Subject>
204-
inline radial_marks_element<size, remove_cvref_t<Subject>>
205-
radial_marks(Subject&& subject)
206-
{
207-
return {std::forward<Subject>(subject)};
208-
}
209-
210-
////////////////////////////////////////////////////////////////////////////
211-
// Radial Labels (You can use this to place dial labels around dials)
212-
////////////////////////////////////////////////////////////////////////////
213-
template <std::size_t _size, concepts::Element Subject, std::size_t num_labels>
214-
class radial_labels_element : public radial_element_base<_size, Subject>
215-
{
216-
public:
217-
218-
static std::size_t const size = _size;
219-
using base_type = radial_element_base<_size, Subject>;
220-
using string_array = std::array<std::string, num_labels>;
221-
222-
radial_labels_element(Subject subject, float font_size)
223-
: base_type(std::move(subject))
224-
, _font_size(font_size)
225-
{}
226-
227-
void draw(context const& ctx) override;
228-
229-
string_array _labels;
230-
float _font_size;
231-
};
232-
233-
template <std::size_t size, concepts::Element Subject, std::size_t num_labels>
234-
inline void
235-
radial_labels_element<size, Subject, num_labels>::draw(context const& ctx)
236-
{
237-
// Draw the subject
238-
base_type::draw(ctx);
239-
240-
// Draw the labels
241-
auto cp = circle{center_point(ctx.bounds), ctx.bounds.width()/2};
242-
draw_radial_labels(
243-
ctx.canvas, cp, _font_size, _labels.data(), num_labels);
244-
}
245-
246-
template <std::size_t size, concepts::Element Subject, typename... S>
247-
inline radial_labels_element<size, remove_cvref_t<Subject>, sizeof...(S)>
248-
radial_labels(Subject&& subject, float font_size, S&&... s)
249-
{
250-
auto r = radial_labels_element<size, remove_cvref_t<Subject>, sizeof...(S)>
251-
{std::move(subject), font_size};
252-
r._labels = {{std::move(s)...}};
253-
return r;
254-
}
255135
}
256136

257137
#endif

0 commit comments

Comments
 (0)