NexusForce 1.0.0
A rigorously engineered full-stack C++ backend library.
载入中...
搜索中...
未找到
neforce::tui::component_base类 参考abstract

组件基类 更多...

#include <component.hpp>

类 neforce::tui::component_base 继承关系图:
[图例]

Public 成员函数

virtual element render ()=0
 声明式渲染
virtual bool on_key (const key_event &e)
 键盘事件处理
virtual bool on_mouse (const mouse_event &e)
 鼠标事件处理
virtual void on_mouse_leave ()
 鼠标离开回调
void set_pass_through (bool v) noexcept
 设置事件穿透
bool pass_through () const noexcept
 是否启用事件穿透
bool has_focus () const noexcept
 是否持有 Reconciler 键盘焦点
void set_has_focus (bool v) noexcept
 设置 Reconciler 焦点状态(由 Reconciler 调用)
virtual void on_animation (int64_t delta)
 动画帧回调
virtual void setup ()
 挂载回调
virtual void cleanup () noexcept
 卸载回调
virtual bool should_update ()
 是否需要更新
component_baseparent () const noexcept
 获取父组件
size_t child_count () const noexcept
 获取子组件数量
component_basechild_at (size_t i) const noexcept
 获取指定索引的子组件
int index () const noexcept
 获取自身在父组件中的索引
void add_child (unique_ptr< component_base > child)
 注册子组件
unique_ptr< component_baseremove_child (component_base *child)
 移除子组件
unique_ptr< component_basedetach ()
 从父组件中脱离自身
void detach_all_children ()
 移除所有子组件
virtual bool focusable () const
 是否可获取焦点
component_baseactive_child () noexcept
 获取当前激活的子组件
const component_baseactive_child () const noexcept
 获取当前激活的子组件
void set_active_child (component_base *child) noexcept
 设置激活的子组件
bool active () const noexcept
 是否处于激活状态
bool focused () const noexcept
 是否拥有焦点
virtual void take_focus ()
 请求焦点
void schedule_render ()
 调度重渲染
template<typename Ctx>
void provide_context (Ctx value)
 设置上下文值
template<typename Ctx>
const Ctx & context () const
 获取上下文值

Protected 属性

component_baseparent_ = nullptr
 父组件指针
component_baseactive_child_ = nullptr
 当前激活的子组件
bool has_focus_ = false
 reconciler 焦点状态
bool pass_through_ = false
 事件穿透标志
strandstrand_ = nullptr
 串行执行器
io_contextctx_ = nullptr
 事件循环上下文
vector< unique_ptr< component_base > > children_
 子组件列表

详细描述

组件基类

在文件 component.hpp36 行定义.

成员函数说明

◆ active()

bool neforce::tui::component_base::active ( ) const
inlinenodiscardnoexcept

是否处于激活状态

返回
是否活跃

在文件 component.hpp251 行定义.

引用了 parent_.

被这些函数引用 focused().

◆ active_child() [1/2]

const component_base * neforce::tui::component_base::active_child ( ) const
inlinenodiscardnoexcept

获取当前激活的子组件

返回
激活的子组件指针

在文件 component.hpp239 行定义.

引用了 active_child_.

◆ active_child() [2/2]

component_base * neforce::tui::component_base::active_child ( )
inlinenodiscardnoexcept

获取当前激活的子组件

返回
激活的子组件指针

在文件 component.hpp233 行定义.

引用了 active_child_.

◆ add_child()

void neforce::tui::component_base::add_child ( unique_ptr< component_base > child)
inline

注册子组件

参数
child子组件指针

父组件接管子组件生命周期。注册后子组件将参与焦点链遍历和生命周期管理。

在文件 component.hpp175 行定义.

引用了 children_, ctx_, neforce::unique_ptr< T, Deleter >::get(), neforce::move() , 以及 strand_.

◆ child_at()

component_base * neforce::tui::component_base::child_at ( size_t i) const
inlinenodiscardnoexcept

获取指定索引的子组件

参数
i索引
返回
子组件指针

在文件 component.hpp151 行定义.

引用了 children_.

◆ child_count()

size_t neforce::tui::component_base::child_count ( ) const
inlinenodiscardnoexcept

获取子组件数量

返回
子组件数

在文件 component.hpp144 行定义.

引用了 children_.

◆ cleanup()

virtual void neforce::tui::component_base::cleanup ( )
inlinevirtualnoexcept

卸载回调

在组件被移除前调用。在此断开连接、释放资源。

在文件 component.hpp123 行定义.

被这些函数引用 remove_child().

◆ context()

template<typename Ctx>
const Ctx & neforce::tui::component_base::context ( ) const
inlinenodiscard

获取上下文值

模板参数
Ctx上下文类型
返回
上下文常量引用

在文件 component.hpp305 行定义.

◆ detach()

unique_ptr< component_base > neforce::tui::component_base::detach ( )
inlinenodiscard

从父组件中脱离自身

返回
自身指针

在文件 component.hpp207 行定义.

引用了 parent_.

◆ focusable()

virtual bool neforce::tui::component_base::focusable ( ) const
inlinenodiscardvirtual

是否可获取焦点

返回
true 表示该组件可接收键盘事件

在文件 component.hpp227 行定义.

◆ focused()

bool neforce::tui::component_base::focused ( ) const
inlinenodiscardnoexcept

是否拥有焦点

返回
是否已聚焦

在文件 component.hpp257 行定义.

引用了 active() , 以及 parent_.

◆ has_focus()

bool neforce::tui::component_base::has_focus ( ) const
inlinenodiscardnoexcept

是否持有 Reconciler 键盘焦点

返回
是否聚焦

在文件 component.hpp97 行定义.

引用了 has_focus_.

◆ index()

int neforce::tui::component_base::index ( ) const
inlinenodiscardnoexcept

获取自身在父组件中的索引

返回
索引,无父组件返回 -1

在文件 component.hpp157 行定义.

引用了 parent_.

◆ on_animation()

virtual void neforce::tui::component_base::on_animation ( int64_t delta)
inlinevirtual

动画帧回调

参数
delta距上一帧的毫秒数

在文件 component.hpp109 行定义.

◆ on_key()

virtual bool neforce::tui::component_base::on_key ( const key_event & e)
inlinevirtual

键盘事件处理

参数
e键盘事件
返回
true 表示事件已消费,false 继续向父组件传递

在文件 component.hpp56 行定义.

◆ on_mouse()

virtual bool neforce::tui::component_base::on_mouse ( const mouse_event & e)
inlinevirtual

鼠标事件处理

参数
e鼠标事件
返回
true 表示事件已消费

在文件 component.hpp66 行定义.

◆ on_mouse_leave()

virtual void neforce::tui::component_base::on_mouse_leave ( )
inlinevirtual

鼠标离开回调

当鼠标从前一帧的当前组件移动到其他组件时,Reconciler 调用此方法。

在文件 component.hpp76 行定义.

◆ parent()

component_base * neforce::tui::component_base::parent ( ) const
inlinenodiscardnoexcept

获取父组件

返回
父组件指针,根组件返回 nullptr

在文件 component.hpp138 行定义.

引用了 parent_.

◆ pass_through()

bool neforce::tui::component_base::pass_through ( ) const
inlinenodiscardnoexcept

是否启用事件穿透

返回
是否穿透

在文件 component.hpp91 行定义.

引用了 pass_through_.

◆ provide_context()

template<typename Ctx>
void neforce::tui::component_base::provide_context ( Ctx value)
inline

设置上下文值

模板参数
Ctx上下文类型
参数
value上下文值

在文件 component.hpp295 行定义.

引用了 neforce::make_shared() , 以及 neforce::move().

◆ remove_child()

unique_ptr< component_base > neforce::tui::component_base::remove_child ( component_base * child)
inline

移除子组件

参数
child子组件指针
返回
子组件指针,调用者接管其生命周期

在文件 component.hpp190 行定义.

引用了 children_, cleanup(), neforce::move() , 以及 parent_.

被这些函数引用 detach_all_children().

◆ render()

virtual element neforce::tui::component_base::render ( )
pure virtual

声明式渲染

返回
虚拟元素树

Reconciler 每次 flush 时调用此方法获取最新 UI 描述。 实现必须是纯函数——仅构建 element 树,禁止终端 I/O。

注解
禁止在 render() 中修改 State。

◆ schedule_render()

void neforce::tui::component_base::schedule_render ( )
inline

调度重渲染

state<T> 在写入时调用,通知 reconciler。

在文件 component.hpp283 行定义.

◆ set_active_child()

void neforce::tui::component_base::set_active_child ( component_base * child)
inlinenoexcept

设置激活的子组件

参数
child要激活的子组件指针

在文件 component.hpp245 行定义.

引用了 active_child_.

◆ set_has_focus()

void neforce::tui::component_base::set_has_focus ( bool v)
inlinenoexcept

设置 Reconciler 焦点状态(由 Reconciler 调用)

参数
v是否聚焦

在文件 component.hpp103 行定义.

引用了 has_focus_.

◆ set_pass_through()

void neforce::tui::component_base::set_pass_through ( bool v)
inlinenoexcept

设置事件穿透

参数
v是否穿透

当设为 true 时,聚焦组件未消费的键盘事件会继续向父组件传递; 默认为 false,未消费的事件将被丢弃。

在文件 component.hpp85 行定义.

引用了 pass_through_.

◆ setup()

virtual void neforce::tui::component_base::setup ( )
inlinevirtual

挂载回调

在首次 render() 之前调用。在此连接 signal、订阅事件、启动异步操作。

在文件 component.hpp116 行定义.

◆ should_update()

virtual bool neforce::tui::component_base::should_update ( )
inlinevirtual

是否需要更新

返回
true 表示需要重新 render,false 跳过本次渲染

性能优化钩子。reconciler 在每次 flush 前检查此方法, 返回 false 则复用上次的 element 树。

在文件 component.hpp132 行定义.


该类的文档由以下文件生成: