跳转到内容

充电球(`gsp_charging_orb`)

提供水波、柔光光环和彩色光环,可配置充电粒子和膜状波纹。

适合显示状态、测量结果或动态效果。

先按兼容性页的工具命令配置 gspc 和 gsp_sim_host,再在解压后的组件或公共仓库根目录运行:

charging_orb-preview.sh
mkdir -p gsp-out/widget-preview
gspc pack \
examples/usage/widgets/charging_orb/charging_orb.json \
--deployable -o gsp-out/widget-preview/charging_orb.gspb
gsp_sim_host \
--bundle gsp-out/widget-preview/charging_orb.gspb --frames 0

这些命令会编译当前示例,并在 ESP-GSP 模拟器中打开浏览器预览。

模拟器与设备运行时使用相同的编译几何。预览初始值来自 JSON;应用驱动的变化需要模拟器后端/API 或设备代码。

如果应用代码需要读写某个对象,请为它设置稳定的 name。GSPC 会为命名对象生成下方列出的类型化函数。

charging_orb.json
{
"screen": "charging_orb_demo",
"w": 320,
"h": 240,
"screen_bg": "#08131F",
"font": "../../../common/fonts/DejaVuSans.ttf",
"objects": [
{
"type": "charging_orb",
"name": "charge",
"parent": -1,
"x": 70,
"y": 20,
"w": 180,
"h": 180,
"style": "halo",
"value": 62,
"fg_color": "#69CEF6",
"strength": 85,
"period_ms": 4200,
"particles": 4,
"softness": 90,
"ripple": 55,
"charging": true
},
{
"type": "label",
"parent": -1,
"x": 90,
"y": 92,
"w": 140,
"h": 40,
"text": "62%",
"font_size": 32,
"fg_color": "#EFFFFF",
"text_align": "center"
},
{
"type": "label",
"parent": -1,
"x": 20,
"y": 210,
"w": 280,
"h": 22,
"text": "ENERGY / CHARGING",
"font_size": 14,
"fg_color": "#7AADB5",
"text_align": "center"
}
]
}

规范示例来自 examples/usage/widgets/charging_orb/charging_orb.json。复制时请一并复制它引用的相对资源。

const gsp_component_directory_t *const * gsp_charging_orb_docs_component_directories(uint16_t *out_count)
esp_err_t gsp_charging_orb_demo_charge_animate_phase(esp_gsp_handle_t gsp, uint32_t from, uint32_t to, uint32_t duration_ms, esp_gsp_ease_t ease)
esp_err_t gsp_charging_orb_demo_charge_animate_phase_to(esp_gsp_handle_t gsp, uint32_t to, uint32_t duration_ms, esp_gsp_ease_t ease)
esp_err_t gsp_charging_orb_demo_charge_get_charging(esp_gsp_handle_t gsp, bool *out_value)
esp_err_t gsp_charging_orb_demo_charge_get_effective_visible(esp_gsp_handle_t gsp, bool *out_visible)
esp_err_t gsp_charging_orb_demo_charge_get_info(esp_gsp_handle_t gsp, esp_gsp_component_info_t *out_info)
esp_err_t gsp_charging_orb_demo_charge_get_phase(esp_gsp_handle_t gsp, uint32_t *out_value)
esp_err_t gsp_charging_orb_demo_charge_get_playing(esp_gsp_handle_t gsp, bool *out_value)
esp_err_t gsp_charging_orb_demo_charge_get_value(esp_gsp_handle_t gsp, int32_t *out_value)
esp_err_t gsp_charging_orb_demo_charge_play_phase(esp_gsp_handle_t gsp, uint32_t from, uint32_t to, const esp_gsp_animation_config_t *config)
esp_err_t gsp_charging_orb_demo_charge_set_charging(esp_gsp_handle_t gsp, bool new_value)
esp_err_t gsp_charging_orb_demo_charge_set_phase(esp_gsp_handle_t gsp, uint32_t new_value)
esp_err_t gsp_charging_orb_demo_charge_set_playing(esp_gsp_handle_t gsp, bool new_value)
esp_err_t gsp_charging_orb_demo_charge_set_value(esp_gsp_handle_t gsp, int32_t value)
esp_err_t gsp_charging_orb_demo_charge_stop_phase(esp_gsp_handle_t gsp)
esp_gsp_config_t gsp_charging_orb_docs_config(void)
size_t gsp_charging_orb_docs_dynamic_image_slots(void)

以上签名来自该 JSON 的实际编译产物。

字段 类型 必填 默认值 / 范围 可运行时更新 编译器定义
type string 是 — — 控件类型
parent int 是 默认 -1; -1…65534 — 父对象索引(-1 表示屏幕根节点)
x int 是 默认 0; -32768…32767 场景: 不支持; 模板: 不支持 相对于父对象的 x 坐标
y int 是 默认 0; -32768…32767 场景: 不支持; 模板: 不支持 相对于父对象的 y 坐标
w int 是 0…65535 场景: 不支持; 模板: 不支持 宽度(像素)
h int 是 0…65535 场景: 不支持; 模板: 不支持 高度(像素)
name identifier — — — 稳定组件名称;生成 GSP_OBJ_KEY_<NAME>
fg_color color — 默认 #38BDF8 runtime_style 特效颜色
value int — 默认 100; 0…100 — 液面高度或特效强度,百分比
period_ms int — 默认 2800; 100…60000 runtime_style 动画周期,毫秒
softness int — 默认 75; 0…100 runtime_style 光晕边缘柔和程度,百分比
strength int — 默认 65; 0…100 runtime_style 柔光强度,百分比
ripple int — 默认 45; 0…100 runtime_style 贴附式膜状波纹强度,百分比
style enum — 默认 halo; liquid, halo, plasma — 充电球视觉风格
charging bool — 默认 true — 开启充电动态效果和粒子
particles int — 默认 4; 0…6 runtime_style 柔光能量粒子数量上限
查看此控件支持的其他字段
字段 类型 必填 默认值 / 范围 可运行时更新 编译器定义
hidden bool — 默认 false 是 初始隐藏(通过动作或 set_visible 显示)
enabled bool — — — 初始交互状态;设置后会公开可由后代控件继承的运行时 enabled 属性
disabled_color color — 默认 #808080 — 禁用态覆盖颜色
disabled_opacity int — 默认 112; 0…255 — 禁用态覆盖透明度
bind identifier — — — 公开状态名称;生成 GSP_BIND_<NAME>
bind_target enum — visible, value, color, text, resource, data — 显式绑定状态类型
dynamic string_list — — — 运行时可变属性列表(如 text、color、visible、resource、x、y、w、h、opacity)
callback identifier — — — 应用回调名称;生成按场景区分的事件辅助函数
events action_list — — — 输入绑定:[{event, action, ...}]
runtime_style bool — 默认 false — 生成运行时外观设置接口(按需启用)
bg_color color — — — 可选静态背景颜色
playing bool — 默认 true — 可见时自动推进动画
phase int — 默认 0; 0…65535 — 初始周期相位,0..65535
opacity int — 默认 255; 0…255 runtime_style 特效整体透明度
查看所有组件共享字段
字段 类型 必填 默认值 / 范围 可运行时更新 编译器定义
parent_name string — — — 使用名称而不是索引指定父对象