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.cpp (1810B)


1 #include <format> 2 #include <fstream> 3 #include <iostream> 4 5 #include "display/window.hpp" 6 7 namespace display 8 { 9 10 std::ostream& Window::set_cursor(xpos_t xpos, ypos_t ypos) const 11 { 12 return Element::set_cursor(axpos() + xpos, aypos() + ypos); 13 } 14 15 std::ostream& Window::set_cursor(pos_t pos) const 16 { 17 return Element::set_cursor(apos() + pos); 18 } 19 20 void Window::render() const 21 { 22 const auto space = std::string(awth().value(), ' '); 23 24 for (auto j = aypos(); j < aypos() + m_padd.top; j++) { 25 Element::set_cursor(axpos(), j) << space; 26 } 27 28 for (auto j = m_ypos; j < aypos() + ahgt(); j++) { 29 Element::set_cursor(axpos(), j) << space; 30 } 31 } 32 33 void Window::line_reset() const 34 { 35 m_ypos = ypos(); 36 } 37 38 std::ostream& Window::line_next() const 39 { 40 if (m_ypos == ypos() + hgt()) { 41 static std::ofstream null; 42 null.setstate(std::ios_base::badbit); 43 return null; 44 } 45 46 return Element::set_cursor(axpos(), m_ypos++); 47 } 48 49 void Window::line_empty() const 50 { 51 line_next() << std::string(awth().value(), ' '); 52 } 53 54 void Window::line_left(const std::string& text) const 55 { 56 const auto left = std::string(m_padd.left.value(), ' '); 57 const auto right = std::string(m_padd.right.value(), ' '); 58 59 line_next() << left << std::format("{:<{}}", text, wth().value()) << right; 60 } 61 62 void Window::line_center(const std::string& text) const 63 { 64 const auto left = std::string(m_padd.left.value(), ' '); 65 const auto right = std::string(m_padd.right.value(), ' '); 66 67 line_next() << left << std::format("{:^{}}", text, wth().value()) << right; 68 } 69 70 void Window::line_right(const std::string& text) const 71 { 72 const auto left = std::string(m_padd.left.value(), ' '); 73 const auto right = std::string(m_padd.right.value(), ' '); 74 75 line_next() << left << std::format("{:>{}}", text, wth().value()) << right; 76 } 77 78 } // namespace display