display

Layout and Rendering TUI library
git clone git://git.dimitrijedobrota.com/display.git
Log | Files | Refs | README | LICENSE | HACKING | CONTRIBUTING | CODE_OF_CONDUCT | BUILDING

window_pivot.cpp (1274B)


0 #include "display/window_pivot.hpp"
2 #include "display/utility.hpp"
4 namespace display
5 {
7 using namespace literals; // NOLINT(*namespace*)
9 plc_t WindowPivot::place(plc_t aplc, piv_t piv, dim_t dim)
10 {
11 const auto [awth, ahth] = aplc.dim;
12 const auto [wth, hgt] = dim;
14 dim_t start(0_w, 0_h);
15 dim_t end(0_w, 0_h);
17 using display::add_lim, display::sub_lim;
19 switch (piv.piv_x()) {
20 case piv_t::x::left():
21 start.width = 0_w;
22 end.width = add_lim(start.width, wth, awth);
23 break;
24 case piv_t::x::center():
25 start.width = sub_lim((awth / 2_w), (wth / 2_w), 0_w);
26 end.width = add_lim(start.width, wth, awth);
27 break;
28 case piv_t::x::right():
29 end.width = awth;
30 start.width = sub_lim(end.width, wth, 0_w);
31 break;
32 }
34 switch (piv.piv_y()) {
35 case piv_t::y::top():
36 start.height = 0_h;
37 end.height = add_lim(start.height, hgt, ahth);
38 break;
39 case piv_t::y::center():
40 start.height = sub_lim((ahth / 2_h), (hgt / 2_h), 0_h);
41 end.height = add_lim(start.height, hgt, ahth);
42 break;
43 case piv_t::y::bottom():
44 end.height = ahth;
45 start.height = sub_lim(end.height, hgt, 0_h);
46 break;
47 }
49 return {aplc.pos + start, end - start};
50 }
52 } // namespace display