2018-10-10 01:06:03 +08:00
|
|
|
#include "ftxui/component/component.hpp"
|
|
|
|
#include "ftxui/component/delegate.hpp"
|
|
|
|
#include <assert.h>
|
|
|
|
|
2019-01-07 00:10:35 +08:00
|
|
|
namespace ftxui::component {
|
2018-10-10 01:06:03 +08:00
|
|
|
|
|
|
|
Component::Component(Delegate* delegate) {
|
|
|
|
delegate_ = delegate;
|
|
|
|
delegate_->Register(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
Component::~Component() {}
|
|
|
|
|
|
|
|
dom::Element Component::Render() {
|
|
|
|
using namespace ftxui::dom;
|
|
|
|
return text(L"Not implemented component");
|
|
|
|
}
|
|
|
|
|
2018-10-19 04:58:38 +08:00
|
|
|
bool Component::OnEvent(Event event) {
|
2018-10-10 01:06:03 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Component::Focused() {
|
|
|
|
Delegate* current = delegate_->Root();
|
|
|
|
while (current) {
|
|
|
|
if (current == delegate_)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
Component* active_child = current->component()->GetActiveChild();
|
|
|
|
current = active_child ? active_child->delegate_ : nullptr;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Component::Active() {
|
|
|
|
Delegate* parent = delegate_->Parent();
|
|
|
|
return parent && parent->component()->GetActiveChild() == this;
|
|
|
|
}
|
|
|
|
|
|
|
|
Component* Component::PreviousSibling() {
|
|
|
|
Delegate* sibling = delegate_->PreviousSibling();
|
|
|
|
return sibling ? sibling->component() : nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
Component* Component::NextSibling() {
|
|
|
|
Delegate* sibling = delegate_->NextSibling();
|
|
|
|
return sibling ? sibling->component() : nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
Component* Component::Parent() {
|
|
|
|
Delegate* parent_delegate = delegate_->Parent();
|
|
|
|
if (!parent_delegate)
|
|
|
|
return nullptr;
|
|
|
|
return parent_delegate->component();
|
|
|
|
}
|
|
|
|
|
2019-01-07 00:10:35 +08:00
|
|
|
} // namespace ftxui::component
|