displayLayout and Rendering TUI library |
git clone git://git.dimitrijedobrota.com/display.git |
Log | Files | Refs | README | LICENSE | HACKING | CONTRIBUTING | CODE_OF_CONDUCT | BUILDING |
window.cpp (1810B)
0 #include <format>
1 #include <fstream>
2 #include <iostream>
4 #include "display/window.hpp"
6 namespace display
7 {
9 std::ostream& Window::set_cursor(xpos_t xpos, ypos_t ypos) const
10 {
11 return Element::set_cursor(axpos() + xpos, aypos() + ypos);
12 }
14 std::ostream& Window::set_cursor(pos_t pos) const
15 {
16 return Element::set_cursor(apos() + pos);
17 }
19 void Window::render() const
20 {
21 const auto space = std::string(awth().value(), ' ');
23 for (auto j = aypos(); j < aypos() + m_padd.top; j++) {
24 Element::set_cursor(axpos(), j) << space;
25 }
27 for (auto j = m_ypos; j < aypos() + ahgt(); j++) {
28 Element::set_cursor(axpos(), j) << space;
29 }
30 }
32 void Window::line_reset() const
33 {
34 m_ypos = ypos();
35 }
37 std::ostream& Window::line_next() const
38 {
39 if (m_ypos == ypos() + hgt()) {
40 static std::ofstream null;
41 null.setstate(std::ios_base::badbit);
42 return null;
43 }
45 return Element::set_cursor(axpos(), m_ypos++);
46 }
48 void Window::line_empty() const
49 {
50 line_next() << std::string(awth().value(), ' ');
51 }
53 void Window::line_left(const std::string& text) const
54 {
55 const auto left = std::string(m_padd.left.value(), ' ');
56 const auto right = std::string(m_padd.right.value(), ' ');
58 line_next() << left << std::format("{:<{}}", text, wth().value()) << right;
59 }
61 void Window::line_center(const std::string& text) const
62 {
63 const auto left = std::string(m_padd.left.value(), ' ');
64 const auto right = std::string(m_padd.right.value(), ' ');
66 line_next() << left << std::format("{:^{}}", text, wth().value()) << right;
67 }
69 void Window::line_right(const std::string& text) const
70 {
71 const auto left = std::string(m_padd.left.value(), ' ');
72 const auto right = std::string(m_padd.right.value(), ' ');
74 line_next() << left << std::format("{:>{}}", text, wth().value()) << right;
75 }
77 } // namespace display