component/catch_event: improve the example for CatchEvent() (#351)

before this change, the example in the doxygen document for CatchEvent()
does not use the documented function. hence the example is not that
useful for developers interested in a typical usage of this function.

after this change, the example is improved to added the call to
CatchEvent(), which allows the application to the Loop() function at
user input.

Signed-off-by: Kefu Chai <tchaikov@gmail.com>
This commit is contained in:
Kefu Chai 2022-03-04 20:23:31 +08:00 committed by GitHub
parent 9dbc23a7d4
commit a254e36632
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -39,7 +39,14 @@ class CatchEventBase : public ComponentBase {
/// auto renderer = Renderer([] {
/// return text("My interface");
/// });
/// screen.Loop(renderer);
/// auto component = CatchEvent(renderer, [&](Event event) {
/// if (event == Event::Character('q')) {
/// screen.ExitLoopClosure()();
/// return true;
/// }
/// return false;
/// });
/// screen.Loop(component);
/// ```
Component CatchEvent(Component child,
std::function<bool(Event event)> on_event) {