6#include "TTauri/Widgets/Widget.hpp"
7#include "TTauri/GUI/DrawContext.hpp"
8#include "TTauri/Text/format10.hpp"
9#include "TTauri/Foundation/observable.hpp"
18template<
typename ValueType>
32 ValueType activeValue;
42 value(std::forward<V>(value)),
45 [[maybe_unused]] ttlet value_cbid = value.add_callback([
this](
auto...){
48 [[maybe_unused]] ttlet label_cbid = label.add_callback([
this](
auto...){
71 labelCell = std::make_unique<TextCell>(*label, theme->labelStyle);
80 button_rectangle =
aarect{button_x, button_y, button_width, button_height};
81 button_middle = button_y + button_height * 0.5f;
87 pip_rectangle =
aarect{pip_x, pip_y, pip_width, pip_height};
92 auto context = drawContext;
93 context.cornerShapes =
vec{button_rectangle.height() * 0.5f};
94 context.drawBoxIncludeBorder(button_rectangle);
97 if (value == activeValue) {
99 context.color = theme->accentColor;
101 std::swap(context.color, context.fillColor);
102 context.cornerShapes =
vec{pip_rectangle.height() * 0.5f};
103 context.drawBoxIncludeBorder(pip_rectangle);
106 labelCell->draw(context, label_rectangle, Alignment::TopLeft, button_middle);
115 event.type == MouseEvent::Type::ButtonUp &&
116 event.cause.leftButton &&
129 if (command ==
"gui.activate"_ltag) {
130 if (assign_and_compare(value, activeValue)) {
139 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
A 4D vector.
Definition vec.hpp:37
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
std::atomic< bool > active
Definition Window_base.hpp:86
Definition Window_vulkan_win32.hpp:15
Definition RadioButtonWidget.hpp:19
void layout(hires_utc_clock::time_point displayTimePoint) noexcept override
Layout the widget.
Definition RadioButtonWidget.hpp:61
void handleCommand(string_ltag command) noexcept override
Handle command.
Definition RadioButtonWidget.hpp:124
void draw(DrawContext const &drawContext, hires_utc_clock::time_point displayTimePoint) noexcept override
Draw widget.
Definition RadioButtonWidget.hpp:90
bool acceptsFocus() const noexcept override
Check if the widget will accept keyboard focus.
Definition RadioButtonWidget.hpp:145
void handleMouseEvent(MouseEvent const &event) noexcept override
Definition RadioButtonWidget.hpp:110
HitBox hitBoxTest(vec position) const noexcept override
Find the widget that is under the mouse cursor.
Definition RadioButtonWidget.hpp:137
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
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