TermOx
toggle_button.hpp
1 #ifndef TERMOX_WIDGET_WIDGETS_TOGGLE_BUTTON_HPP
2 #define TERMOX_WIDGET_WIDGETS_TOGGLE_BUTTON_HPP
3 #include <memory>
4 #include <utility>
5 
6 #include <signals_light/signal.hpp>
7 
8 #include <termox/painter/glyph_string.hpp>
9 #include <termox/widget/pair.hpp>
10 #include <termox/widget/widgets/button.hpp>
11 
12 namespace ox {
13 
15 
16 class Toggle_button : public SPair<Button, Button> {
17  public:
18  struct Parameters {
19  Glyph_string top_text;
20  Glyph_string bottom_text;
21  };
22 
23  public:
24  Button& top = this->first;
25  Button& bottom = this->second;
26 
27  public:
28  sl::Signal<void()>& top_pressed = top.pressed;
29  sl::Signal<void()>& bottom_pressed = bottom.pressed;
30 
31  public:
33  Toggle_button(Glyph_string top_text, Glyph_string bottom_text);
34 
36  explicit Toggle_button(Parameters p);
37 
38  public:
40  void show_top();
41 
43  void show_bottom();
44 
46  void toggle();
47 };
48 
50 [[nodiscard]] auto toggle_button(Glyph_string top_text,
51  Glyph_string bottom_text)
52  -> std::unique_ptr<Toggle_button>;
53 
55 [[nodiscard]] auto toggle_button(Toggle_button::Parameters p)
56  -> std::unique_ptr<Toggle_button>;
57 
58 } // namespace ox
59 #endif // TERMOX_WIDGET_WIDGETS_TOGGLE_BUTTON_HPP
Button widget that emits Signal on a left mouse button press.
Definition: button.hpp:18
sl::Signal< void()> pressed
Emitted on a left mouse button press.
Definition: button.hpp:26
Holds a collection of Glyphs with a similar interface to std::string.
Definition: glyph_string.hpp:19
A Button with two alternating sides.
Definition: toggle_button.hpp:16
void show_bottom()
Display the bottom button, without emitting any Signals.
Definition: toggle_button.cpp:37
void show_top()
Display the top button, without emitting any Signals.
Definition: toggle_button.cpp:35
void toggle()
Change the displayed button without emitting any signals.
Definition: toggle_button.cpp:39
Toggle_button(Glyph_string top_text, Glyph_string bottom_text)
Construct with corresponding labels.
Definition: toggle_button.cpp:20
Heterogeneous pair of Widgets within a Layout.
Definition: pair.hpp:14
Definition: toggle_button.hpp:18