TermOx
button_list.hpp
1 #ifndef TERMOX_WIDGET_WIDGETS_BUTTON_LIST_HPP
2 #define TERMOX_WIDGET_WIDGETS_BUTTON_LIST_HPP
3 #include <memory>
4 #include <string>
5 
6 #include <signals_light/signal.hpp>
7 
8 #include <termox/widget/layouts/horizontal.hpp>
9 #include <termox/widget/layouts/opposite.hpp>
10 #include <termox/widget/layouts/passive.hpp>
11 #include <termox/widget/layouts/vertical.hpp>
12 #include <termox/widget/pair.hpp>
13 #include <termox/widget/pipe.hpp>
14 #include <termox/widget/widget.hpp>
15 #include <termox/widget/widgets/button.hpp>
16 #include <termox/widget/widgets/scrollbar.hpp>
17 
18 namespace ox::detail {
19 
20 template <template <typename> class Layout_t>
21 class Just_a_button_list : public Passive<Layout_t<Button>> {
22  public:
23  sl::Signal<void(std::u32string const& name)> button_pressed;
24 
25  public:
26  auto add_button(std::u32string const& name) -> Button&;
27 };
28 
29 template <template <typename> class Layout_t>
31  : Pair<Layout_t<Widget>, Just_a_button_list<Layout_t>, Widget> {
32  Just_a_button_list<Layout_t>& buttons = this->first;
33  Widget& buffer = this->second;
34 };
35 
36 } // namespace ox::detail
37 
38 namespace ox {
39 
41 template <template <typename> class Layout_t>
43  : public Pair<layout::Opposite_t<Layout_t<Widget>>,
44  Scrollbar<Layout_t>,
45  detail::Just_a_button_list_and_buffer<Layout_t>> {
46  private:
47  Scrollbar<Layout_t>& scrollbar = this->first;
48  detail::Just_a_button_list<Layout_t>& buttons = this->second.buttons;
49  Widget& buffer = this->second.buffer;
50 
51  public:
52  sl::Signal<void(std::u32string const& name)>& button_pressed =
53  buttons.button_pressed;
54 
55  struct Parameters {
56  Color scrollbar_bg = Color::Background;
57  Color scrollbar_fg = Color::Foreground;
58  };
59 
60  public:
61  explicit Button_list(Color scrollbar_bg = Color::Background,
62  Color scrollbar_fg = Color::Foreground);
63 
64  explicit Button_list(Parameters p);
65 
66  public:
68 
69  auto add_button(std::u32string const& name) -> Button&;
70 
72  void set_scrollbar_bg(Color c);
73 
75  void set_scrollbar_fg(Color c);
76 };
77 
79 template <template <typename> class Layout_t>
80 [[nodiscard]] auto button_list(
81  typename Button_list<Layout_t>::Parameters p = {})
82  -> std::unique_ptr<Button_list<Layout_t>>;
83 
84 using VButton_list = Button_list<layout::Vertical>;
85 using HButton_list = Button_list<layout::Horizontal>;
86 
88 [[nodiscard]] auto vbutton_list(VButton_list::Parameters p = {})
89  -> std::unique_ptr<VButton_list>;
90 
92 [[nodiscard]] auto hbutton_list(HButton_list::Parameters p = {})
93  -> std::unique_ptr<HButton_list>;
94 
95 } // namespace ox
96 #endif // TERMOX_WIDGET_WIDGETS_BUTTON_LIST_HPP
A list of buttons with connected scrollbar.
Definition: button_list.hpp:45
void set_scrollbar_bg(Color c)
Set the background color of the Scrollbar.
Definition: button_list.cpp:49
void set_scrollbar_fg(Color c)
Set the foreground color of the Scrollbar.
Definition: button_list.cpp:55
auto add_button(std::u32string const &name) -> Button &
Returns reference to the Button added.
Definition: button_list.cpp:43
Button widget that emits Signal on a left mouse button press.
Definition: button.hpp:18
Color numbers [0 - 180] are valid.
Definition: color.hpp:16
Definition: passive.hpp:34
Scrollbar to display progress through some structure, and control progress.
Definition: scrollbar.hpp:27
Definition: widget.hpp:31
Definition: button_list.hpp:21
Definition: button_list.hpp:55
Heterogeneous pair of Widgets within a Layout.
Definition: pair.hpp:14
Definition: button_list.hpp:31