6#include "TTauri/Widgets/Widget.hpp"
7#include "TTauri/Cells/TextCell.hpp"
8#include "TTauri/GUI/DrawContext.hpp"
9#include "TTauri/Foundation/observable.hpp"
10#include "TTauri/Text/format10.hpp"
19template<
typename ValueType=
bool>
50 value(std::forward<V>(value)),
53 [[maybe_unused]] ttlet value_cbid = this->value.add_callback([
this](
auto...){
56 [[maybe_unused]] ttlet label_cbid = this->label.add_callback([
this](
auto...) {
79 labelCell = std::make_unique<TextCell>(*label, theme->labelStyle);
85 toggle_y =
rectangle().height() - toggle_height;
86 toggle_rectangle =
aarect{toggle_x, toggle_y, toggle_width, toggle_height};
87 toggle_middle = toggle_y + toggle_height * 0.5f;
90 slider_y = toggle_y + 1.5f;
91 slider_width = toggle_height - 3.0f;
92 slider_height = toggle_height - 3.0f;
94 slider_move = slider_move_width - slider_width;
100 if (animation_progress < 1.0f) {
104 ttlet animated_value = to_float(value, animation_duration);
107 auto context = drawContext;
108 context.cornerShapes =
vec{toggle_rectangle.height() * 0.5f};
109 context.drawBoxIncludeBorder(toggle_rectangle);
112 ttlet slider_rectangle =
aarect{
113 slider_x + slider_move * animated_value, slider_y,
114 slider_width, slider_height
117 if (value == trueValue) {
119 context.color = theme->accentColor;
123 context.
color = hover ?
128 std::swap(context.color, context.fillColor);
129 context.cornerShapes =
vec{slider_rectangle.height() * 0.5f};
130 context.drawBoxIncludeBorder(slider_rectangle);
132 labelCell->draw(context, label_rectangle, Alignment::TopLeft, toggle_middle);
141 event.type == MouseEvent::Type::ButtonUp &&
142 event.cause.leftButton &&
155 if (command ==
"gui.activate"_ltag) {
156 if (assign_and_compare(value, !*value)) {
165 return HitBox{
this, elevation, *
enabled ? HitBox::Type::Button : HitBox::Type::Default};
Class which represents an axis-aligned rectangle.
Definition aarect.hpp:13
Optimized translate matrix.
Definition mat.hpp:119
Definition observable.hpp:20
float animation_progress(duration animation_duration) const noexcept
The relative time since the start of the animation.
Definition observable.hpp:160
A 4D vector.
Definition vec.hpp:37
static tt_force_inline vec color(float r, float g, float b, float a=1.0f) noexcept
Create a color out of 3 to 4 values.
Definition vec.hpp:226
Draw context for drawing using the TTauri shaders.
Definition DrawContext.hpp:30
Definition MouseEvent.hpp:12
static constexpr float smallHeight
The height of smaller widget like labels, toggles, checkboxes and radio buttons.
Definition Theme.hpp:47
static constexpr float smallWidth
The width of smaller widget like labels, toggles, checkboxes and radio buttons.
Definition Theme.hpp:53
static constexpr float margin
Distance between widgets and between widgets and the border of the container.
Definition Theme.hpp:33
vec borderColor(ssize_t nestingLevel) const noexcept
Get border color of elements of widgets and child widgets.
Definition Theme.hpp:122
std::atomic< bool > active
Definition Window_base.hpp:86
Definition Window_vulkan_win32.hpp:15
Definition ToggleWidget.hpp:20
void handleCommand(string_ltag command) noexcept override
Handle command.
Definition ToggleWidget.hpp:150
void draw(DrawContext const &drawContext, hires_utc_clock::time_point displayTimePoint) noexcept override
Draw widget.
Definition ToggleWidget.hpp:97
bool acceptsFocus() const noexcept override
Check if the widget will accept keyboard focus.
Definition ToggleWidget.hpp:171
HitBox hitBoxTest(vec position) const noexcept override
Find the widget that is under the mouse cursor.
Definition ToggleWidget.hpp:163
void handleMouseEvent(MouseEvent const &event) noexcept override
Definition ToggleWidget.hpp:136
void layout(hires_utc_clock::time_point displayTimePoint) noexcept override
Layout the widget.
Definition ToggleWidget.hpp:69
virtual void handleCommand(string_ltag command) noexcept
Handle command.
Widget(Window &window, Widget *parent, vec defaultExtent) noexcept
observable< bool > enabled
The widget is enabled.
Definition Widget.hpp:150
ssize_t nestingLevel() noexcept
Get nesting level used for selecting colors for the widget.
Definition Widget.hpp:314
virtual void handleMouseEvent(MouseEvent const &event) noexcept
Definition Widget.hpp:374
virtual void layout(hires_utc_clock::time_point displayTimePoint) noexcept
Layout the widget.
virtual void draw(DrawContext const &drawContext, hires_utc_clock::time_point displayTimePoint) noexcept
Draw widget.
aarect rectangle() const noexcept
Get the rectangle in local coordinates.
Definition Widget.hpp:273