display

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

window.cpp (1878B)


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