Exposed components begin/end

Allows iteration over a components children.
Updated Remove function to conform to vector::erase
This commit is contained in:
Felix Heitmann
2021-07-14 13:45:07 +02:00
committed by ArthurSonzogni
parent 2c087f1832
commit 95feb62442
2 changed files with 21 additions and 3 deletions

View File

@@ -29,10 +29,14 @@ class ComponentBase {
// ComponentBase hierarchy.
ComponentBase* Parent();
void Add(Component children);
void Remove(std::size_t idx);
void Remove(Components::iterator child);
// Renders the component.
virtual Element Render();
// Iterate over component children
Components::iterator begin();
Components::iterator end();
// Handles an event.
// By default, reduce on children with a lazy OR.
//

View File

@@ -44,10 +44,24 @@ void ComponentBase::Add(Component child) {
/// @brief Remove a child.
/// @@param idx The child index to be removed.
/// @ingroup component
void ComponentBase::Remove(std::size_t idx) {
children_.erase(children_.begin()+idx);
void ComponentBase::Remove(Components::iterator child) {
children_.erase(child);
}
/// @brief Obtain an iterator to the first child
/// @ingroup component
Components::iterator ComponentBase::begin() {
return children_.begin();
}
/// @brief Obtain an iterator to one after the last child
/// @ingroup component
Components::iterator ComponentBase::end() {
return children_.end();
}
/// @brief Draw the component.
/// Build a ftxui::Element to be drawn on the ftxi::Screen representing this
/// ftxui::ComponentBase.