Replies: 5 comments 6 replies
-
|
Hello @blex-max
Thank you very much! That's greatly appreciated!
There are no builtin solution at the moment ;-( I guess we could add a min/max option in int main_size = 20;
auto foreground = ...;
auto background = ...;
int size = auto split = ResizableSplit({
.main = foreground.
.back = background,
.direction = Direction::Left,
.main_size = &main_size,
.min = 10,
.max = 20,
})This could be added if we believe this would be valuable. Alternatively, one can clamp the size value after handling events, but before rendering the component. // Copyright 2020 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in
// the LICENSE file.
#include <memory> // for shared_ptr, allocator, __shared_ptr_access
#include "ftxui/component/captured_mouse.hpp" // for ftxui
#include "ftxui/component/component.hpp" // for Renderer, ResizableSplitBottom, ResizableSplitLeft, ResizableSplitRight, ResizableSplitTop
#include "ftxui/component/component_base.hpp" // for ComponentBase
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
#include "ftxui/dom/elements.hpp" // for Element, operator|, text, center, border
using namespace ftxui;
std::function<Component(Component)> ClampSize(int* size, int min, int max) {
return [=](Component component) {
return Renderer(component, [=] {
*size = std::max(min, std::min(max, *size));
return component->Render();
});
};
}
int main() {
auto screen = ScreenInteractive::Fullscreen();
auto middle = Renderer([] { return text("middle") | center; });
auto left = Renderer([] { return text("Left") | center; });
auto right = Renderer([] { return text("right") | center; });
auto top = Renderer([] { return text("top") | center; });
auto bottom = Renderer([] { return text("bottom") | center; });
int left_size = 20;
int right_size = 20;
int top_size = 10;
int bottom_size = 10;
auto container = middle;
container = ResizableSplitLeft(left, container, &left_size);
container = ResizableSplitRight(right, container, &right_size);
container = ResizableSplitTop(top, container, &top_size);
container = ResizableSplitBottom(bottom, container, &bottom_size);
// Clamp the sizes.
container |= ClampSize(&left_size, 3, 20);
container |= ClampSize(&right_size, 3, 20);
container |= ClampSize(&top_size, 1, 10);
container |= ClampSize(&bottom_size, 1, 10);
auto renderer =
Renderer(container, [&] { return container->Render() | border; });
screen.Loop(renderer);
}The decorator |
Beta Was this translation helpful? Give feedback.
-
|
Yes this sounds like a good idea. Let's try asking AI to implement this ;-) |
Beta Was this translation helpful? Give feedback.
-
|
For anyone who comes across this, at present I'm using: std::function<Component(Component)> ClampSize(int* size, int min, int max) {
return [=](Component component) {
return Renderer(component, [=] {
*size = std::clamp(*size, min, max);
return component->Render();
});
};
} // from Arthur
std::function<Component(Component)> FixDimension(ftxui::WidthOrHeight dim, ftxui::Constraint constraint, int val) {
return [=](Component component) {
return Renderer(component, [=] {
return component->Render() | size(dim, constraint, val);
});
};
} // because decorating directly with size doesn't rerender every frame
// ...
Component browser_bottom_row =
ResizableSplitRight(gen_info, r_info, &ncol_gen_info) | FixDimension(HEIGHT, GREATER_THAN, nrow_r_info);
Component browser_row_split =
ResizableSplitTop(browser_top_row, browser_bottom_row, &nrow_ss) | ClampSize(&nrow_s, 5, 30);
Component browser_pane =
Renderer(browser_row_split, [&]() {
return browser_row_split->Render() | flex;
});And it's working fine. |
Beta Was this translation helpful? Give feedback.
-
|
@blex-max , I merged adding support for |
Beta Was this translation helpful? Give feedback.
-
|
I'm happy to say that this is working fine for me using 252ce67 - I did notice when playing with that I can induce odd behaviour if main_size begins outside the clamped ranged, but that's not a problem in proper use. Thanks so much for implementing this :) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, thanks so much for ftxui. I recently discovered it and it's great. I can do in minutes what would take me a week in ncurses. As of today I've set up a small sponsorship for the project :).
A small question I can't figure out from the doc, and I can't find it in the search either. I have the following code
What is the appropiate way to ensure that the bottom row is never less than a minimum size?
Many thanks,
Alex
Beta Was this translation helpful? Give feedback.
All reactions