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 | ed9c35afa50572c55d4bd8765a3c90c5018faed0 | 
| parent | 6d854e1e253d3d9237b09ab513d6d03061a54526 | 
| author | Dimitrije Dobrota < mail@dimitrijedobrota.com > | 
| date | Fri, 7 Feb 2025 11:10:01 +0100 | 
Index sort to allow inorder access
| M | CMakeLists.txt | | | + - | 
| M | example/example.cpp | | | ++++ ---- | 
| M | include/display/layout.hpp | | | ++++ - | 
| M | source/layout.cpp | | | +++++++++++++++ ------- | 
4 files changed, 24 insertions(+), 13 deletions(-)
diff --git a/ CMakeLists.txt b/ CMakeLists.txt
          @@ -4,7 +4,7 @@ 
          include(cmake/prelude.cmake)
        
        
          project(
              display
              VERSION 0.1.3
              VERSION 0.1.4
              DESCRIPTION "TUI library"
              HOMEPAGE_URL "https://example.com/"
              LANGUAGES CXX
        
        diff --git a/ example/example.cpp b/ example/example.cpp
          @@ -30,10 +30,10 @@ 
          int main()
        
        
            display::start();
            display::LayoutFree layout;
            layout.add_window({{3, 3}, {15, 15}});
            layout.add_window({{0, 0}, {10, 10}}, 1);
            layout.add_window({{5, 5}, {5, 10}}, 1);
            layout.add_window({{15, 15}, {5, 10}}, 1);
            layout.append({{3, 3}, {15, 15}});
            layout.append({{0, 0}, {10, 10}}, 1);
            layout.append({{5, 5}, {5, 10}}, 1);
            layout.append({{15, 15}, {5, 10}}, 1);
            layout.render(renderer);
            while (true) {
        
        diff --git a/ include/display/layout.hpp b/ include/display/layout.hpp
          @@ -46,7 +46,10 @@ 
          class LayoutFree
        
        
          public:
            using render_f = int(Window&);
            void add_window(Window window, int zidx = -1);
            auto operator[](std::size_t idx) const { return std::get<1>(m_windows[idx]); }
            auto operator[](std::size_t idx) { return std::get<1>(m_windows[idx]); }
            void append(Window window, int zidx = -1);
            int render(render_f renderer);
          diff --git a/ source/layout.cpp b/ source/layout.cpp
@@ -1,11 +1,12 @@
#include <algorithm>
          #include <numeric>
          #include "display/layout.hpp"
          namespace display
          {
          void LayoutFree::add_window(Window window, int zidx)
          void LayoutFree::append(Window window, int zidx)
          {
            m_windows.emplace_back(zidx, std::move(window));
            m_is_sorted = false;
        
        
          @@ -13,16 +14,23 @@ 
          void LayoutFree::add_window(Window window, int zidx)
        
        
          int LayoutFree::render(render_f renderer)
          {
            static std::vector<std::uint8_t> idxs;
            if (!m_is_sorted) {
              std::stable_sort(m_windows.begin(),  // NOLINT
                               m_windows.end(),
                               [](auto& fst, auto& sec)
                               { return std::get<0>(fst) < std::get<0>(sec); });
              idxs.resize(m_windows.size());
              std::iota(idxs.begin(), idxs.end(), 0);
              std::stable_sort(idxs.begin(),  // NOLINT
                               idxs.end(),
                               [&](auto left, auto right)
                               {
                                 return std::get<0>(m_windows[left])
                                     < std::get<0>(m_windows[right]);
                               });
              m_is_sorted = true;
            }
            for (auto& [_, window] : m_windows) {
              const auto res = renderer(window);
            for (const auto idx : idxs) {
              const auto res = renderer(std::get<1>(m_windows[idx]));
              if (res != 0) {
                return res;
              }