mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-09-19 10:08:10 +08:00
Component decorators (#354)
Add decorator variants for decorator components Add the "pipe" operator for components, similar to what was done for Elements. We are able to put something like: ``` Button(...) | Maybe(&show_button) ``` Add decorators for: - `Maybe` - `CatchEvent` - `Renderer` Signed-off-by: Kefu Chai <tchaikov@gmail.com> Co-authored-by: ArthurSonzogni <sonzogniarthur@gmail.com>
This commit is contained in:
32
src/ftxui/component/util.cpp
Normal file
32
src/ftxui/component/util.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
#include <functional> // for function
|
||||
#include <memory> // for __shared_ptr_access
|
||||
|
||||
#include "ftxui/component/component.hpp" // for ElementDecorator, Renderer, ComponentDecorator, operator|, operator|=
|
||||
#include "ftxui/component/component_base.hpp" // for Component, ComponentBase
|
||||
#include "ftxui/dom/elements.hpp" // for Element
|
||||
|
||||
namespace ftxui {
|
||||
|
||||
Component operator|(Component component, ComponentDecorator decorator) {
|
||||
return decorator(component);
|
||||
}
|
||||
|
||||
Component operator|(Component component, ElementDecorator decorator) {
|
||||
return component | Renderer(decorator);
|
||||
}
|
||||
|
||||
Component& operator|=(Component& component, ComponentDecorator decorator) {
|
||||
component = component | decorator;
|
||||
return component;
|
||||
}
|
||||
|
||||
Component& operator|=(Component& component, ElementDecorator decorator) {
|
||||
component = component | decorator;
|
||||
return component;
|
||||
}
|
||||
|
||||
} // namespace ftxui
|
||||
|
||||
// Copyright 2022 Arthur Sonzogni. All rights reserved.
|
||||
// Use of this source code is governed by the MIT license that can be found in
|
||||
// the LICENSE file.
|
Reference in New Issue
Block a user