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 | 5871d5fe619a5656ed5e765d1d0cc6be13643db2 | 
| parent | 611e9210048044f9f9369fbafeb4d284fdae5fff | 
| author | Dimitrije Dobrota < mail@dimitrijedobrota.com > | 
| date | Wed, 19 Feb 2025 12:32:26 +0100 | 
Move render_border and set_cursor to Element
* Add std::flush-es
| M | CMakeLists.txt | | | ++ - | 
| M | example/example.cpp | | | ++++++++ -- | 
| M | include/display/element.hpp | | | +++ | 
| M | include/display/layout.hpp | | | ++++ --- | 
| M | include/display/window.hpp | | | --- | 
| A | source/element.cpp | | | ++++++++++++++++++++++++++++++++++++++ | 
| M | source/window.cpp | | | + --------------------------- | 
7 files changed, 56 insertions(+), 36 deletions(-)
diff --git a/ CMakeLists.txt b/ CMakeLists.txt
          @@ -4,7 +4,7 @@ 
          include(cmake/prelude.cmake)
        
        
          project(
              display
              VERSION 0.1.33
              VERSION 0.1.34
              DESCRIPTION "TUI library"
              HOMEPAGE_URL "git://git.dimitrijedobrota.com/display.git"
              LANGUAGES CXX
        
        
          @@ -20,6 +20,7 @@ 
          find_package(alec 0.1.13 CONFIG REQUIRED)
        
        
          add_library(
              display_display
              source/display.cpp
              source/element.cpp
              source/window.cpp
              source/window_pivot.cpp
          )
        
        diff --git a/ example/example.cpp b/ example/example.cpp
          @@ -53,6 +53,12 @@ 
          public:
        
        
              append().set_child(piv_t(PvtX::Left, PvtY::Center), dim_t(12, 4));
              append().set_child(piv_t(PvtX::Center, PvtY::Center), dim_t(12, 4));
            }
            void render() const override
            {
              display::LayoutRigid<display::Layout<WindowCustom>>::render();
              display::Element::render_border();
            }
          };
          }  // namespace
        
        
          @@ -67,8 +73,8 @@ 
          int main()
        
        
              // clang-format off
              const LayoutRigid<>::layout_t split = {
                  {1, 1, 2},
                  {0, 3, 2},
                  {4, 3, 2},
                  {0, 4, 2},
                  {3, 4, 2},
              };
              // clang-format on
          diff --git a/ include/display/element.hpp b/ include/display/element.hpp
          @@ -25,6 +25,9 @@ 
          public:
        
        
            virtual void clear() const = 0;
            virtual void input(event& evnt) = 0;
            static std::ostream& set_cursor(sz_t posy, sz_t posx);
            void render_border() const;
            const auto& aplc() const { return m_aplc; }
            const auto& apos() const { return aplc().pos; }
            const auto& adim() const { return aplc().dim; }
        
        diff --git a/ include/display/layout.hpp b/ include/display/layout.hpp
          @@ -55,9 +55,7 @@ 
          public:
        
        
              requires(std::is_base_of_v<T, M>)
            M& set_child(Args&&... args)
            {
              if (has_child()) {
                m_child->clear();
              }
              clear();
              m_child = std::make_unique<M>(aplc(), std::forward<Args>(args)...);
              return get_child<M>();
            }
        
        
          @@ -121,6 +119,9 @@ 
          public:
        
        
            {
              for (auto& child : m_children) {
                child->input(evnt);
                if (evnt.type() == event::Type::NONE) {
                  break;
                }
              }
            }
          diff --git a/ include/display/window.hpp b/ include/display/window.hpp
          @@ -18,12 +18,9 @@ 
          public:
        
        
            void clear() const override;
            void input(event& /* unused */) override {}
            void render_border() const;
          protected:
            padd_t padd() const { return m_padd; }
            static std::ostream& set_cursor(sz_t posy, sz_t posx);
            std::ostream& line_next() const;
            void line_reset() const;
        
        diff --git a/ source/element.cpp b/ source/element.cpp
@@ -0,0 +1,38 @@
#include <iostream>
          #include "display/element.hpp"
          namespace display
          {
          std::ostream& Element::set_cursor(sz_t posy, sz_t posx)
          {
            return std::cout << alec::cursor_position(posy + 1, posx + 1);
          }
          void Element::render_border() const
          {
            set_cursor(aypos(), axpos());
            std::cout << "┌";
            for (sz_t i = 2; i < awth(); i++) {
              std::cout << "─";
            }
            std::cout << "┐";
            for (sz_t i = aypos() + 1; i < aypos() + ahgt(); i++) {
              set_cursor(i, axpos()) << "│";
              set_cursor(i, axpos() + awth() - 1) << "│";
            }
            set_cursor(aypos() + ahgt() - 1, axpos());
            std::cout << "└";
            for (sz_t i = 2; i < awth(); i++) {
              std::cout << "─";
            }
            std::cout << "┘";
            std::cout << std::flush;
          }
          }  // namespace display
        
        diff --git a/ source/window.cpp b/ source/window.cpp
          @@ -18,28 +18,7 @@ 
          void Window::render() const
        
        
            for (sz_t i = m_ypos; i < aypos() + ahgt(); i++) {
              set_cursor(i, axpos()) << space;
            }
          }
          void Window::render_border() const
          {
            set_cursor(aypos(), axpos());
            std::cout << "┌";
            for (sz_t i = 2; i < awth(); i++) {
              std::cout << "─";
            }
            std::cout << "┐";
            for (sz_t i = aypos() + 1; i < aypos() + ahgt(); i++) {
              set_cursor(i, axpos()) << "│";
              set_cursor(i, axpos() + awth() - 1) << "│";
            }
            set_cursor(aypos() + ahgt() - 1, axpos());
            std::cout << "└";
            for (sz_t i = 2; i < awth(); i++) {
              std::cout << "─";
            }
            std::cout << "┘";
            std::cout << std::flush;
          }
          void Window::clear() const
        
        
          @@ -59,11 +38,6 @@ 
          void Window::line_reset() const
        
        
            m_ypos = ypos();
          }
          std::ostream& Window::set_cursor(sz_t posy, sz_t posx)
          {
            return std::cout << alec::cursor_position(posy + 1, posx + 1);
          }
          std::ostream& Window::line_next() const
          {
            if (m_ypos == ypos() + hgt()) {