1 #ifndef TERMOX_WIDGET_WIDGETS_CHECKBOX_HPP
2 #define TERMOX_WIDGET_WIDGETS_CHECKBOX_HPP
6 #include <signals_light/signal.hpp>
8 #include <termox/common/overload.hpp>
9 #include <termox/painter/glyph_string.hpp>
10 #include <termox/system/mouse.hpp>
11 #include <termox/widget/detail/link_lifetimes.hpp>
12 #include <termox/widget/layouts/horizontal.hpp>
13 #include <termox/widget/layouts/vertical.hpp>
14 #include <termox/widget/pipe.hpp>
15 #include <termox/widget/widgets/label.hpp>
21 template <
template <
typename>
typename Layout_t>
27 enum class State : bool { Unchecked, Checked };
68 [[nodiscard]]
auto get_state() const -> State;
77 [[nodiscard]] auto
is_locked() const ->
bool;
95 void update_display();
102 [[nodiscard]] auto hcheckbox(
HCheckbox::State initial_state,
104 bool locked) -> std::unique_ptr<
HCheckbox>;
111 [[nodiscard]] auto vcheckbox(
VCheckbox::State initial_state,
113 bool locked) -> std::unique_ptr<
VCheckbox>;
121 namespace ox::detail {
124 template <
template <
typename>
typename Layout_t,
125 typename Checkbox_type,
128 :
public Label_wrapper<Layout_t, Checkbox_type, Layout_t, label_last> {
134 using Checkbox_t = Checkbox_type;
138 Checkbox_t& checkbox = Base_t::wrapped;
139 Label_t& label = Base_t::label;
143 typename Base_t::Parameters label_parameters = {},
144 typename Checkbox_t::Parameters checkbox_parameters = {})
145 :
Base_t{std::move(label_parameters), std::move(checkbox_parameters)}
147 using namespace pipe;
148 Base_t::label | on_mouse_press([&](
auto) { checkbox.toggle(); });
149 Base_t::padding | on_mouse_press([&](
auto) { checkbox.toggle(); });
153 using Base_t::wrapped;
162 template <
typename T>
163 inline auto constexpr make_labeled_cb_fn =
164 [](
typename T::Label_wrapper_t::Parameters label_parameters = {},
165 typename T::Checkbox_t::Parameters checkbox_parameters = {})
166 -> std::unique_ptr<T> {
167 return std::make_unique<T>(std::move(label_parameters),
168 std::move(checkbox_parameters));
173 template <
typename Checkbox_t>
174 inline auto constexpr make_checkbox_fn = Overload{
175 [](
typename Checkbox_t::Parameters parameters = {})
176 -> std::unique_ptr<Checkbox_t> {
177 return std::make_unique<Checkbox_t>(std::move(parameters));
179 [](
typename Checkbox_t::State initial_state,
180 bool locked) -> std::unique_ptr<Checkbox_t> {
181 return std::make_unique<Checkbox_t>(initial_state, locked);
189 State initial_state = State::Unchecked;
194 Checkbox1(State initial_state = State::Unchecked,
bool locked =
false)
195 :
HCheckbox{initial_state, {U
"☒", U
"☐"}, locked}
198 Checkbox1(Parameters p) : Checkbox1{p.initial_state, p.locked} {}
201 inline auto constexpr checkbox1 = make_checkbox_fn<Checkbox1>;
203 using HCheckbox1_label =
204 detail::Label_checkbox_impl<layout::Horizontal, Checkbox1, true>;
205 using HCheckbox_label = HCheckbox1_label;
207 using HLabel_checkbox1 =
208 detail::Label_checkbox_impl<layout::Horizontal, Checkbox1, false>;
209 using HLabel_checkbox = HLabel_checkbox1;
211 using VCheckbox1_label =
212 detail::Label_checkbox_impl<layout::Vertical, Checkbox1, true>;
213 using VCheckbox_label = VCheckbox1_label;
215 using VLabel_checkbox1 =
216 detail::Label_checkbox_impl<layout::Vertical, Checkbox1, false>;
217 using VLabel_checkbox = VLabel_checkbox1;
219 inline auto constexpr hcheckbox1_label = make_labeled_cb_fn<HCheckbox_label>;
220 inline auto constexpr hcheckbox_label = hcheckbox1_label;
221 inline auto constexpr hlabel_checkbox1 = make_labeled_cb_fn<HLabel_checkbox>;
222 inline auto constexpr hlabel_checkbox = hlabel_checkbox1;
223 inline auto constexpr vcheckbox1_label = make_labeled_cb_fn<VCheckbox_label>;
224 inline auto constexpr vcheckbox_label = vcheckbox1_label;
225 inline auto constexpr vlabel_checkbox1 = make_labeled_cb_fn<VLabel_checkbox>;
226 inline auto constexpr vlabel_checkbox = vlabel_checkbox1;
232 State initial_state = State::Unchecked;
237 Checkbox2(State initial_state = State::Unchecked,
bool locked =
false)
238 :
HCheckbox{initial_state, {U
"[x]", U
"[ ]"}, locked}
241 Checkbox2(Parameters p) : Checkbox2{p.initial_state, p.locked} {}
244 inline auto constexpr checkbox2 = make_checkbox_fn<Checkbox2>;
246 using HCheckbox2_label =
247 detail::Label_checkbox_impl<layout::Horizontal, Checkbox2, true>;
248 using HLabel_checkbox2 =
249 detail::Label_checkbox_impl<layout::Horizontal, Checkbox2, false>;
250 using VCheckbox2_label =
251 detail::Label_checkbox_impl<layout::Vertical, Checkbox2, true>;
252 using VLabel_checkbox2 =
253 detail::Label_checkbox_impl<layout::Vertical, Checkbox2, false>;
255 inline auto constexpr hcheckbox2_label = make_labeled_cb_fn<HCheckbox2_label>;
256 inline auto constexpr hlabel_checkbox2 = make_labeled_cb_fn<HLabel_checkbox2>;
257 inline auto constexpr vcheckbox2_label = make_labeled_cb_fn<VCheckbox2_label>;
258 inline auto constexpr vlabel_checkbox2 = make_labeled_cb_fn<VLabel_checkbox2>;
266 State initial_state = State::Unchecked;
271 Checkbox3(State initial_state = State::Unchecked,
bool locked =
false)
272 :
VCheckbox{initial_state, {U
"┌x└", U
"┌ └"}, locked}
275 Checkbox3(Parameters p) : Checkbox3{p.initial_state, p.locked} {}
278 inline auto constexpr checkbox3 = make_checkbox_fn<Checkbox3>;
280 using HCheckbox3_label =
281 detail::Label_checkbox_impl<layout::Horizontal, Checkbox3, true>;
283 inline auto constexpr hcheckbox3_label = make_labeled_cb_fn<HCheckbox3_label>;
291 State initial_state = State::Unchecked;
296 Checkbox4(State initial_state = State::Unchecked,
bool locked =
false)
297 :
VCheckbox{initial_state, {U
"┐x┘", U
"┐ ┘"}, locked}
300 Checkbox4(Parameters p) : Checkbox4{p.initial_state, p.locked} {}
303 inline auto constexpr checkbox4 = make_checkbox_fn<Checkbox4>;
305 using HLabel_checkbox4 =
306 detail::Label_checkbox_impl<layout::Horizontal, Checkbox4, false>;
308 inline auto constexpr hlabel_checkbox4 = make_labeled_cb_fn<HLabel_checkbox4>;
314 State initial_state = State::Unchecked;
319 Checkbox5(State initial_state = State::Unchecked,
bool locked =
false)
320 :
HCheckbox{initial_state, {U
"┌x┐", U
"┌ ┐"}, locked}
323 Checkbox5(Parameters p) : Checkbox5{p.initial_state, p.locked} {}
326 inline auto constexpr checkbox5 = make_checkbox_fn<Checkbox5>;
328 using VCheckbox5_label =
329 detail::Label_checkbox_impl<layout::Vertical, Checkbox5, true>;
331 inline auto constexpr vcheckbox5_label = make_labeled_cb_fn<VCheckbox5_label>;
337 State initial_state = State::Unchecked;
342 Checkbox6(State initial_state = State::Unchecked,
bool locked =
false)
343 :
HCheckbox{initial_state, {U
"└x┘", U
"└ ┘"}, locked}
346 Checkbox6(Parameters p) : Checkbox6{p.initial_state, p.locked} {}
349 inline auto constexpr checkbox6 = make_checkbox_fn<Checkbox6>;
351 using VLabel_checkbox6 =
352 detail::Label_checkbox_impl<layout::Vertical, Checkbox6, false>;
354 inline auto constexpr vlabel_checkbox6 = make_labeled_cb_fn<VLabel_checkbox6>;
362 State initial_state = State::Unchecked;
367 Checkbox7(State initial_state = State::Unchecked,
bool locked =
false)
368 :
VCheckbox{initial_state, {U
"╭x╰", U
"╭ ╰"}, locked}
371 Checkbox7(Parameters p) : Checkbox7{p.initial_state, p.locked} {}
374 inline auto constexpr checkbox7 = make_checkbox_fn<Checkbox7>;
376 using HCheckbox7_label =
377 detail::Label_checkbox_impl<layout::Horizontal, Checkbox7, true>;
379 inline auto constexpr hcheckbox7_label = make_labeled_cb_fn<HCheckbox7_label>;
387 State initial_state = State::Unchecked;
392 Checkbox8(State initial_state = State::Unchecked,
bool locked =
false)
393 :
VCheckbox{initial_state, {U
"╮x╯", U
"╮ ╯"}, locked}
396 Checkbox8(Parameters p) : Checkbox8{p.initial_state, p.locked} {}
399 inline auto constexpr checkbox8 = make_checkbox_fn<Checkbox8>;
401 using HLabel_checkbox8 =
402 detail::Label_checkbox_impl<layout::Horizontal, Checkbox8, false>;
404 inline auto constexpr hlabel_checkbox8 = make_labeled_cb_fn<HLabel_checkbox8>;
410 State initial_state = State::Unchecked;
415 Checkbox9(State initial_state = State::Unchecked,
bool locked =
false)
416 :
HCheckbox{initial_state, {U
"╭x╮", U
"╭ ╮"}, locked}
419 Checkbox9(Parameters p) : Checkbox9{p.initial_state, p.locked} {}
422 inline auto constexpr checkbox9 = make_checkbox_fn<Checkbox9>;
424 using VCheckbox9_label =
425 detail::Label_checkbox_impl<layout::Vertical, Checkbox9, true>;
427 inline auto constexpr vcheckbox9_label = make_labeled_cb_fn<VCheckbox9_label>;
433 State initial_state = State::Unchecked;
438 Checkbox10(State initial_state = State::Unchecked,
bool locked =
false)
439 :
HCheckbox{initial_state, {U
"╰x╯", U
"╰ ╯"}, locked}
442 Checkbox10(Parameters p) : Checkbox10{p.initial_state, p.locked} {}
445 inline auto constexpr checkbox10 = make_checkbox_fn<Checkbox10>;
447 using VLabel_checkbox10 =
448 detail::Label_checkbox_impl<layout::Vertical, Checkbox10, false>;
450 inline auto constexpr vlabel_checkbox10 = make_labeled_cb_fn<VLabel_checkbox10>;
460 State initial_state = State::Unchecked;
465 Checkbox11(State initial_state = State::Unchecked,
bool locked =
false)
466 :
VCheckbox{initial_state, {U
"┘╴┐", U
"┘ ┐"}, locked}
469 Checkbox11(Parameters p) : Checkbox11{p.initial_state, p.locked} {}
472 inline auto constexpr checkbox11 = make_checkbox_fn<Checkbox11>;
474 using HCheckbox11_label =
475 detail::Label_checkbox_impl<layout::Horizontal, Checkbox11, true>;
477 inline auto constexpr hcheckbox11_label = make_labeled_cb_fn<HCheckbox11_label>;
485 State initial_state = State::Unchecked;
490 Checkbox12(State initial_state = State::Unchecked,
bool locked =
false)
491 :
VCheckbox{initial_state, {U
"└╶┌", U
"└ ┌"}, locked}
494 Checkbox12(Parameters p) : Checkbox12{p.initial_state, p.locked} {}
497 inline auto constexpr checkbox12 = make_checkbox_fn<Checkbox12>;
499 using HLabel_checkbox12 =
500 detail::Label_checkbox_impl<layout::Horizontal, Checkbox12, false>;
502 inline auto constexpr hlabel_checkbox12 = make_labeled_cb_fn<HLabel_checkbox12>;
508 State initial_state = State::Unchecked;
513 Checkbox13(State initial_state = State::Unchecked,
bool locked =
false)
514 :
HCheckbox{initial_state, {U
"┘╵└", U
"┘ └"}, locked}
517 Checkbox13(Parameters p) : Checkbox13{p.initial_state, p.locked} {}
520 inline auto constexpr checkbox13 = make_checkbox_fn<Checkbox13>;
522 using VCheckbox13_label =
523 detail::Label_checkbox_impl<layout::Vertical, Checkbox13, true>;
525 inline auto constexpr vcheckbox13_label = make_labeled_cb_fn<VCheckbox13_label>;
531 State initial_state = State::Unchecked;
536 Checkbox14(State initial_state = State::Unchecked,
bool locked =
false)
537 :
HCheckbox{initial_state, {U
"┐╷┌", U
"┐ ┌"}, locked}
540 Checkbox14(Parameters p) : Checkbox14{p.initial_state, p.locked} {}
543 inline auto constexpr checkbox14 = make_checkbox_fn<Checkbox14>;
545 using VLabel_checkbox14 =
546 detail::Label_checkbox_impl<layout::Vertical, Checkbox14, false>;
548 inline auto constexpr vlabel_checkbox14 = make_labeled_cb_fn<VLabel_checkbox14>;
556 State initial_state = State::Unchecked;
561 Checkbox15(State initial_state = State::Unchecked,
bool locked =
false)
562 :
VCheckbox{initial_state, {U
"╯╴╮", U
"╯ ╮"}, locked}
565 Checkbox15(Parameters p) : Checkbox15{p.initial_state, p.locked} {}
568 inline auto constexpr checkbox15 = make_checkbox_fn<Checkbox15>;
570 using HCheckbox15_label =
571 detail::Label_checkbox_impl<layout::Horizontal, Checkbox15, true>;
573 inline auto constexpr hcheckbox15_label = make_labeled_cb_fn<HCheckbox15_label>;
581 State initial_state = State::Unchecked;
586 Checkbox16(State initial_state = State::Unchecked,
bool locked =
false)
587 :
VCheckbox{initial_state, {U
"╰╶╭", U
"╰ ╭"}, locked}
590 Checkbox16(Parameters p) : Checkbox16{p.initial_state, p.locked} {}
593 inline auto constexpr checkbox16 = make_checkbox_fn<Checkbox16>;
595 using HLabel_checkbox16 =
596 detail::Label_checkbox_impl<layout::Horizontal, Checkbox16, false>;
598 inline auto constexpr hlabel_checkbox16 = make_labeled_cb_fn<HLabel_checkbox16>;
604 State initial_state = State::Unchecked;
609 Checkbox17(State initial_state = State::Unchecked,
bool locked =
false)
610 :
HCheckbox{initial_state, {U
"╯╵╰", U
"╯ ╰"}, locked}
613 Checkbox17(Parameters p) : Checkbox17{p.initial_state, p.locked} {}
616 inline auto constexpr checkbox17 = make_checkbox_fn<Checkbox17>;
618 using VCheckbox17_label =
619 detail::Label_checkbox_impl<layout::Vertical, Checkbox17, true>;
621 inline auto constexpr vcheckbox17_label = make_labeled_cb_fn<VCheckbox17_label>;
627 State initial_state = State::Unchecked;
632 Checkbox18(State initial_state = State::Unchecked,
bool locked =
false)
633 :
HCheckbox{initial_state, {U
"╮╷╭", U
"╮ ╭"}, locked}
636 Checkbox18(Parameters p) : Checkbox18{p.initial_state, p.locked} {}
639 inline auto constexpr checkbox18 = make_checkbox_fn<Checkbox18>;
641 using VLabel_checkbox18 =
642 detail::Label_checkbox_impl<layout::Vertical, Checkbox18, false>;
644 inline auto constexpr vlabel_checkbox18 = make_labeled_cb_fn<VLabel_checkbox18>;
652 State initial_state = State::Unchecked;
657 Checkbox19(State initial_state = State::Unchecked,
bool locked =
false)
658 :
HCheckbox{initial_state, {U
"├x┤", U
"├ ┤"}, locked}
661 Checkbox19(Parameters p) : Checkbox19{p.initial_state, p.locked} {}
664 inline auto constexpr checkbox19 = make_checkbox_fn<Checkbox19>;
666 using HCheckbox19_label =
667 detail::Label_checkbox_impl<layout::Horizontal, Checkbox19, true>;
668 using HLabel_checkbox19 =
669 detail::Label_checkbox_impl<layout::Horizontal, Checkbox19, false>;
670 using VCheckbox19_label =
671 detail::Label_checkbox_impl<layout::Vertical, Checkbox19, true>;
672 using VLabel_checkbox19 =
673 detail::Label_checkbox_impl<layout::Vertical, Checkbox19, false>;
675 inline auto constexpr hcheckbox19_label = make_labeled_cb_fn<HCheckbox19_label>;
676 inline auto constexpr hlabel_checkbox19 = make_labeled_cb_fn<HLabel_checkbox19>;
677 inline auto constexpr vcheckbox19_label = make_labeled_cb_fn<VCheckbox19_label>;
678 inline auto constexpr vlabel_checkbox19 = make_labeled_cb_fn<VLabel_checkbox19>;
684 State initial_state = State::Unchecked;
689 Checkbox20(State initial_state = State::Unchecked,
bool locked =
false)
690 :
HCheckbox{initial_state, {U
"┤x├", U
"┤ ├"}, locked}
693 Checkbox20(Parameters p) : Checkbox20{p.initial_state, p.locked} {}
696 inline auto constexpr checkbox20 = make_checkbox_fn<Checkbox20>;
698 using HCheckbox20_label =
699 detail::Label_checkbox_impl<layout::Horizontal, Checkbox20, true>;
700 using HLabel_checkbox20 =
701 detail::Label_checkbox_impl<layout::Horizontal, Checkbox20, false>;
702 using VCheckbox20_label =
703 detail::Label_checkbox_impl<layout::Vertical, Checkbox20, true>;
704 using VLabel_checkbox20 =
705 detail::Label_checkbox_impl<layout::Vertical, Checkbox20, false>;
707 inline auto constexpr hcheckbox20_label = make_labeled_cb_fn<HCheckbox20_label>;
708 inline auto constexpr hlabel_checkbox20 = make_labeled_cb_fn<HLabel_checkbox20>;
709 inline auto constexpr vcheckbox20_label = make_labeled_cb_fn<VCheckbox20_label>;
710 inline auto constexpr vlabel_checkbox20 = make_labeled_cb_fn<VLabel_checkbox20>;
716 template <
template <
typename>
typename Layout_t>
717 auto toggle(Checkbox<Layout_t>& cb) -> sl::Slot<void()>;
719 template <
template <
typename>
typename Layout_t>
720 auto check(Checkbox<Layout_t>& cb) -> sl::Slot<void()>;
722 template <
template <
typename>
typename Layout_t>
723 auto uncheck(Checkbox<Layout_t>& cb) -> sl::Slot<void()>;
Definition: checkbox.hpp:430
Definition: checkbox.hpp:457
Definition: checkbox.hpp:482
Definition: checkbox.hpp:505
Definition: checkbox.hpp:528
Definition: checkbox.hpp:553
Definition: checkbox.hpp:578
Definition: checkbox.hpp:601
Definition: checkbox.hpp:624
Definition: checkbox.hpp:649
Definition: checkbox.hpp:186
Definition: checkbox.hpp:681
Definition: checkbox.hpp:229
Definition: checkbox.hpp:263
Definition: checkbox.hpp:288
Definition: checkbox.hpp:311
Definition: checkbox.hpp:334
Definition: checkbox.hpp:359
Definition: checkbox.hpp:384
Definition: checkbox.hpp:407
Checkbox Widget that is either checked or not checked.
Definition: checkbox.hpp:22
void uncheck()
Set the state to be unchecked.
Definition: checkbox.cpp:52
void toggle()
Change state to be unchecked if currently checked, checked otherwise.
Definition: checkbox.cpp:65
sl::Signal< void()> unchecked
Emitted when box becomes unchecked.
Definition: checkbox.hpp:45
void set_display(Display d)
Set the look of each Checkbox State.
Definition: checkbox.cpp:103
auto get_state() const -> State
Return the current state of the Checkbox as Checkbox::State enum value.
Definition: checkbox.cpp:74
auto get_display() -> Display
Return the look of each Checkbox State.
Definition: checkbox.cpp:114
Checkbox(State initial_state, Display display, bool locked)
Construct a new Checkbox.
Definition: checkbox.cpp:17
void lock()
Lock the Checkbox, it can not be toggled when locked.
Definition: checkbox.cpp:79
sl::Signal< void()> checked
Emitted when box becomes checked.
Definition: checkbox.hpp:42
void unlock()
Unlock the Checkbox, allowing it to be toggled.
Definition: checkbox.cpp:88
void check()
Set the state to be checked.
Definition: checkbox.cpp:38
sl::Signal< void()> toggled
Emitted every time the box changes state.
Definition: checkbox.hpp:48
auto is_locked() const -> bool
Return true if the Checkbox is locked.
Definition: checkbox.cpp:97
auto mouse_press_event(Mouse const &m) -> bool override
Handles Mouse_press_event objects.
Definition: checkbox.cpp:125
Holds a collection of Glyphs with a similar interface to std::string.
Definition: glyph_string.hpp:19
A single line of text with alignment, non-editable.
Definition: label.hpp:22
Label, buffer and Checkbox tuple implementation.
Definition: checkbox.hpp:128
Wraps a Widget_t object with a label.
Definition: label.hpp:171
Definition: checkbox.hpp:432
Definition: checkbox.hpp:459
Definition: checkbox.hpp:484
Definition: checkbox.hpp:507
Definition: checkbox.hpp:530
Definition: checkbox.hpp:555
Definition: checkbox.hpp:580
Definition: checkbox.hpp:603
Definition: checkbox.hpp:626
Definition: checkbox.hpp:651
Definition: checkbox.hpp:188
Definition: checkbox.hpp:683
Definition: checkbox.hpp:231
Definition: checkbox.hpp:265
Definition: checkbox.hpp:290
Definition: checkbox.hpp:313
Definition: checkbox.hpp:336
Definition: checkbox.hpp:361
Definition: checkbox.hpp:386
Definition: checkbox.hpp:409
Definition: checkbox.hpp:29
Definition: checkbox.hpp:34