From df2ddcc5889bd47b75be7c827436d4643667904b Mon Sep 17 00:00:00 2001 From: Ken Reneris Date: Sat, 28 Jun 2025 08:51:41 -0700 Subject: [PATCH 1/2] Add gridbox children to children_ so that layout will see need_iteration when a flex node is in the grid --- src/ftxui/dom/gridbox.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/ftxui/dom/gridbox.cpp b/src/ftxui/dom/gridbox.cpp index 38b30b5f..db06c0fe 100644 --- a/src/ftxui/dom/gridbox.cpp +++ b/src/ftxui/dom/gridbox.cpp @@ -46,6 +46,12 @@ class GridBox : public Node { line.push_back(filler()); } } + + for (const auto& line : lines_) { + for (const auto &element : line) { + children_.push_back( element ); + } + } } void ComputeRequirement() override { From 2d5026973010102deabdcc8a9902e0bbc09aee85 Mon Sep 17 00:00:00 2001 From: Ken Reneris Date: Sat, 28 Jun 2025 09:15:37 -0700 Subject: [PATCH 2/2] private changes. don't shrink table content --- src/ftxui/dom/box_helper.cpp | 40 +++++++++++++++++++++++++++++++++--- src/ftxui/dom/box_helper.hpp | 2 +- src/ftxui/dom/gridbox.cpp | 2 +- src/ftxui/dom/table.cpp | 4 ++-- 4 files changed, 41 insertions(+), 7 deletions(-) diff --git a/src/ftxui/dom/box_helper.cpp b/src/ftxui/dom/box_helper.cpp index 8284cf30..4c73df7d 100644 --- a/src/ftxui/dom/box_helper.cpp +++ b/src/ftxui/dom/box_helper.cpp @@ -58,11 +58,39 @@ void ComputeShrinkHard(std::vector* elements, element.size = element.min_size + added_space; } + +} + + +// Called when the size allowed is lower than the requested size, and the +// shrinkable element can not absorbe the (negative) extra_space. This assign +// zero to shrinkable elements and distribute the remaining (negative) +// extra_space toward the other non shrinkable elements. +void ComputeShrinkHardHack(std::vector* elements, + int extra_space, + int size) +{ + for (Element& element : *elements) + { + if (element.flex_shrink != 0) + { + element.size = 0; + } + } + + for (auto it = elements->rbegin(); it != elements->rend(); ++it) + { + Element& element = *it; + + auto remove = std::min(element.min_size, -extra_space); + element.size = element.min_size - remove; + extra_space += remove; + } } } // namespace -void Compute(std::vector* elements, int target_size) { +void Compute(std::vector* elements, int target_size, bool hack) { int size = 0; int flex_grow_sum = 0; int flex_shrink_sum = 0; @@ -84,8 +112,14 @@ void Compute(std::vector* elements, int target_size) { ComputeShrinkEasy(elements, extra_space, flex_shrink_sum); } else { - ComputeShrinkHard(elements, extra_space + flex_shrink_size, - size - flex_shrink_size); + if (hack) + { + ComputeShrinkHardHack(elements, extra_space + flex_shrink_size, size - flex_shrink_size); + } + else + { + ComputeShrinkHard(elements, extra_space + flex_shrink_size, size - flex_shrink_size); + } } } diff --git a/src/ftxui/dom/box_helper.hpp b/src/ftxui/dom/box_helper.hpp index e7782dfa..381c937b 100644 --- a/src/ftxui/dom/box_helper.hpp +++ b/src/ftxui/dom/box_helper.hpp @@ -19,7 +19,7 @@ struct Element { int size = 0; }; -void Compute(std::vector* elements, int target_size); +void Compute(std::vector* elements, int target_size, bool hack=false); } // namespace ftxui::box_helper #endif /* end of include guard: FTXUI_DOM_BOX_HELPER_HPP */ diff --git a/src/ftxui/dom/gridbox.cpp b/src/ftxui/dom/gridbox.cpp index db06c0fe..5051df4c 100644 --- a/src/ftxui/dom/gridbox.cpp +++ b/src/ftxui/dom/gridbox.cpp @@ -115,7 +115,7 @@ class GridBox : public Node { const int target_size_x = box.x_max - box.x_min + 1; const int target_size_y = box.y_max - box.y_min + 1; - box_helper::Compute(&elements_x, target_size_x); + box_helper::Compute(&elements_x, target_size_x, true); box_helper::Compute(&elements_y, target_size_y); Box box_y = box; diff --git a/src/ftxui/dom/table.cpp b/src/ftxui/dom/table.cpp index 7076a3ab..f7b5333d 100644 --- a/src/ftxui/dom/table.cpp +++ b/src/ftxui/dom/table.cpp @@ -216,13 +216,13 @@ Element Table::Render() { // Line if ((x + y) % 2 == 1) { - it = std::move(it) | flex; + it = std::move(it)| flex; //it = std::move(it); // | flex; continue; } // Cells if ((x % 2) == 1 && (y % 2) == 1) { - it = std::move(it) | flex_shrink; + // it = std::move(it) | flex_shrink; //it = std::move(it) | flex_shrink; continue; }