Allows components to remove a child by index.

This commit is contained in:
Felix Heitmann
2021-07-14 13:36:52 +02:00
committed by ArthurSonzogni
parent 9b7ddb1130
commit 2c087f1832
2 changed files with 8 additions and 1 deletions

View File

@@ -29,7 +29,7 @@ class ComponentBase {
// ComponentBase hierarchy.
ComponentBase* Parent();
void Add(Component children);
void Remove(std::size_t idx);
// Renders the component.
virtual Element Render();

View File

@@ -41,6 +41,13 @@ void ComponentBase::Add(Component child) {
children_.push_back(std::move(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);
}
/// @brief Draw the component.
/// Build a ftxui::Element to be drawn on the ftxi::Screen representing this
/// ftxui::ComponentBase.