1 #ifndef TERMOX_WIDGET_LAYOUT_FIXED_HPP
2 #define TERMOX_WIDGET_LAYOUT_FIXED_HPP
5 #include <termox/widget/layouts/horizontal.hpp>
6 #include <termox/widget/layouts/vertical.hpp>
7 #include <termox/widget/pipe.hpp>
8 #include <termox/widget/widget.hpp>
13 template <
template <
typename>
typename Layout_t,
typename Widget_t>
14 class Fixed :
public Layout_t<Widget> {
16 using Base_t = Layout_t<Widget>;
18 static auto constexpr is_horizontal = layout::is_horizontal_v<Base_t>;
26 template <
typename... Args>
27 Fixed(
int offset_1,
int offset_2, Args&&... args)
28 : buffer_1{this->
template make_child()},
30 this->
template make_child<Widget_t>(std::forward<Args>(args)...)},
31 buffer_2{this->
template make_child()},
35 assert(offset_1_ >= 0 && offset_2_ >= 0);
36 this->update_policies(offset_1_, offset_2_);
37 if constexpr (is_horizontal) {
38 buffer_1 | pipe::fixed_width(offset_1_);
39 buffer_2 | pipe::fixed_width(offset_2_);
42 buffer_1 | pipe::fixed_height(offset_1_);
43 buffer_2 | pipe::fixed_height(offset_2_);
47 template <
typename... Args>
48 Fixed(
int offset, Args&&... args)
49 :
Fixed{offset, offset, std::forward<Args>(args)...}
53 auto child_polished_event(
Widget& child) ->
bool override
55 if (&child == &widget)
56 this->update_policies(offset_1_, offset_2_);
57 return Base_t::child_polished_event(child);
65 void update_policies(
int offset_1,
int offset_2)
68 auto const offset_total = offset_1 + offset_2;
69 sp.hint(sp.hint() + offset_total);
70 sp.min(sp.min() + offset_total);
72 sp.max(sp.max() + offset_total);
75 this->height_policy = widget.height_policy;
76 this->width_policy = widget.width_policy;
78 if constexpr (is_horizontal)
79 offset_policy(this->width_policy);
81 offset_policy(this->width_policy);
85 template <
typename W
idget_t>
88 template <
typename Widget_t,
typename... Args>
89 [[nodiscard]]
inline auto hfixed(Args&&... args)
90 -> std::unique_ptr<HFixed<Widget_t>>
92 return std::make_unique<HFixed<Widget_t>>(std::forward<Args>(args)...);
95 template <
typename W
idget_t>
96 using VFixed = Fixed<layout::Vertical, Widget_t>;
98 template <
typename Widget_t,
typename... Args>
99 [[nodiscard]]
inline auto vfixed(Args&&... args)
100 -> std::unique_ptr<VFixed<Widget_t>>
102 return std::make_unique<VFixed<Widget_t>>(std::forward<Args>(args)...);
105 template <
typename W
idget_t>
110 template <
typename... Args>
111 Fixed_2d(
int north,
int south,
int east,
int west, Args&&... args)
112 : Base_t{west, east, north, south, std::forward<Args>(args)...}
116 Widget_t& widget = this->Base_t::widget.widget;
119 template <
typename Widget_t,
typename... Args>
120 [[nodiscard]]
inline auto fixed_2d(Args&&... args)
121 -> std::unique_ptr<Fixed_2d<Widget_t>>
123 return std::make_unique<Fixed_2d<Widget_t>>(std::forward<Args>(args)...);
Definition: fixed.hpp:106
Fixed offset before and after Widget_t object.
Definition: fixed.hpp:14
Defines how a Layout should resize a Widget in one length Dimension.
Definition: size_policy.hpp:11
static constexpr auto maximum_max
Largest possible value for max().
Definition: size_policy.hpp:26