Allow a Dimension::Fit to extend beyond the terminal maximum height (#950)

For long tables (and other DOM elements), one may want the screen to render on dimensions higher than the terminal.  
Hence, this PR proposes a way to do so, with an optional parameter in the `Dimension::Fit` util function.

Discussions / Issues :  
- https://github.com/ArthurSonzogni/FTXUI/issues/572
- https://github.com/ArthurSonzogni/FTXUI/discussions/949

Bug:https://github.com/ArthurSonzogni/FTXUI/issues/572
Fixed:Bug:https://github.com/ArthurSonzogni/FTXUI/issues/572
Co-authored-by: ArthurSonzogni <sonzogniarthur@gmail.com>
This commit is contained in:
Boris Jaulmes
2024-11-07 21:07:09 +01:00
committed by GitHub
parent 55af678fb9
commit 70bc44d28b
4 changed files with 18 additions and 7 deletions

View File

@@ -90,7 +90,7 @@ Element& operator|=(Element& e, Decorator d) {
/// The minimal dimension that will fit the given element.
/// @see Fixed
/// @see Full
Dimensions Dimension::Fit(Element& e) {
Dimensions Dimension::Fit(Element& e, bool extend_beyond_screen) {
const Dimensions fullsize = Dimension::Full();
Box box;
box.x_min = 0;
@@ -106,7 +106,10 @@ Dimensions Dimension::Fit(Element& e) {
// Don't give the element more space than it needs:
box.x_max = std::min(box.x_max, e->requirement().min_x);
box.y_max = std::min(box.y_max, e->requirement().min_y);
box.y_max = e->requirement().min_y;
if (!extend_beyond_screen) {
box.y_max = std::min(box.y_max, fullsize.dimy);
}
e->SetBox(box);
status.need_iteration = false;
@@ -116,10 +119,14 @@ Dimensions Dimension::Fit(Element& e) {
if (!status.need_iteration) {
break;
}
// Increase the size of the box until it fits, but not more than the with of
// the terminal emulator:
// Increase the size of the box until it fits...
box.x_max = std::min(e->requirement().min_x, fullsize.dimx);
box.y_max = std::min(e->requirement().min_y, fullsize.dimy);
box.y_max = e->requirement().min_y;
// ... but don't go beyond the screen size:
if (!extend_beyond_screen) {
box.y_max = std::min(box.y_max, fullsize.dimy);
}
}
return {