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 | dd1a7e97d6177f2229a16a9eba752efbf8507608 | 
| parent | 09e7edc5a481251f57e1038573da37d3503339b7 | 
| author | Dimitrije Dobrota < mail@dimitrijedobrota.com > | 
| date | Tue, 18 Feb 2025 04:38:13 +0100 | 
Cleanup types.hpp
* No distinction between absolute and non-absolute types
* Usage indicated through naming
* Clenup default constructors and default parameters
| M | CMakeLists.txt | | | + - | 
| M | example/example.cpp | | | +++ --- | 
| M | example/navig/navig.cpp | | | + - | 
| M | include/display/element.hpp | | | +++ --- | 
| M | include/display/layout.hpp | | | +++++ ----- | 
| M | include/display/layout_rigid.hpp | | | +++ --- | 
| M | include/display/types.hpp | | | +++++++++++++++++ ----------------------------------------- | 
| M | include/display/window.hpp | | | + - | 
| M | include/display/window_pivot.hpp | | | +++++ ----- | 
| M | source/display.cpp | | | ++ -- | 
10 files changed, 41 insertions(+), 65 deletions(-)
diff --git a/ CMakeLists.txt b/ CMakeLists.txt
          @@ -4,7 +4,7 @@ 
          include(cmake/prelude.cmake)
        
        
          project(
              display
              VERSION 0.1.28
              VERSION 0.1.29
              DESCRIPTION "TUI library"
              HOMEPAGE_URL "git://git.dimitrijedobrota.com/display.git"
              LANGUAGES CXX
        
        diff --git a/ example/example.cpp b/ example/example.cpp
          @@ -10,12 +10,12 @@ 
          namespace
        
        
          {
          using display::PvtX, display::PvtY;
          using display::sz_t, display::dim_t, display::piv_t, display::aplace_t;
          using display::sz_t, display::dim_t, display::piv_t, display::place_t;
          class WindowCustom : public display::WindowPivot
          {
          public:
            explicit WindowCustom(aplace_t aplc, piv_t piv, dim_t dim)
            explicit WindowCustom(place_t aplc, piv_t piv, dim_t dim)
                : WindowPivot(aplc, piv, dim)
            {
            }
        
        
          @@ -40,7 +40,7 @@ 
          public:
        
        
          class LayoutCustom : public display::LayoutRigid<display::Layout<WindowCustom>>
          {
          public:
            explicit LayoutCustom(display::aplace_t aplc)
            explicit LayoutCustom(display::place_t aplc)
                : LayoutRigid(aplc, {{0, 1, 2}, {7, 8, 3}, {6, 5, 4}})
            {
              append().set_child(piv_t(PvtX::Left, PvtY::Top), dim_t(12, 4));
        
        diff --git a/ example/navig/navig.cpp b/ example/navig/navig.cpp
          @@ -17,7 +17,7 @@ 
          bool is_finished = false;  // NOLINT
        
        
          class WindowCustom : public display::WindowPivot
          {
          public:
            WindowCustom(display::aplace_t aplc,
            WindowCustom(display::place_t aplc,
                         display::piv_t piv,
                         const example::menu_t& menu)
                : WindowPivot(aplc, piv, calc_dim(menu))
        
        diff --git a/ include/display/element.hpp b/ include/display/element.hpp
          @@ -7,7 +7,7 @@ 
          namespace display
        
        
          class Element
          {
          public:
            explicit Element(aplace_t aplc)
            explicit Element(place_t aplc)
                : m_aplc(aplc)
            {
            }
        
        
          @@ -20,7 +20,7 @@ 
          public:
        
        
            virtual ~Element() = default;
            virtual void resize(aplace_t aplc) { m_aplc = aplc; }
            virtual void resize(place_t aplc) { m_aplc = aplc; }
            virtual void render() const = 0;
            virtual void clear() const = 0;
            virtual void input(event& evnt) = 0;
        
        
          @@ -34,7 +34,7 @@ 
          public:
        
        
            const auto& ahgt() const { return adim().height; }
          private:
            aplace_t m_aplc;
            place_t m_aplc;
          };
          }  // namespace display
        
        diff --git a/ include/display/layout.hpp b/ include/display/layout.hpp
          @@ -16,12 +16,12 @@ 
          class Layout : public Element
        
        
          public:
            using ptr_t = std::unique_ptr<T>;
            explicit Layout(aplace_t aplc)
            explicit Layout(place_t aplc)
                : Element(aplc)
            {
            }
            void resize(aplace_t aplc) override
            void resize(place_t aplc) override
            {
              Element::resize(aplc);
          
          @@ -89,12 +89,12 @@ 
          class LayoutMulti : public Element
        
        
          public:
            using ptr_t = std::unique_ptr<T>;
            explicit LayoutMulti(aplace_t aplc)
            explicit LayoutMulti(place_t aplc)
                : Element(aplc)
            {
            }
            void resize(aplace_t aplc) override
            void resize(place_t aplc) override
            {
              Element::resize(aplc);
          
          @@ -150,7 +150,7 @@ 
          public:
        
        
            std::size_t size() { return m_children.size(); }
          private:
            virtual aplace_t place(std::size_t /* unused */) const { return aplc(); }
            virtual place_t place(std::size_t /* unused */) const { return aplc(); }
            std::vector<ptr_t> m_children;
          };
        
        diff --git a/ include/display/layout_rigid.hpp b/ include/display/layout_rigid.hpp
          @@ -16,12 +16,12 @@ 
          class LayoutRigid : public LayoutMulti<T>
        
        
          public:
            using layout_t = std::vector<std::vector<std::uint8_t>>;
            LayoutRigid(aplace_t aplc, layout_t layout);  // NOLINT
            LayoutRigid(place_t aplc, layout_t layout);  // NOLINT
          private:
            std::size_t count_and_pad(layout_t& layout) const;
            aplace_t place(std::size_t idx) const override
            place_t place(std::size_t idx) const override
            {
              const auto [m, n] = m_grid;
              const auto [w, h] = this->adim();
        
        
          @@ -56,7 +56,7 @@ 
          private:
        
        
          };
          template<typename T>
          LayoutRigid<T>::LayoutRigid(aplace_t aplc, layout_t layout)
          LayoutRigid<T>::LayoutRigid(place_t aplc, layout_t layout)
              : LayoutMulti<T>(aplc)
              , m_grid(static_cast<sz_t>(layout[0].size()),
                       static_cast<sz_t>(layout.size()))
        
        diff --git a/ include/display/types.hpp b/ include/display/types.hpp
          @@ -14,7 +14,12 @@ 
          using sz_t = std::uint16_t;
        
        
          struct dim_t
          {
            dim_t(sz_t wdth = 0, sz_t hght = 0)  // NOLINT
            dim_t()
                : dim_t(0, 0)
            {
            }
            dim_t(sz_t wdth, sz_t hght)  // NOLINT
                : width(wdth)
                , height(hght)
            {
        
        
          @@ -32,7 +37,12 @@ 
          struct dim_t
        
        
          struct pos_t
          {
            pos_t(sz_t xpos = 0, sz_t ypos = 0)  // NOLINT
            pos_t()
                : pos_t(0, 0)
            {
            }
            pos_t(sz_t xpos, sz_t ypos)
                : x(xpos)
                , y(ypos)
            {
        
        
          @@ -48,59 +58,25 @@ 
          struct pos_t
        
        
            dim_t operator-(pos_t rhs) const
            {
              return {static_cast<sz_t>(x - rhs.x), static_cast<sz_t>(y - rhs.y)};
            }
            sz_t x;
            sz_t y;
          };
          struct apos_t
          {
            apos_t(sz_t xpos, sz_t ypos)
                : x(xpos)
                , y(ypos)
            {
            }
            apos_t operator+(pos_t rhs) const
            {
              return {
                  static_cast<sz_t>(x + rhs.x),
                  static_cast<sz_t>(y + rhs.y),
                  static_cast<sz_t>(x - rhs.x),
                  static_cast<sz_t>(y - rhs.y),
              };
            }
            dim_t operator-(apos_t rhs) const
            {
              return {static_cast<sz_t>(rhs.x - x), static_cast<sz_t>(rhs.y - y)};
            }
            sz_t x;
            sz_t y;
          };
          struct place_t
          {
            place_t(pos_t posval, dim_t dimval)
                : pos(posval)
                , dim(dimval)
            {
            }
            pos_t pos;
            dim_t dim;
          };
          struct aplace_t
          {
            aplace_t(apos_t aposval, dim_t adimval)
            place_t(pos_t aposval, dim_t adimval)
                : apos(aposval)
                , adim(adimval)
            {
            }
            apos_t apos;
            pos_t apos;
            dim_t adim;
          };
          
          @@ -120,7 +96,7 @@ 
          enum class PvtY : std::uint8_t
        
        
          struct piv_t
          {
            piv_t(PvtX pvtx = PvtX::Left, PvtY pvty = PvtY::Top)  // NOLINT
            piv_t(PvtX pvtx, PvtY pvty)
                : x(pvtx)
                , y(pvty)
            {
        
        diff --git a/ include/display/window.hpp b/ include/display/window.hpp
          @@ -9,7 +9,7 @@ 
          namespace display
        
        
          class Window : public Element
          {
          public:
            explicit Window(aplace_t aplc)
            explicit Window(place_t aplc)
                : Element(aplc)
            {
            }
        
        diff --git a/ include/display/window_pivot.hpp b/ include/display/window_pivot.hpp
          @@ -9,20 +9,20 @@ 
          namespace display
        
        
          class WindowPivot : public Window
          {
          public:
            WindowPivot(aplace_t aplc, piv_t piv, dim_t dim)
            WindowPivot(place_t aplc, piv_t piv, dim_t dim)
                : Window(place(aplc, piv, dim))
                , m_piv(piv)
                , m_dim(dim)
            {
            }
            void resize(aplace_t aplc) override
            void resize(place_t aplc) override
            {
              Window::resize(place(aplc, m_piv, m_dim));
            }
          protected:
            static aplace_t place(aplace_t aplc, piv_t piv, dim_t dim)
            static place_t place(place_t aplc, piv_t piv, dim_t dim)
            {
              const auto [cols, rows] = aplc.adim;
              const sz_t colsh = cols / 2;
        
        
          @@ -34,8 +34,8 @@ 
          protected:
        
        
              const sz_t zero = 0;
              display::pos_t start;
              display::pos_t end;
              pos_t start;
              pos_t end;
              using display::add_lim, display::sub_lim;
          diff --git a/ source/display.cpp b/ source/display.cpp
          @@ -28,7 +28,7 @@ 
          Display& Display::display()
        
        
          }
          Display::Display()
              : m_layout(aplace_t(apos_t(0, 0), alec::get_screen_size()))
              : m_layout(place_t(pos_t(0, 0), alec::get_screen_size()))
          {
            struct sigaction old_sig_action = {};
            sigaction(SIGWINCH, nullptr, &old_sig_action);
        
        
          @@ -90,7 +90,7 @@ 
          bool Display::get_resized() const
        
        
          void Display::resize()
          {
            m_layout.resize(aplace_t(apos_t(0, 0), alec::get_screen_size()));
            m_layout.resize(place_t(pos_t(0, 0), alec::get_screen_size()));
          }
          void Display::render() const