mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-09-18 09:08:08 +08:00
Add more documentation.
This commit is contained in:

committed by
Arthur Sonzogni

parent
f2dc080a35
commit
114ab4ae2a
@@ -5,28 +5,44 @@
|
||||
#include <algorithm>
|
||||
|
||||
namespace ftxui {
|
||||
void Component::Detach() {
|
||||
if (!parent_)
|
||||
return;
|
||||
auto it = std::find(std::begin(parent_->children_),
|
||||
std::end(parent_->children_), this);
|
||||
parent_->children_.erase(it);
|
||||
}
|
||||
|
||||
void Component::Attach(Component* parent) {
|
||||
Detach();
|
||||
parent_ = parent;
|
||||
parent_->children_.push_back(this);
|
||||
}
|
||||
|
||||
void Component::Add(Component* child) {
|
||||
child->Attach(this);
|
||||
}
|
||||
|
||||
Component::~Component() {
|
||||
Detach();
|
||||
}
|
||||
|
||||
/// @brief Return the parent Component, or nul if any.
|
||||
/// @see Attach
|
||||
/// @see Detach
|
||||
/// @see Parent
|
||||
/// @ingroup component
|
||||
Component* Component::Parent() {
|
||||
return parent_;
|
||||
}
|
||||
|
||||
/// @brief Add a children.
|
||||
/// @@param child The child to be attached.
|
||||
/// @ingroup component
|
||||
void Component::Add(Component* child) {
|
||||
child->Attach(this);
|
||||
}
|
||||
|
||||
/// @brief Draw the component.
|
||||
/// Build a ftxui::Element to be drawn on the ftxi::Screen representing this
|
||||
/// ftxui::Component.
|
||||
/// @ingroup component
|
||||
Element Component::Render() {
|
||||
if (children_.size() == 1)
|
||||
return children_.front()->Render();
|
||||
|
||||
return text(L"Not implemented component");
|
||||
}
|
||||
|
||||
/// @brief Called in response to an event.
|
||||
/// @param event The event.
|
||||
/// @return True when the event has been handled.
|
||||
/// The default implementation called OnEvent on every child until one return
|
||||
/// true. If none returns true, return false.
|
||||
/// @ingroup component
|
||||
bool Component::OnEvent(Event event) {
|
||||
for (Component* child : children_) {
|
||||
if (child->OnEvent(event))
|
||||
@@ -35,17 +51,16 @@ bool Component::OnEvent(Event event) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/// @brief Return the currently Active child.
|
||||
/// @return the currently Active child.
|
||||
/// @ingroup component
|
||||
Component* Component::ActiveChild() {
|
||||
return children_.empty() ? nullptr : children_.front();
|
||||
}
|
||||
|
||||
Element Component::Render() {
|
||||
if (children_.size() == 1)
|
||||
return children_.front()->Render();
|
||||
|
||||
return text(L"Not implemented component");
|
||||
}
|
||||
|
||||
/// @brief Returns if the elements if focused by the user.
|
||||
/// True when the Component is focused by the user. An element is Focused when
|
||||
/// it is with all its ancestors the ActiveChild() of their parents.
|
||||
bool Component::Focused() {
|
||||
Component* current = this;
|
||||
for (;;) {
|
||||
@@ -58,6 +73,31 @@ bool Component::Focused() {
|
||||
}
|
||||
}
|
||||
|
||||
/// @brief Detach this children from its parent.
|
||||
/// @see Attach
|
||||
/// @see Detach
|
||||
/// @see Parent
|
||||
/// @ingroup component
|
||||
void Component::Detach() {
|
||||
if (!parent_)
|
||||
return;
|
||||
auto it = std::find(std::begin(parent_->children_),
|
||||
std::end(parent_->children_), this);
|
||||
parent_->children_.erase(it);
|
||||
}
|
||||
|
||||
/// @brief Attach this element to its parent.
|
||||
/// @see Attach
|
||||
/// @see Detach
|
||||
/// @see Parent
|
||||
/// @ingroup component
|
||||
void Component::Attach(Component* parent) {
|
||||
Detach();
|
||||
parent_ = parent;
|
||||
parent_->children_.push_back(this);
|
||||
}
|
||||
|
||||
|
||||
} // namespace ftxui
|
||||
|
||||
// Copyright 2020 Arthur Sonzogni. All rights reserved.
|
||||
|
Reference in New Issue
Block a user