displayLayout and Rendering TUI library |
git clone git://git.dimitrijedobrota.com/display.git |
Log | Files | Refs | README | LICENSE | HACKING | CONTRIBUTING | CODE_OF_CONDUCT | BUILDING |
commit | f19a7bdf2f3ea69b19640adb9c03fcbbec1d6de9 |
parent | 3de3fb64e8f9d6d905972e16419088edaafa266c |
author | Dimitrije Dobrota <mail@dimitrijedobrota.com> |
date | Sun, 2 Mar 2025 11:41:08 +0100 |
Relative set_cursor, flush at the end
Diffstat:M | include/display/element.hpp | | | +++--- |
M | include/display/window.hpp | | | +++ |
M | source/display.cpp | | | + |
M | source/element.cpp | | | +++++------ |
M | source/window.cpp | | | ++++++++++++++------- |
5 files changed, 26 insertions(+), 16 deletions(-)
diff --git a/include/display/element.hpp b/include/display/element.hpp
@@ -16,7 +16,7 @@ public:
Element& operator=(const Element&) = delete;
Element(Element&&) = default;
Element& operator=(Element&&) = default;
Element& operator=(Element&&) = delete;
virtual ~Element() = default;
@@ -25,8 +25,8 @@ public:
virtual void clear() const = 0;
virtual void input(event& evnt) = 0;
static std::ostream& set_cursor(xpos_t xpos, ypos_t ypos);
static std::ostream& set_cursor(pos_t pos);
static std::ostream& set_cursor(xpos_t xapos, ypos_t yapos);
static std::ostream& set_cursor(pos_t apos);
void render_border() const;
diff --git a/include/display/window.hpp b/include/display/window.hpp
@@ -22,6 +22,9 @@ public:
protected:
pad_t padd() const { return m_padd; }
std::ostream& set_cursor(xpos_t xpos, ypos_t ypos) const;
std::ostream& set_cursor(pos_t pos) const;
std::ostream& line_next() const;
void line_reset() const;
diff --git a/source/display.cpp b/source/display.cpp
@@ -96,6 +96,7 @@ void Display::resize()
void Display::render() const
{
m_layout.render();
std::cout << std::flush;
}
void Display::input(event& evnt)
diff --git a/source/element.cpp b/source/element.cpp
@@ -5,14 +5,15 @@
namespace display
{
std::ostream& Element::set_cursor(xpos_t xpos, ypos_t ypos)
std::ostream& Element::set_cursor(xpos_t xapos, ypos_t yapos)
{
return std::cout << alec::cursor_position(ypos.value() + 1, xpos.value() + 1);
return std::cout << alec::cursor_position(yapos.value() + 1,
xapos.value() + 1);
}
std::ostream& Element::set_cursor(pos_t pos)
std::ostream& Element::set_cursor(pos_t apos)
{
return set_cursor(pos.x, pos.y);
return set_cursor(apos.x, apos.y);
}
void Element::render_border() const
@@ -36,8 +37,6 @@ void Element::render_border() const
std::cout << "─";
}
std::cout << "┘";
std::cout << std::flush;
}
} // namespace display
diff --git a/source/window.cpp b/source/window.cpp
@@ -7,18 +7,27 @@
namespace display
{
std::ostream& Window::set_cursor(xpos_t xpos, ypos_t ypos) const
{
return Element::set_cursor(axpos() + xpos, aypos() + ypos);
}
std::ostream& Window::set_cursor(pos_t pos) const
{
return Element::set_cursor(apos() + pos);
}
void Window::render() const
{
const auto space = std::string(awth().value(), ' ');
for (auto j = aypos(); j < aypos() + m_padd.top; j++) {
set_cursor(axpos(), j) << space;
Element::set_cursor(axpos(), j) << space;
}
for (auto j = m_ypos; j < aypos() + ahgt(); j++) {
set_cursor(axpos(), j) << space;
Element::set_cursor(axpos(), j) << space;
}
std::cout << std::flush;
}
void Window::clear() const
@@ -27,10 +36,8 @@ void Window::clear() const
std::cout << alec::foreground_v<alec::Color::DEFAULT>;
for (auto j = ypos_t(0); j < aypos() + ahgt(); j++) {
set_cursor(axpos(), j) << std::string(awth().value(), ' ');
Element::set_cursor(axpos(), j) << std::string(awth().value(), ' ');
}
std::cout << std::flush;
}
void Window::line_reset() const
@@ -46,7 +53,7 @@ std::ostream& Window::line_next() const
return null;
}
return set_cursor(axpos(), m_ypos++);
return Element::set_cursor(axpos(), m_ypos++);
}
void Window::line_empty() const