Open rbrugo opened 9 months ago
I see you are rendering:
flexbox(
[...],
hbox([...])
)
The hbox is displayed as a whole inside the flexbox. So when it doesn't fit the current line, the whole hbox is moved to the next line.
It seems to me you would like to unpack the elements from the hbox and happened them to the flexbox.
What about using this:
https://github.com/ArthurSonzogni/FTXUI/assets/4759106/22741ede-e42f-469a-93d5-1f0275ab81ed
#include <memory> // for shared_ptr, __shared_ptr_access
#include <string> // for operator+, to_string
#include <ftxui/component/component.hpp>
#include <ftxui/component/screen_interactive.hpp>
#include "ftxui/component/captured_mouse.hpp" // for ftxui
#include "ftxui/component/component.hpp" // for Button, Horizontal, Renderer
#include "ftxui/component/component_base.hpp" // for ComponentBase
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
#include "ftxui/dom/elements.hpp" // for separator, gauge, text, Element, operator|, vbox, border
using namespace ftxui;
int main() {
auto const words = std::vector<std::string>{
"one", "two", "three", "four", "five",
"six", "seven", "eight", "nine", "ten",
};
auto const sz = static_cast<int>(words.size());
auto value = 0;
auto btn1 = Button("-1", [&value] { value = std::max(value - 1, 0); });
auto btn2 = Button("+1", [&value, sz] { value = std::min(value + 1, sz); });
auto layout = Container::Vertical({
btn1,
btn2,
});
auto renderer = Renderer(layout, [&] {
Elements elements = {
text("Some"), text("text"), text("some"), text("text"),
text("some"), text("text"), btn1->Render(), btn2->Render(),
};
std::transform(words.begin(), words.begin() + value,
std::back_inserter(elements),
[](auto txt) { return text(txt); });
FlexboxConfig config;
config.gap_x = 1;
return flexbox(std::move(elements), config);
});
int resize = 10;
Component empty = Renderer([] { return text("Empty"); });
auto final_renderer = ResizableSplitLeft(renderer, empty, &resize);
auto screen = ftxui::ScreenInteractive::Fullscreen();
screen.Loop(final_renderer);
}
Hello! I'm having some issue in display container output as I want.
Let's say I want to render some text like this:
what I see is: the text continues on a newline as soon as it reaches the end of the page.
Now, I want to make the page dynamic: I want to render a number of elements of
words
based on the number of times the user pressed the button.But now, if I press the
+1
button until I get to three, I get the following output:So part of the text disappears to fit in the screen and nothing gets on the new line.
Studying the source code, I noticed
Container::Horizontal
useshbox
internally, so I rolled a new container usingflexbox
and tried with it:`flex_container` implementation, basycally a copy-paste of `ContainerBase` and `HorizontalContainer`
```cpp #includeThe code is basically the same:
What happens is that now, when I increment the
value
, my elements goes to a new line - but the go there as a whole! (I had to add aVertical
because without it the new line is not rendered, but that's not the point; the rest of the code is the same)At this point I'm not sure about how to get the result I want. I tried to find a way to "unpack" the
Renderer
output into theflex_container
(basically get{some_text ... some_text btn1 btn2 one two ... ten}
instead of{{some_text ... some_text} btn1 btn2 {one two ... ten}}
), but got no luck, and now I'm out of ideas.Do you have any suggestion?