TermOx
horizontal.hpp
1 #ifndef TERMOX_WIDGET_LAYOUTS_HORIZONTAL_HPP
2 #define TERMOX_WIDGET_LAYOUTS_HORIZONTAL_HPP
3 #include <cstddef>
4 #include <memory>
5 #include <type_traits>
6 #include <utility>
7 
8 #include "detail/linear_layout.hpp"
9 
10 namespace ox::layout::h_detail {
11 
12 struct Get_area {
13  [[nodiscard]] auto operator()(int primary, int secondary) const -> Area
14  {
15  return {primary, secondary};
16  }
17 };
18 
19 struct Get_point {
20  [[nodiscard]] auto operator()(int primary, int secondary) const -> Point
21  {
22  return {primary, secondary};
23  }
24 };
25 
27  [[nodiscard]] auto operator()(Widget const& w) const -> Size_policy const&
28  {
29  return w.width_policy;
30  }
31 };
32 
34  [[nodiscard]] auto operator()(Widget const& w) const -> int
35  {
36  return w.area().width;
37  }
38 };
39 
41  [[nodiscard]] auto operator()(Widget const& w) const -> int
42  {
43  return w.top_left().x;
44  }
45 };
46 
48  [[nodiscard]] auto operator()(Widget const& w) const -> Size_policy const&
49  {
50  return w.height_policy;
51  }
52 };
53 
55  [[nodiscard]] auto operator()(Widget const& w) const -> int
56  {
57  return w.area().height;
58  }
59 };
60 
62  [[nodiscard]] auto operator()(Widget const& w) const -> int
63  {
64  return w.top_left().y;
65  }
66 };
67 
68 using Primary = detail::
69  Dimension_parameters<Primary_policy, Primary_length, Primary_offset>;
70 
71 using Secondary = detail::
72  Dimension_parameters<Secondary_policy, Secondary_length, Secondary_offset>;
73 
76 
77 } // namespace ox::layout::h_detail
78 
79 namespace ox::layout {
80 
81 template <typename Child_t = Widget>
82 using Horizontal =
84 
86 template <typename Widget_t = Widget, typename... Args>
87 [[nodiscard]] auto horizontal(Args&&... args)
88  -> std::unique_ptr<Horizontal<Widget_t>>
89 {
90  return std::make_unique<Horizontal<Widget_t>>(std::forward<Args>(args)...);
91 }
92 
93 namespace detail {
94 template <typename Child_t>
95 auto is_horizontal_impl(layout::Horizontal<Child_t>&) -> std::true_type;
96 
97 auto is_horizontal_impl(...) -> std::false_type;
98 } // namespace detail
99 
100 template <typename T>
101 using Is_horizontal = decltype(detail::is_horizontal_impl(std::declval<T&>()));
102 
104 template <typename T>
105 inline bool constexpr is_horizontal_v = Is_horizontal<T>::value;
106 
107 } // namespace ox::layout
108 #endif // TERMOX_WIDGET_LAYOUTS_HORIZONTAL_HPP
Defines how a Layout should resize a Widget in one length Dimension.
Definition: size_policy.hpp:11
Definition: widget.hpp:31
auto top_left() const -> Point
Return the global top left corner of this widget.
Definition: widget.cpp:106
Size_policy height_policy
Describes how the height of this Widget should be modified by a Layout.
Definition: widget.hpp:102
Size_policy width_policy
Describes how the width of this Widget should be modified by a Layout.
Definition: widget.hpp:99
auto area() const -> Area
Return the area the widget occupies.
Definition: widget.cpp:108
Lays out Widgets in 2D, sharing space in a primary dimension.
Definition: linear_layout.hpp:35
Definition: linear_layout.hpp:15
Definition: linear_layout.hpp:25
Definition: horizontal.hpp:12
Definition: horizontal.hpp:19
Definition: horizontal.hpp:33
Definition: horizontal.hpp:40
Definition: horizontal.hpp:26
Definition: horizontal.hpp:54
Definition: horizontal.hpp:61
Definition: horizontal.hpp:47