mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2024-12-11 21:56:10 +08:00
Allow a Dimension::Fit to extend beyond the terminal maximum height (#950)
Some checks failed
Build / Tests (gcc, gcov, Linux GCC, ubuntu-latest) (push) Failing after 41s
Build / documentation (push) Failing after 42s
Build / Tests (llvm, llvm-cov gcov, Linux Clang, ubuntu-latest) (push) Failing after 2m3s
Build / Tests (cl, Windows MSVC, windows-latest) (push) Has been cancelled
Build / Create release (push) Has been cancelled
Build / Build packages (build/ftxui*Darwin*, macos-latest) (push) Has been cancelled
Build / Build packages (build/ftxui*Linux*, ubuntu-latest) (push) Has been cancelled
Build / Build packages (build/ftxui*Win64*, windows-latest) (push) Has been cancelled
CodeQL / Analyze (cpp) (push) Failing after 1m34s
Some checks failed
Build / Tests (gcc, gcov, Linux GCC, ubuntu-latest) (push) Failing after 41s
Build / documentation (push) Failing after 42s
Build / Tests (llvm, llvm-cov gcov, Linux Clang, ubuntu-latest) (push) Failing after 2m3s
Build / Tests (cl, Windows MSVC, windows-latest) (push) Has been cancelled
Build / Create release (push) Has been cancelled
Build / Build packages (build/ftxui*Darwin*, macos-latest) (push) Has been cancelled
Build / Build packages (build/ftxui*Linux*, ubuntu-latest) (push) Has been cancelled
Build / Build packages (build/ftxui*Win64*, windows-latest) (push) Has been cancelled
CodeQL / Analyze (cpp) (push) Failing after 1m34s
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:
parent
55af678fb9
commit
70bc44d28b
@ -46,6 +46,9 @@ current (development)
|
|||||||
- Feature: Add `hscroll_indicator`. It display an horizontal indicator
|
- Feature: Add `hscroll_indicator`. It display an horizontal indicator
|
||||||
reflecting the current scroll position. Proposed by @ibrahimnasson in
|
reflecting the current scroll position. Proposed by @ibrahimnasson in
|
||||||
[issue 752](https://github.com/ArthurSonzogni/FTXUI/issues/752)
|
[issue 752](https://github.com/ArthurSonzogni/FTXUI/issues/752)
|
||||||
|
- Feature: Add `extend_beyond_screen` option to `Dimension::Fit(..)`, allowing
|
||||||
|
the element to be larger than the screen. Proposed by @LordWhiro. See #572 and
|
||||||
|
#949.
|
||||||
|
|
||||||
### Screen
|
### Screen
|
||||||
- Feature: Add `Box::IsEmpty()`.
|
- Feature: Add `Box::IsEmpty()`.
|
||||||
|
@ -55,7 +55,8 @@ int main() {
|
|||||||
content.DecorateCellsAlternateRow(color(Color::White), 3, 2);
|
content.DecorateCellsAlternateRow(color(Color::White), 3, 2);
|
||||||
|
|
||||||
auto document = table.Render();
|
auto document = table.Render();
|
||||||
auto screen = Screen::Create(Dimension::Fit(document));
|
auto screen =
|
||||||
|
Screen::Create(Dimension::Fit(document, /*extend_beyond_screen=*/true));
|
||||||
Render(screen, document);
|
Render(screen, document);
|
||||||
screen.Print();
|
screen.Print();
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
|
@ -183,7 +183,7 @@ Element align_right(Element);
|
|||||||
Element nothing(Element element);
|
Element nothing(Element element);
|
||||||
|
|
||||||
namespace Dimension {
|
namespace Dimension {
|
||||||
Dimensions Fit(Element&);
|
Dimensions Fit(Element&, bool extend_beyond_screen = false);
|
||||||
} // namespace Dimension
|
} // namespace Dimension
|
||||||
|
|
||||||
} // namespace ftxui
|
} // namespace ftxui
|
||||||
|
@ -90,7 +90,7 @@ Element& operator|=(Element& e, Decorator d) {
|
|||||||
/// The minimal dimension that will fit the given element.
|
/// The minimal dimension that will fit the given element.
|
||||||
/// @see Fixed
|
/// @see Fixed
|
||||||
/// @see Full
|
/// @see Full
|
||||||
Dimensions Dimension::Fit(Element& e) {
|
Dimensions Dimension::Fit(Element& e, bool extend_beyond_screen) {
|
||||||
const Dimensions fullsize = Dimension::Full();
|
const Dimensions fullsize = Dimension::Full();
|
||||||
Box box;
|
Box box;
|
||||||
box.x_min = 0;
|
box.x_min = 0;
|
||||||
@ -106,7 +106,10 @@ Dimensions Dimension::Fit(Element& e) {
|
|||||||
|
|
||||||
// Don't give the element more space than it needs:
|
// Don't give the element more space than it needs:
|
||||||
box.x_max = std::min(box.x_max, e->requirement().min_x);
|
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);
|
e->SetBox(box);
|
||||||
status.need_iteration = false;
|
status.need_iteration = false;
|
||||||
@ -116,10 +119,14 @@ Dimensions Dimension::Fit(Element& e) {
|
|||||||
if (!status.need_iteration) {
|
if (!status.need_iteration) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// Increase the size of the box until it fits, but not more than the with of
|
// Increase the size of the box until it fits...
|
||||||
// the terminal emulator:
|
|
||||||
box.x_max = std::min(e->requirement().min_x, fullsize.dimx);
|
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 {
|
return {
|
||||||
|
Loading…
Reference in New Issue
Block a user