10#include <egt/detail/math.h>
11#include <egt/detail/meta.h>
14#include <egt/painter.h>
15#include <egt/signal.h>
18#include <egt/widget.h>
143 range->on_value_changed([
this,
flags]()
160 auto i = std::find_if(this->
m_values.begin(), this->m_values.end(),
161 [&
handle](
const auto & obj)
163 return obj->handle == handle;
185 if (value.handle ==
handle)
197 EGT_NODISCARD
const std::string&
text()
const {
return m_text; }
217 bool changed =
false;
227 if (value.range->value(v))
233 this->on_user_input_changed.
invoke();
253 const auto c = b.
center();
255 const auto smalldim = std::min(b.width(), b.height());
260 if (value.width > maxwidth)
261 maxwidth = value.width;
266 const auto radius = smalldim * 0.5f - (maxwidth * 0.5f);
267 const auto angle1 = detail::to_radians<float>(-90, widget.
start_angle());
268 const auto angle2 = detail::to_radians<float>(-90,
271 value.range->value()));
273 painter.
set(value.color);
275 auto cr = painter.
context().get();
277 cairo_set_line_cap(cr, CAIRO_LINE_CAP_ROUND);
279 cairo_set_line_cap(cr, CAIRO_LINE_CAP_BUTT);
281 painter.
draw(
Arc(c, radius, angle1, angle2));
286 text = std::to_string(value.range->value());
292 auto target =
Rect(
Size(smalldim, smalldim));
293 target.move_to_center(b.center());
297 detail::draw_text(painter,
314 const Point c = b.center();
318 angle = angle + 360.0f;
327 const auto n = (
static_cast<float>(value) -
328 static_cast<float>(min)) /
329 (
static_cast<float>(max) -
static_cast<float>(min));
338 const auto n = degrees / 360.;
339 return (n * (max - min)) + min;
372 : range(std::
move(r)),
379 std::shared_ptr<RangeValue<T2>> range;
static constexpr HVBitField center
Definition widgetflags.h:297
Manager of the Drawable for each widget type.
Definition theme.h:104
Utility class for managing a set of flags with the ability to observe changes to the flags.
Definition flags.h:40
A Frame is a Widget that has children widgets.
Definition frame.h:45
uint64_t RegisterHandle
Handle type.
Definition object.h:61
EGT_NODISCARD const std::string & name() const
Get the name of the Object.
Definition object.h:42
Drawing interface for 2D graphics.
Definition painter.h:45
Painter & set(const Pattern &pattern)
Set the current color.
Painter & line_width(float width)
Set the current line width.
Painter & draw(const PointType< T, detail::Compatible::normal > &point)
Move to a point.
Definition painter.h:182
EGT_NODISCARD shared_cairo_t context() const
Get the current underlying context the painter is using.
Definition painter.h:340
@ bg
General (Window, Frame) background color.
@ label_text
Label text color.
A Pattern which can store one or more colors at different offsets (steps) which can be used to create...
Definition pattern.h:55
EGT_NODISCARD T angle_to(const PointType &point) const noexcept
Return the angle in radians from this point to get to another.
Definition geometry.h:176
Manages a value in a range.
Definition value.h:88
EGT_NODISCARD constexpr PointType< Dim, DimCompat > center() const noexcept
Return the center point of the rectangle.
Definition geometry.h:681
std::list< std::tuple< std::string, std::string, Serializer::Attributes > > Properties
Definition serialize.h:47
Signal class used for defining a signal and dispatching events.
Definition signal.h:30
void invoke(Args... args)
Invoke all handlers with the specified args.
Definition signal.h:85
static Font scale_font(const Size &target, const std::string &text, const Font &font)
Given a Font, text, and a target Size, scale the font size so that the text will will fit and return ...
Radial widget that draws a series of RangleValues on a circle.
Definition radial.h:47
Object::RegisterHandle m_handle_counter
Counter used to generate unique handles for each handle registration.
Definition radial.h:393
RadialType(Serializer::Properties &props) noexcept
Definition radial.h:105
void draw(Painter &painter, const Rect &rect) override
Draw the widget.
Definition radial.h:240
EGT_NODISCARD T value_to_degrees(T min, T max, T value) const
Normalize a value to degrees.
Definition radial.h:325
RadialType(const Rect &rect={}) noexcept
Definition radial.h:85
RadialFlag
Radial flags.
Definition radial.h:62
@ rounded_cap
When drawing the value, use rounded ends.
@ input_value
This value is modified by user input.
@ text_value
Use the value for the center text of the widget.
Object::RegisterHandle add(const std::shared_ptr< RangeValue< T > > &range, const Pattern &color={}, DefaultDim width=10, RadialFlags flags={})
Add a range value to the radial.
Definition radial.h:133
EGT_NODISCARD const std::string & text() const
Get the current text of the radial.
Definition radial.h:197
RadialType(Serializer::Properties &props, bool is_derived) noexcept
Definition radial.h:112
bool internal_drag() const override
Definition radial.h:360
void remove(Object::RegisterHandle handle)
Remove a range value from the radial.
Definition radial.h:158
std::string m_text
Center text of the widget.
Definition radial.h:387
static void default_draw(RadialType< T > &widget, Painter &painter, const Rect &rect)
Default draw method for the widget.
Definition radial.h:246
void text(const std::string &text)
Set the center label text of the dial.
Definition radial.h:202
void handle(Event &event) override
Handle an event.
Definition radial.h:208
std::vector< ValueData< T > > m_values
The second value of the widget.
Definition radial.h:390
EGT_NODISCARD T degrees_to_value(T min, T max, T degrees) const
Normalize degrees to a value.
Definition radial.h:336
float m_start_angle
The starting angle in degrees for the min values.
Definition radial.h:396
egt::Flags< RadialFlag > RadialFlags
Radial flags.
Definition radial.h:80
void start_angle(float value)
Set the starting angle in degrees for the min values.
Definition radial.h:353
RadialType(Frame &parent, const Rect &rect={}) noexcept
Definition radial.h:96
EGT_NODISCARD float start_angle() const
The starting angle in degrees for the min values.
Definition radial.h:345
void color(Object::RegisterHandle handle, const Pattern &color)
Set the individual color of a range value.
Definition radial.h:181
Signal on_user_input_changed
Event signal.
Definition radial.h:57
EGT_NODISCARD float touch_to_degrees(const Point &point) const
Convert a touch point to degrees on the radial.
Definition radial.h:311
@ pointer_click
Pointer event.
@ pointer_drag
Pointer event.
SizeType< DefaultDim, detail::Compatible::normal > Size
Helper type alias.
Definition geometry.h:573
RectType< DefaultDim, detail::Compatible::normal > Rect
Helper type alias.
Definition geometry.h:1023
ArcType< DefaultDim > Arc
Helper type alias.
Definition geometry.h:1191
constexpr T bit(T n)
Utility to create a bit mask for the specified bit.
Definition meta.h:306
void ignoreparam(T &&)
Utility function to safely ignore a parameter to a function.
Definition meta.h:97
constexpr T to_degrees(T radians)
Convert from radians to degrees.
Definition math.h:72
int DefaultDim
Define the default dimension type used for geometry.
Definition geometry.h:34
EGT framework namespace.
Definition animation.h:24
A single event that has information about the event and state for the event.
Definition event.h:255
EGT_NODISCARD const EventId & id() const noexcept
Get the id of the event.
Definition event.h:284
Pointer & pointer()
Get the Pointer event data.
Definition event.h:309
DisplayPoint point
Mouse position in display coordinates.
Definition event.h:133
When using enum_to_string() and enum_from_string(), this type needs to be defined and specialized to ...
Definition enum.h:48