HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
toggle_widget.hpp
1// Copyright Take Vos 2021.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7#include "abstract_button_widget.hpp"
8#include "default_button_delegate.hpp"
9
10namespace tt {
11
49public:
51 using delegate_type = typename super::delegate_type;
52 using callback_ptr_type = typename delegate_type::callback_ptr_type;
53
61
71 template<typename Value, typename... Args>
72 toggle_widget(gui_window &window, widget *parent, Value &&value, Args &&...args) noexcept
73 requires(not std::is_convertible_v<Value, weak_or_unique_ptr<delegate_type>>) :
75 window,
76 parent,
77 make_unique_default_button_delegate<button_type::toggle>(std::forward<Value>(value), std::forward<Args>(args)...))
78 {
79 }
80
82 [[nodiscard]] bool constrain(hires_utc_clock::time_point display_time_point, bool need_reconstrain) noexcept override;
83 [[nodiscard]] void layout(hires_utc_clock::time_point displayTimePoint, bool need_layout) noexcept override;
84 void draw(draw_context context, hires_utc_clock::time_point display_time_point) noexcept override;
86private:
87 static constexpr hires_utc_clock::duration _animation_duration = 150ms;
88
89 extent2 _button_size;
90 aarectangle _button_rectangle;
91 animator<float> _animated_value = _animation_duration;
92 aarectangle _pip_rectangle;
93 float _pip_move_range;
94
96 void draw_toggle_button(draw_context context) noexcept;
97 void draw_toggle_pip(draw_context draw_context, hires_utc_clock::time_point display_time_point) noexcept;
98};
99
100} // namespace tt
button_type
The type of button.
Definition button_type.hpp:13
@ toggle
A toggle button.
STL namespace.
A type that gets animated between two values.
Definition animator.hpp:18
Class which represents an axis-aligned rectangle.
Definition axis_aligned_rectangle.hpp:20
Draw context for drawing using the TTauri shaders.
Definition draw_context.hpp:29
Definition gui_window.hpp:36
Class that hold either a weak_ptr or a unique_ptr This class is to hold a weak_ptr,...
Definition weak_or_unique_ptr.hpp:25
Definition abstract_button_widget.hpp:23
Definition button_delegate.hpp:14
A GUI widget that permits the user to make a binary choice.
Definition toggle_widget.hpp:48
toggle_widget(gui_window &window, widget *parent, std::unique_ptr< delegate_type > delegate) noexcept
Construct a toggle widget.
toggle_widget(gui_window &window, widget *parent, Value &&value, Args &&...args) noexcept
Construct a toggle widget with a default button delegate.
Definition toggle_widget.hpp:72
An interactive graphical object as part of the user-interface.
Definition widget.hpp:39
widget *const parent
Pointer to the parent widget.
Definition widget.hpp:48
gui_window & window
Convenient reference to the Window.
Definition widget.hpp:43