Skip to content

Latest commit

 

History

History
541 lines (353 loc) · 7.68 KB

component_api.md

File metadata and controls

541 lines (353 loc) · 7.68 KB

druid.component API

位于 /druid/component.lua

函数

字段

create


component.create(base_type, meta)

创建新组件类型的工厂函数。

  • 参数:

    • base_type (table): 基础组件类型
    • meta (table): 组件元数据
  • 返回:

    • component_type (table): 新的组件类型

create_widget


component.create_widget(meta)

创建新组件类型的工厂函数。

  • 参数:

    • meta (table): 组件元数据
  • 返回:

    • component_type (table): 新的组件类型

init


component.init(self, druid, name, ...)

组件初始化。

  • 参数:
    • self (druid.component): 组件实例
    • druid (druid.instance): Druid 实例
    • name (string): 组件名称
    • ... (...): 其他参数

update


component.update(self, dt)

组件更新函数。

  • 参数:
    • self (druid.component): 组件实例
    • dt (number): 时间增量

on_remove


component.on_remove(self)

组件移除时调用。

  • 参数:
    • self (druid.component): 组件实例

on_input


component.on_input(self, action_id, action)

处理输入事件。

  • 参数:

    • self (druid.component): 组件实例
    • action_id (hash): 动作 ID
    • action (table): 动作表
  • 返回:

    • consumed (boolean): 是否消费了输入事件

on_input_interrupt


component.on_input_interrupt(self)

输入中断时调用。

  • 参数:
    • self (druid.component): 组件实例

on_message


component.on_message(self, message_id, message, sender)

处理消息事件。

  • 参数:
    • self (druid.component): 组件实例
    • message_id (hash): 消息 ID
    • message (table): 消息内容
    • sender (url): 发送者 URL

on_late_init


component.on_late_init(self)

延迟初始化。

  • 参数:
    • self (druid.component): 组件实例

on_focus_lost


component.on_focus_lost(self)

失去焦点时调用。

  • 参数:
    • self (druid.component): 组件实例

on_focus_gained


component.on_focus_gained(self)

获得焦点时调用。

  • 参数:
    • self (druid.component): 组件实例

on_style_change


component.on_style_change(self)

样式更改时调用。

  • 参数:
    • self (druid.component): 组件实例

on_layout_change


component.on_layout_change(self)

布局更改时调用。

  • 参数:
    • self (druid.component): 组件实例

on_window_resized


component.on_window_resized(self, width, height)

窗口调整大小时调用。

  • 参数:
    • self (druid.component): 组件实例
    • width (number): 新宽度
    • height (number): 新高度

on_language_change


component.on_language_change(self)

语言更改时调用。

  • 参数:
    • self (druid.component): 组件实例

set_style


component.set_style(self, style)

设置组件样式。

  • 参数:
    • self (druid.component): 组件实例
    • style (table): 样式表

set_template


component.set_template(self, template)

设置组件模板。

  • 参数:
    • self (druid.component): 组件实例
    • template (table): 模板表

get_template


component.get_template(self)

获取组件模板。

  • 参数:

    • self (druid.component): 组件实例
  • 返回:

    • template (table): 模板表

set_nodes


component.set_nodes(self, nodes)

设置组件节点。

  • 参数:
    • self (druid.component): 组件实例
    • nodes (table): 节点表

get_context


component.get_context(self)

获取组件上下文。

  • 参数:

    • self (druid.component): 组件实例
  • 返回:

    • context (table): 组件上下文

get_node


component.get_node(self, node_id)

获取节点。

  • 参数:

    • self (druid.component): 组件实例
    • node_id (string): 节点 ID
  • 返回:

    • node (node): GUI 节点

get_druid


component.get_druid(self)

获取 Druid 实例。

  • 参数:

    • self (druid.component): 组件实例
  • 返回:

    • druid (druid.instance): Druid 实例

get_name


component.get_name(self)

获取组件名称。

  • 参数:

    • self (druid.component): 组件实例
  • 返回:

    • name (string): 组件名称

get_parent_name


component.get_parent_name(self)

获取父组件名称。

  • 参数:

    • self (druid.component): 组件实例
  • 返回:

    • parent_name (string): 父组件名称

get_input_priority


component.get_input_priority(self)

获取输入优先级。

  • 参数:

    • self (druid.component): 组件实例
  • 返回:

    • priority (number): 输入优先级

set_input_priority


component.set_input_priority(self, priority)

设置输入优先级。

  • 参数:
    • self (druid.component): 组件实例
    • priority (number): 输入优先级

reset_input_priority


component.reset_input_priority(self)

重置输入优先级。

  • 参数:
    • self (druid.component): 组件实例

get_uid


component.get_uid(self)

获取组件唯一 ID。

  • 参数:

    • self (druid.component): 组件实例
  • 返回:

    • uid (number): 唯一 ID

set_input_enabled


component.set_input_enabled(self, enabled)

设置输入启用状态。

  • 参数:
    • self (druid.component): 组件实例
    • enabled (boolean): 是否启用输入

get_input_enabled


component.get_input_enabled(self)

获取输入启用状态。

  • 参数:

    • self (druid.component): 组件实例
  • 返回:

    • enabled (boolean): 是否启用输入

get_parent_component


component.get_parent_component(self)

获取父组件。

  • 参数:

    • self (druid.component): 组件实例
  • 返回:

    • parent (druid.component): 父组件

get_nodes


component.get_nodes(self)

获取组件节点。

  • 参数:

    • self (druid.component): 组件实例
  • 返回:

    • nodes (table): 节点表

get_childrens


component.get_childrens(self)

获取子组件。

  • 参数:

    • self (druid.component): 组件实例
  • 返回:

    • childrens (table): 子组件表

事件字段

druid

组件关联的 Druid 实例。