TermOx
hideable.hpp
1 #ifndef TERMOX_WIDGET_WIDGETS_HIDEABLE_HPP
2 #define TERMOX_WIDGET_WIDGETS_HIDEABLE_HPP
3 #include <utility>
4 
5 #include <termox/widget/layouts/stack.hpp>
6 #include <termox/widget/pair.hpp>
7 #include <termox/widget/widget.hpp>
8 
9 namespace ox {
10 
12 template <typename Widget_t>
13 class Hideable : public SPair<Widget, Widget_t> {
14  public:
15  using Parameters = typename Widget_t::Parameter;
16 
17  public:
18  Widget_t& w = this->second;
19 
20  public:
21  Hideable()
22  {
23  this->set_active_page(widget_index_);
24  this->give_focus_on_change(false);
25  }
26 
28 
29  explicit Hideable(Parameters p) : SPair<Widget, Widget_t>{{}, p}
30  {
31  this->set_active_page(widget_index_);
32  this->give_focus_on_change(false);
33  }
34 
35  public:
37  void show() { this->set_active_page(widget_index_); }
38 
40  void hide() { this->set_active_page(blank_index_); }
41 
43  [[nodiscard]] auto is_hidden() const -> bool
44  {
45  return this->active_page_index() == blank_index_;
46  }
47 
48  private:
49  static constexpr auto blank_index_ = 0uL;
50  static constexpr auto widget_index_ = 1uL;
51 };
52 
54 template <typename Widget_t>
55 [[nodiscard]] auto hideable() -> std::unique_ptr<Hideable<Widget_t>>
56 {
57  return std::make_unique<Hideable<Widget_t>>();
58 }
59 
61 template <typename Widget_t>
62 [[nodiscard]] auto hideable(typename Hideable<Widget_t>::Parameters p)
63  -> std::unique_ptr<Hideable<Widget_t>>
64 {
65  return std::make_unique<Hideable<Widget_t>>(std::move(p));
66 }
67 
68 } // namespace ox
69 #endif // TERMOX_WIDGET_WIDGETS_HIDEABLE_HPP
Policy to make any Widget or Layout hideable with a hide() and show() method.
Definition: hideable.hpp:13
auto is_hidden() const -> bool
Return if w is hidden.
Definition: hideable.hpp:43
void hide()
Display nothing on the widget space.
Definition: hideable.hpp:40
void show()
Display the held widget.
Definition: hideable.hpp:37
Hideable(Parameters p)
Forward constructor Parameters for the Widget_t that is being wrapped.
Definition: hideable.hpp:29
Definition: widget.hpp:31
Heterogeneous pair of Widgets within a Layout.
Definition: pair.hpp:14