6#include "TTauri/Widgets/Widget.hpp"
7#include "TTauri/Cells/TextCell.hpp"
8#include "TTauri/GUI/DrawContext.hpp"
9#include "TTauri/Text/FontBook.hpp"
10#include "TTauri/Text/format10.hpp"
11#include "TTauri/Foundation/observable.hpp"
20template<
typename ValueType>
23 char32_t check = 0x2713;
53 falseValue(falseValue),
54 value(std::forward<V>(value)),
57 [[maybe_unused]] ttlet value_cbid = value.add_callback([
this](
auto...){
61 [[maybe_unused]] ttlet label_cbid = label.add_callback([
this](
auto...){
83 ttlet labelText = *label;
84 labelCell = std::make_unique<TextCell>(labelText, theme->labelStyle);
90 button_y =
rectangle().height() - button_height;
91 button_rectangle =
aarect{button_x, button_y, button_width, button_height};
92 button_middle = button_y + button_height * 0.5f;
95 ttlet checkFontId = fontBook->
find_font(
"Arial", FontWeight::Regular,
false);
97 checkBoundingBox = scale(checkGlyph.getBoundingBox(), button_height * 1.2f);
99 check_rectangle = align(button_rectangle, checkBoundingBox, Alignment::MiddleCenter);
104 auto context = drawContext;
105 context.drawBoxIncludeBorder(button_rectangle);
108 context.color = theme->accentColor;
112 if (value == trueValue) {
113 context.transform = drawContext.transform *
mat::T{0.0, 0.0, 0.001f};
114 context.drawGlyph(checkGlyph, check_rectangle);
115 }
else if (value == falseValue) {
118 std::swap(context.color, context.fillColor);
119 context.transform = drawContext.transform *
mat::T{0.0, 0.0, 0.001f};
120 context.drawFilledQuad(shrink(button_rectangle, 3.0f));
123 labelCell->draw(context, label_rectangle, Alignment::TopLeft, button_middle);
132 event.type == MouseEvent::Type::ButtonUp &&
133 event.cause.leftButton &&
146 if (command ==
"gui.activate"_ltag) {
147 if (assign_and_compare(value, value == falseValue ? trueValue : falseValue)) {
156 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
FontGlyphIDs find_glyph(FontID font_id, Grapheme grapheme) const noexcept
Find a glyph using the given code-point.
FontID find_font(FontFamilyID family_id, FontVariant variant) const noexcept
Find a font closest to the variant.
Definition FontGlyphIDs.hpp:77
Definition Grapheme.hpp:20
Definition CheckboxWidget.hpp:21
HitBox hitBoxTest(vec position) const noexcept override
Find the widget that is under the mouse cursor.
Definition CheckboxWidget.hpp:154
void layout(hires_utc_clock::time_point displayTimePoint) noexcept override
Layout the widget.
Definition CheckboxWidget.hpp:73
void handleCommand(string_ltag command) noexcept override
Handle command.
Definition CheckboxWidget.hpp:141
void draw(DrawContext const &drawContext, hires_utc_clock::time_point displayTimePoint) noexcept override
Draw widget.
Definition CheckboxWidget.hpp:102
bool acceptsFocus() const noexcept override
Check if the widget will accept keyboard focus.
Definition CheckboxWidget.hpp:162
void handleMouseEvent(MouseEvent const &event) noexcept override
Definition CheckboxWidget.hpp:127
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