1 #ifndef TERMOX_WIDGET_WIDGETS_MENU_STACK_HPP
2 #define TERMOX_WIDGET_WIDGETS_MENU_STACK_HPP
7 #include <termox/painter/glyph_string.hpp>
8 #include <termox/system/system.hpp>
9 #include <termox/widget/focus_policy.hpp>
10 #include <termox/widget/layouts/stack.hpp>
11 #include <termox/widget/widgets/menu.hpp>
26 static auto constexpr menu_index_ = 0uL;
32 this->Stack::set_active_page(menu_index_);
42 template <
typename Widget_t,
typename... Args>
45 static_assert(std::is_base_of<Widget, Widget_t>::value,
46 "Menu_stack::make_page: Widget_t must be a Widget type");
48 this->Stack::make_page<Widget_t>(std::forward<Args>(args)...);
49 this->connect_to_menu(std::move(title), this->Stack::size() - 1);
54 template <
typename W
idget_t>
58 std::is_base_of<Child_t, Widget_t>::value,
59 "Menu_stack::append_page: Widget_t must be a Child_t type");
60 this->Stack::append_page(std::move(w_ptr));
61 this->connect_to_menu(std::move(title), this->Stack::size() - 1);
67 std::unique_ptr<Widget> widget,
70 this->Stack::insert_page(std::move(widget), index + 1);
71 this->connect_to_menu(std::move(title), index + 1);
79 this->remove_from_menu(index + 1);
80 this->Stack::delete_page(index + 1);
87 [[nodiscard]]
auto remove_page(std::size_t index) -> std::unique_ptr<Widget>
89 this->remove_from_menu(index + 1);
90 return this->Stack::remove_page(index + 1);
103 [[nodiscard]]
auto size() const -> std::
size_t
105 return this->Stack::size() - 1;
109 [[nodiscard]]
auto menu() ->
Menu& {
return menu_; }
112 [[nodiscard]]
auto menu() const ->
Menu const& {
return menu_; }
115 void goto_menu() { this->Stack::set_active_page(menu_index_); }
120 this->Stack::set_active_page(index + 1);
129 void remove_from_menu(std::size_t index)
132 if (this->Stack::active_page_index() == index)
133 this->Stack::set_active_page(menu_index_);
138 void connect_to_menu(Glyph_string title, std::size_t index)
140 auto& signal = menu_.
insert_item(std::move(title), index - 1);
141 signal.connect(slot::set_active_page(*
this, index));
146 template <
typename... Args>
147 [[nodiscard]]
auto menu_stack(Args&&... args) -> std::unique_ptr<Menu_stack>
149 return std::make_unique<Menu_stack>(std::forward<Args>(args)...);
Holds a collection of Glyphs with a similar interface to std::string.
Definition: glyph_string.hpp:19
A Layout enabling only a single Widget at a time.
Definition: stack.hpp:29