private changes. don't shrink table content

This commit is contained in:
Ken Reneris
2025-06-28 09:15:37 -07:00
parent df2ddcc588
commit 2d50269730
4 changed files with 41 additions and 7 deletions

View File

@@ -58,11 +58,39 @@ void ComputeShrinkHard(std::vector<Element>* elements,
element.size = element.min_size + added_space; 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<Element>* 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 } // namespace
void Compute(std::vector<Element>* elements, int target_size) { void Compute(std::vector<Element>* elements, int target_size, bool hack) {
int size = 0; int size = 0;
int flex_grow_sum = 0; int flex_grow_sum = 0;
int flex_shrink_sum = 0; int flex_shrink_sum = 0;
@@ -84,8 +112,14 @@ void Compute(std::vector<Element>* elements, int target_size) {
ComputeShrinkEasy(elements, extra_space, flex_shrink_sum); ComputeShrinkEasy(elements, extra_space, flex_shrink_sum);
} else { } else {
ComputeShrinkHard(elements, extra_space + flex_shrink_size, if (hack)
size - flex_shrink_size); {
ComputeShrinkHardHack(elements, extra_space + flex_shrink_size, size - flex_shrink_size);
}
else
{
ComputeShrinkHard(elements, extra_space + flex_shrink_size, size - flex_shrink_size);
}
} }
} }

View File

@@ -19,7 +19,7 @@ struct Element {
int size = 0; int size = 0;
}; };
void Compute(std::vector<Element>* elements, int target_size); void Compute(std::vector<Element>* elements, int target_size, bool hack=false);
} // namespace ftxui::box_helper } // namespace ftxui::box_helper
#endif /* end of include guard: FTXUI_DOM_BOX_HELPER_HPP */ #endif /* end of include guard: FTXUI_DOM_BOX_HELPER_HPP */

View File

@@ -115,7 +115,7 @@ class GridBox : public Node {
const int target_size_x = box.x_max - box.x_min + 1; const int target_size_x = box.x_max - box.x_min + 1;
const int target_size_y = box.y_max - box.y_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_helper::Compute(&elements_y, target_size_y);
Box box_y = box; Box box_y = box;

View File

@@ -216,13 +216,13 @@ Element Table::Render() {
// Line // Line
if ((x + y) % 2 == 1) { if ((x + y) % 2 == 1) {
it = std::move(it) | flex; it = std::move(it)| flex; //it = std::move(it); // | flex;
continue; continue;
} }
// Cells // Cells
if ((x % 2) == 1 && (y % 2) == 1) { 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; continue;
} }