Replies: 2 comments 9 replies
-
I think you could create a CatchEvent class that will first ask for the children. This is similar to: class CatchEventBase2 : public ComponentBase {
public:
// Constructor.
explicit CatchEventBase2(std::function<bool(Event)> on_event)
: on_event_(std::move(on_event)) {}
// Component implementation.
bool OnEvent(Event event) override {
if (ComponentBase2:OnEvent(event)) {
return true;
} else {
return on_event_(event)
}
}
protected:
std::function<bool(Event)> on_event_;
};
Component CatchEvent2(Component child,
std::function<bool(Event event)> on_event) {
auto out = Make<CatchEventBase2>(std::move(on_event));
out->Add(std::move(child));
return out;
}
ComponentDecorator CatchEvent2(std::function<bool(Event)> on_event) {
return [on_event = std::move(on_event)](Component child) {
return CatchEvent2(std::move(child), [on_event = on_event](Event event) {
return on_event(std::move(event));
});
};
} |
Beta Was this translation helpful? Give feedback.
-
@ArthurSonzogni , a sort of related question: Is it possible for a component to Unfocus/YieldFocus itself in its OnEvent handler? For instance, I have a data table with rows. The user can select rows with arrow keys or the mouse. If they do, the table does TakeFocus(). If it is Focused(), then its Render() call, it shows a section with details about the row at the bottom. When the user hits ESC, I'd like to stop showing the details at the bottom and in order to do that, unfocus the table. |
Beta Was this translation helpful? Give feedback.
-
Hi there. I've got an app with a main component that contains a bunch of subcomponents. The main component wants to display a help dialog when the user hits
h
or?
. This works great, but there are also some text input boxes where the user can legitimately type words that contain h, likethere
. Right now as soon as the user hits theh
in "there", the help dialog pops up.How can the MainComponent know that some great-grandchild input component of it has Focus for input?
Beta Was this translation helpful? Give feedback.
All reactions