TermOx
menu.hpp
1 #ifndef TERMOX_WIDGET_WIDGETS_MENU_HPP
2 #define TERMOX_WIDGET_WIDGETS_MENU_HPP
3 #include <cstddef>
4 #include <memory>
5 
6 #include <signals_light/signal.hpp>
7 
8 #include <termox/painter/glyph_string.hpp>
9 #include <termox/system/key.hpp>
10 #include <termox/system/mouse.hpp>
11 #include <termox/widget/layouts/passive.hpp>
12 #include <termox/widget/layouts/selecting.hpp>
13 #include <termox/widget/layouts/vertical.hpp>
14 #include <termox/widget/pair.hpp>
15 #include <termox/widget/widgets/label.hpp>
16 #include <termox/widget/widgets/selectable.hpp>
17 
18 namespace ox {
19 
20 class Menu_item : public Selectable<HLabel> {
21  public:
22  sl::Signal<void()> selected;
23 
24  public:
25  explicit Menu_item(Glyph_string label);
26 };
27 
28 class Menu_list
29  : public Passive<layout::Selecting<layout::Vertical<Menu_item>>> {
31 
32  public:
33  Menu_list();
34 
35  public:
37 
38  auto append_item(Glyph_string label) -> sl::Signal<void()>&;
39 
41 
42  auto insert_item(Glyph_string label, std::size_t index)
43  -> sl::Signal<void()>&;
44 
46  void remove_item(std::size_t index);
47 
48  protected:
49  auto key_press_event(Key k) -> bool override;
50 
51  // Selecting base class installs event filter on children.
52  auto mouse_press_event_filter(Widget& w, Mouse const& m) -> bool override;
53 };
54 
55 class Menu : public VPair<Menu_list, Widget> {
56  public:
57  Menu();
58 
59  public:
61 
62  auto append_item(Glyph_string label) -> sl::Signal<void()>&;
63 
65 
66  auto insert_item(Glyph_string label, std::size_t index)
67  -> sl::Signal<void()>&;
68 
70  void remove_item(std::size_t index);
71 
72  private:
73  Menu_list& menu_ = this->first;
74  Widget& buffer = this->second;
75 };
76 
78 [[nodiscard]] auto menu() -> std::unique_ptr<Menu>;
79 
80 } // namespace ox
81 #endif // TERMOX_WIDGET_WIDGETS_MENU_HPP
Holds a collection of Glyphs with a similar interface to std::string.
Definition: glyph_string.hpp:19
Definition: menu.hpp:20
Definition: menu.hpp:29
auto append_item(Glyph_string label) -> sl::Signal< void()> &
Append item to the end of list, displayed with label.
Definition: menu.cpp:31
void remove_item(std::size_t index)
Remove item a index in the Menu_list, no-op if index is invalid.
Definition: menu.cpp:44
auto insert_item(Glyph_string label, std::size_t index) -> sl::Signal< void()> &
Insert item at index into the Menu_list, displayed with label.
Definition: menu.cpp:36
Definition: menu.hpp:55
void remove_item(std::size_t index)
Remove item a index in the Menu_list, no-op if index is invalid.
Definition: menu.cpp:95
auto append_item(Glyph_string label) -> sl::Signal< void()> &
Append item to the end of list, displayed with label.
Definition: menu.cpp:84
auto insert_item(Glyph_string label, std::size_t index) -> sl::Signal< void()> &
Insert item at index into the Menu_list, displayed with label.
Definition: menu.cpp:89
Definition: passive.hpp:34
Wraps Widget_t to provide select() and unselect() methods to modify display.
Definition: selectable.hpp:12
Definition: widget.hpp:31
Adds a 'Selected Child' concept to Layout_t.
Definition: selecting.hpp:24
Heterogeneous pair of Widgets within a Layout.
Definition: pair.hpp:14