Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 37 additions & 3 deletions src/ftxui/dom/box_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,39 @@

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)

Check failure on line 71 in src/ftxui/dom/box_helper.cpp

View workflow job for this annotation

GitHub Actions / CMake, llvm, macos-latest

unused parameter 'size' [-Werror,-Wunused-parameter]

Check failure on line 71 in src/ftxui/dom/box_helper.cpp

View workflow job for this annotation

GitHub Actions / CMake, gcc, ubuntu-latest

unused parameter ‘size’ [-Werror=unused-parameter]

Check failure on line 71 in src/ftxui/dom/box_helper.cpp

View workflow job for this annotation

GitHub Actions / CMake, llvm, ubuntu-latest

unused parameter 'size' [-Werror,-Wunused-parameter]

Check failure on line 71 in src/ftxui/dom/box_helper.cpp

View workflow job for this annotation

GitHub Actions / Test modules (ubuntu-latest, llvm)

unused parameter 'size' [-Werror,-Wunused-parameter]
{
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<Element>* elements, int target_size) {
void Compute(std::vector<Element>* elements, int target_size, bool hack) {
int size = 0;
int flex_grow_sum = 0;
int flex_shrink_sum = 0;
Expand All @@ -84,8 +112,14 @@
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);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/ftxui/dom/box_helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ struct Element {
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

#endif /* end of include guard: FTXUI_DOM_BOX_HELPER_HPP */
8 changes: 7 additions & 1 deletion src/ftxui/dom/gridbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -109,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;
Expand Down
4 changes: 2 additions & 2 deletions src/ftxui/dom/table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Loading