Menu or button does not work in component #1051
-
Instead of buttons I added a menu, the result is the same. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hello @SLHome
You might want to call "Add(...)" to make What about: class workspace_input : public ftxui::ComponentBase
{
Component window{Container::Vertical({})};
Component menu{Container::Horizontal({})};
Component log{Container::Vertical({})};
public:
workspace_input()
{
menu->Add(Button("Clear", [this]() { log->DetachAllChildren(); }, button_style));
menu->Add(Button("Close", [this]() { Detach(); }, button_style));
window->Add(menu);
window->Add(log);
Add(window)
}
}; Alternatively, without defining a new class. using namespace ftxui;
Component CreateWorkspaceInput() {
auto button_style = ButtonStyle();
button_style.background_color = Color::GrayDark;
button_style.text_color = Color::White;
Component log = Container::Vertical({});
Component workspace_input = Container::Vertical({
Container::Horizontal({
Button("Clear", [=] { log->DetachAllChildren(); }, button_style),
Button("Close", [=] { workspace_input->Detach(); }, button_style),
}),
log,
});
return workspace_input;
} (The last one might leak, because the children button "own" the parents via the callback) |
Beta Was this translation helpful? Give feedback.
-
Thanks, the first variant worked fine, but if I remove the "window" component, which I considered an extra layer, then everything stops displaying. |
Beta Was this translation helpful? Give feedback.
Hello @SLHome
workspace_input
isn't linked towindow
. So theOnEvent
isn't propagated properly.You might want to call "Add(...)" to make
workspace_input
the parent ofwindow
.What about: