-
-
Notifications
You must be signed in to change notification settings - Fork 416
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Modal windows, what am I doing wrong? #897
Comments
I believe this is due to both of the component not to be "focusable". Ideally, you wouldn't use Here is the solution: #include <ftxui/component/component.hpp>
#include <ftxui/component/event.hpp>
#include <ftxui/component/screen_interactive.hpp>
#include <ftxui/dom/deprecated.hpp>
#include <ftxui/dom/elements.hpp>
int main() {
auto screen = ftxui::ScreenInteractive::Fullscreen();
auto showHide = false;
auto main = ftxui::Renderer([&](bool focused) {
auto element = ftxui::vbox(ftxui::text("main") | ftxui::center) | ftxui::border;
if (focused) {
element |= ftxui::focus;
element |= ftxui::bold;
}
return element;
});
// goal: open modal dialog on Enter key
main |= ftxui::CatchEvent([&](ftxui::Event event) {
if (event == ftxui::Event::Return) {
showHide = true;
return true;
}
return false;
});
auto modal = ftxui::Renderer([&](bool focused) {
auto element = ftxui::vbox(ftxui::text("modal") | ftxui::center) | ftxui::border;
if (focused) {
element |= ftxui::focus;
element |= ftxui::bold;
}
return element;
});
// goal: close modal dialog on Q button
modal |= ftxui::CatchEvent([&](ftxui::Event event) {
if (event == ftxui::Event::Character('q')) {
showHide = false;
return true;
}
return false;
});
main |= ftxui::Modal(modal, &showHide);
screen.Loop(main);
return 0;
} |
Hey, thank you so much for the quick support. Works like a charm! I'm still learning the possibilities of FTXUI. You're saying you would not use Thanks again, really appreciated! |
Hey,
I'm trying to get modal to work for my project but I can't get it right. Maybe someone can give me a hint why the following minimum example doesn't work? Is it even supposed to work like that? Any help appreciated!
Summary:
ftxui::Modal
decoratorftxui::CatchEvent
decoratorsThe text was updated successfully, but these errors were encountered: