时钟(`gsp_clock`)
指针与刻度可独立配置的模拟时钟。
适合显示状态、测量结果或动态效果。
本地交互预览
Section titled “本地交互预览”先按兼容性页的工具命令配置 gspc 和 gsp_sim_host,再在解压后的组件或公共仓库根目录运行:
mkdir -p gsp-out/widget-previewgspc pack \ examples/usage/widgets/clock/clock.json \ --deployable -o gsp-out/widget-preview/clock.gspbgsp_sim_host \ --bundle gsp-out/widget-preview/clock.gspb --frames 0这些命令会编译当前示例,并在 ESP-GSP 模拟器中打开浏览器预览。
模拟器与设备运行时使用相同的编译几何。预览初始值来自 JSON;应用驱动的变化需要模拟器后端/API 或设备代码。
如果应用代码需要读写某个对象,请为它设置稳定的 name。GSPC 会为命名对象生成下方列出的类型化函数。
{"screen":"widget_clock","w":480,"h":320,"screen_bg":"#101827","objects":[{"type":"clock","parent":-1,"name":"local_time","x":130,"y":30,"w":220,"h":220,"hour_angle":305,"minute_angle":120,"second_angle":218,"hour_color":"#F8FAFC","minute_color":"#BAE6FD","second_color":"#FB7185","tick_color":"#64748B","bg_color":"#172235","border_color":"#334A68","border_width":2,"radius":110}]}规范示例来自 examples/usage/widgets/clock/clock.json。复制时请一并复制它引用的相对资源。
此场景生成的 C API
Section titled “此场景生成的 C API”const gsp_component_directory_t *const * gsp_clock_docs_component_directories(uint16_t *out_count)esp_err_t gsp_widget_clock_local_time_animate_hour_angle(esp_gsp_handle_t gsp, int32_t from, int32_t to, uint32_t duration_ms, esp_gsp_ease_t ease)esp_err_t gsp_widget_clock_local_time_animate_hour_angle_to(esp_gsp_handle_t gsp, int32_t to, uint32_t duration_ms, esp_gsp_ease_t ease)esp_err_t gsp_widget_clock_local_time_animate_minute_angle(esp_gsp_handle_t gsp, int32_t from, int32_t to, uint32_t duration_ms, esp_gsp_ease_t ease)esp_err_t gsp_widget_clock_local_time_animate_minute_angle_to(esp_gsp_handle_t gsp, int32_t to, uint32_t duration_ms, esp_gsp_ease_t ease)esp_err_t gsp_widget_clock_local_time_animate_second_angle(esp_gsp_handle_t gsp, int32_t from, int32_t to, uint32_t duration_ms, esp_gsp_ease_t ease)esp_err_t gsp_widget_clock_local_time_animate_second_angle_to(esp_gsp_handle_t gsp, int32_t to, uint32_t duration_ms, esp_gsp_ease_t ease)esp_err_t gsp_widget_clock_local_time_get_effective_visible(esp_gsp_handle_t gsp, bool *out_visible)esp_err_t gsp_widget_clock_local_time_get_hour_angle(esp_gsp_handle_t gsp, int32_t *out_value)esp_err_t gsp_widget_clock_local_time_get_info(esp_gsp_handle_t gsp, esp_gsp_component_info_t *out_info)esp_err_t gsp_widget_clock_local_time_get_minute_angle(esp_gsp_handle_t gsp, int32_t *out_value)esp_err_t gsp_widget_clock_local_time_get_second_angle(esp_gsp_handle_t gsp, int32_t *out_value)esp_err_t gsp_widget_clock_local_time_play_hour_angle(esp_gsp_handle_t gsp, int32_t from, int32_t to, const esp_gsp_animation_config_t *config)esp_err_t gsp_widget_clock_local_time_play_minute_angle(esp_gsp_handle_t gsp, int32_t from, int32_t to, const esp_gsp_animation_config_t *config)esp_err_t gsp_widget_clock_local_time_play_second_angle(esp_gsp_handle_t gsp, int32_t from, int32_t to, const esp_gsp_animation_config_t *config)esp_err_t gsp_widget_clock_local_time_set_hour_angle(esp_gsp_handle_t gsp, int32_t new_value)esp_err_t gsp_widget_clock_local_time_set_minute_angle(esp_gsp_handle_t gsp, int32_t new_value)esp_err_t gsp_widget_clock_local_time_set_second_angle(esp_gsp_handle_t gsp, int32_t new_value)esp_err_t gsp_widget_clock_local_time_set_time( esp_gsp_handle_t gsp, uint8_t hour, uint8_t minute, uint8_t second)esp_err_t gsp_widget_clock_local_time_stop_hour_angle(esp_gsp_handle_t gsp)esp_err_t gsp_widget_clock_local_time_stop_minute_angle(esp_gsp_handle_t gsp)esp_err_t gsp_widget_clock_local_time_stop_second_angle(esp_gsp_handle_t gsp)esp_gsp_config_t gsp_clock_docs_config(void)size_t gsp_clock_docs_dynamic_image_slots(void)以上签名来自该 JSON 的实际编译产物。
此示例使用的字段
Section titled “此示例使用的字段”| 字段 | 类型 | 必填 | 默认值 / 范围 | 可运行时更新 | 编译器定义 |
|---|---|---|---|---|---|
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> |
bg_color |
color |
— | — | 是 | 背景/填充颜色(#RRGGBB 或 #RRGGBBAA) |
radius |
int |
— | 默认 0; 0…65535 | 场景: 不支持; 模板: 不支持 | 圆角半径(像素) |
border_color |
color |
— | — | — | 边框描边颜色 |
border_width |
int |
— | 0…65535 | — | 边框描边宽度(需要 border_color) |
hour_angle |
int |
— | 默认 0; 0…359 | — | 时针角度 |
minute_angle |
int |
— | 默认 0; 0…359 | — | 分针角度 |
second_angle |
int |
— | 默认 0; 0…359 | — | 秒针角度 |
hour_color |
color |
— | — | — | 时针颜色 |
minute_color |
color |
— | — | — | 分针颜色 |
second_color |
color |
— | — | — | 秒针颜色 |
tick_color |
color |
— | — | — | 整点刻度颜色 |
查看此控件支持的其他字段
| 字段 | 类型 | 必填 | 默认值 / 范围 | 可运行时更新 | 编译器定义 |
|---|---|---|---|---|---|
min_width |
int |
— | 0…65535 | — | 编译期最小宽度,单位像素 |
max_width |
int |
— | 0…65535 | — | 编译期最大宽度,单位像素 |
min_height |
int |
— | 0…65535 | — | 编译期最小高度,单位像素 |
max_height |
int |
— | 0…65535 | — | 编译期最大高度,单位像素 |
layout |
enum |
— | row, column, grid |
— | 子对象自动布局:行/列/网格 |
layout_wrap |
bool |
— | 默认 false |
— | 将行/列子对象换行到其他行 |
grid_columns |
int |
— | 1…65535 | — | 网格布局的等宽列数 |
grid_column_span |
int |
— | 默认 1; 1…65535 | — | 父网格布局中的列跨度 |
gap |
int |
— | 默认 0; 0…4096 | — | 自动布局间距(像素) |
padding |
int |
— | 默认 0; 0…4096 | — | 自动布局内边距(像素) |
padding_left |
int |
— | 0…4096 | — | 行布局起始内边距覆盖值 |
padding_right |
int |
— | 0…4096 | — | 行布局末尾内边距覆盖值 |
padding_top |
int |
— | 0…4096 | — | 列布局起始内边距覆盖值 |
padding_bottom |
int |
— | 0…4096 | — | 列布局末尾内边距覆盖值 |
grow |
int |
— | 默认 0; 0…100 | — | 自动布局扩展权重 |
margin |
int |
— | 默认 0; 0…4096 | — | 子对象两侧的自动布局外边距 |
margin_left |
int |
— | 0…4096 | — | 自动布局 x 轴起始外边距 |
margin_right |
int |
— | 0…4096 | — | 自动布局 x 轴末尾外边距 |
margin_top |
int |
— | 0…4096 | — | 自动布局 y 轴起始外边距 |
margin_bottom |
int |
— | 0…4096 | — | 自动布局 y 轴末尾外边距 |
align_main |
enum |
— | start, center, end, space_between |
— | 自动布局主轴对齐方式 |
align_cross |
enum |
— | start, center, end, stretch |
— | 自动布局交叉轴对齐方式 |
dynamic_reflow |
bool |
— | 默认 false |
— | 将直接命名布局子对象自动提升为动态定位并生成 gsp_<stem>_<name>_reflow_ex 与 _scroll_attach/_scroll_reflow() 辅助函数 |
scrollable |
bool |
— | 默认 false |
— | 在 dynamic_reflow 容器上启用内置拖拽滚动辅助函数(自动开启 clip_children: true) |
scroll |
enum |
— | 默认 none; none, vertical, horizontal, auto |
— | 在 dynamic_reflow 容器上启用内置拖拽滚动的简写(自动开启 clip_children: true) |
hidden |
bool |
— | 默认 false |
是 | 初始隐藏(通过动作或 set_visible 显示) |
fg_color |
color |
— | — | — | 前景颜色(根据控件类型用于文字、旋钮、线条或标记) |
opacity |
int |
— | 默认 255; 0…255 | 场景: 不支持; 模板: 不支持 | 0–255 混合透明度 |
bg_gradient |
color |
— | — | — | 第二个渐变色标(与 bg_color 配合) |
gradient_dir |
enum |
— | 默认 vertical; vertical, horizontal |
— | 渐变方向 |
shadow_color |
color |
— | — | — | 静态硬阴影颜色 |
shadow_opacity |
int |
— | 默认 96; 0…255 | — | 静态硬阴影透明度 |
shadow_offset_x |
int |
— | -32768…32767 | — | 静态硬阴影 x 偏移 |
shadow_offset_y |
int |
— | -32768…32767 | — | 静态硬阴影 y 偏移 |
shadow_spread |
int |
— | 0…4096 | — | 静态硬阴影扩散范围(像素) |
shadow_radius |
int |
— | 0…65535 | — | 静态硬阴影圆角半径 |
border_opacity |
int |
— | 默认 255; 0…255 | — | 边框描边透明度 |
outline_color |
color |
— | — | — | 外部轮廓颜色 |
outline_width |
int |
— | 默认 0; 0…65535 | — | 外部轮廓宽度 |
outline_opacity |
int |
— | 默认 255; 0…255 | — | 外部轮廓透明度 |
outline_pad |
int |
— | 默认 0; 0…4096 | — | 元素与外部轮廓之间的间隔 |
text_line_space |
int |
— | 默认 0; 0…4096 | — | 静态文字行之间的额外间距,单位像素 |
text_vertical_align |
enum |
— | 默认 auto; auto, top, center, bottom |
— | 静态文字块的垂直对齐;auto 保留单行居中、多行顶部对齐 |
text |
string |
— | — | 是 | 静态文字内容(UTF-8) |
text_align |
enum |
— | left, center, right |
— | 文字对齐方式 |
overflow |
enum |
— | 默认 clip; clip, ellipsis |
— | 单行文字溢出方式 |
font |
path |
— | — | — | 单个对象的 TTF/OTF 字体覆盖路径 |
font_size |
int |
— | 1…255 | — | 单个对象的字体像素尺寸 |
font_charset |
string |
— | — | — | 运行时绑定文字可使用的字形;静态文字会自动加入 |
font_charset_file |
path |
— | — | — | 相对于场景的 UTF-8 字符集文件,与 font_charset 和静态文本合并 |
font_link |
enum |
— | embedded, external, auto |
— | 字体存储策略:内嵌/外部/自动 |
input |
bool |
— | 默认 false |
— | 文字输入字段:接入光标/键盘流程 |
animation_codec |
enum |
— | lossless, eaf4, eaf4_bounded, jpeg, hardware_jpeg |
— | 动画帧策略:无损增量帧、EAF4 4×4 帧间像素差分、完整 JPEG 帧,或仅在目标具备硬件解码能力时使用 JPEG |
svg_layout |
enum |
— | content, canvas |
— | SVG 部件定位:裁紧内容或保留原画布布局 |
morph_to |
path |
— | — | — | 路径结构和填充一致的 SVG 结束形状 |
morph |
int |
— | 0…100 | — | SVG 形变或位图网格位移的插值进度,单位为百分比 |
svg_element |
string |
— | — | — | SVG 元素 ID;按绘制边界导入为独立图片 |
tint |
color |
— | — | — | SVG 轮廓颜色;生成运行时颜色设置接口 |
image |
path |
— | — | 是 | 图片、动图、视频(可选 FFmpeg)或编译 SVG 的文件路径 |
video_start_ms |
int |
— | 0…4294967295 | — | 视频片段起点,单位毫秒 |
video_duration_ms |
int |
— | 1…4294967295 | — | 视频片段时长,单位毫秒;省略则导入到结尾 |
video_fit |
enum |
— | contain, cover, stretch |
— | 构建期视频宽高比适配;contain 使用黑色补边 |
video_loop_count |
int |
— | 0…65535 | — | 视频播放次数(默认 1;0 无限循环) |
video_max_decoded_bytes |
int |
— | 1…9223372036854775807 | — | 主机保留的 RGBA 像素预算(默认 256 MiB,不代表进程总内存) |
video_max_frames |
int |
— | 1…65535 | — | 最大视频解码帧数(默认 4096) |
codec |
enum |
— | raw, lossless, jpeg, auto, speed, size, store, qoi, png, rle16, rle16_a8, rle32, default, hardware_jpeg |
— | 图片编码格式 |
dither |
bool |
— | — | — | 减轻图片和动图的 RGB565 色阶;覆盖 Profile 的 image_dither |
quality |
int |
— | 1…100 | — | JPEG 质量 1–100(省略时使用 Profile 默认值) |
jpeg_quality |
int |
— | 1…100 | — | 旧版 JPEG 质量字段别名 |
compress |
bool |
— | — | — | 图片压缩开关(兼容字段;优先使用 codec) |
cache_policy |
enum |
— | mmap_direct, mmap, decode_lru, lru, preload |
— | 图片缓存策略:mmap_direct、decode_lru 或 preload |
store_scale |
number |
— | 0.05…1.0 | — | 编码时应用的预缩放比例 |
max_fps |
int |
— | 0…120 | — | 动画导入帧率上限;视频默认 30,显式 0 保留源时间戳 |
fit |
enum |
— | 默认 stretch; stretch, fill, contain, cover, native |
— | 图像适配方式,native 以原始像素大小居中绘制,并按旋转范围计算脏区 |
position_x |
number |
— | 默认 0.5; 0.0…1.0 | — | 图片适配的水平对齐位置 |
position_y |
number |
— | 默认 0.5; 0.0…1.0 | — | 图片适配的垂直对齐位置 |
rotation |
int |
— | 默认 0; -32768…32767 | 场景: 图片; 模板: 不支持 | 图片绕边界框中心顺时针旋转,支持源图透明度;超出边界框的部分会被裁剪 |
scalable |
bool |
— | 默认 false |
— | 启用运行时图片缩放 |
scale |
number |
— | 默认 1.0; 0.0625…16.0 | — | 运行时图片初始缩放比例 |
min_scale |
number |
— | 默认 0.5; 0.0625…16.0 | — | 运行时图片最小缩放比例 |
max_scale |
number |
— | 默认 4.0; 0.0625…16.0 | — | 运行时图片最大缩放比例 |
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, ...}] |
template |
identifier |
— | — | — | 将此子树声明为渲染模板 |
max_instances |
int |
— | 1…65535 | — | 同时存活模板实例的最大数量;计入自动推导的资源池需求 |
dynamic_color |
bool |
— | — | — | 模板成员公开每实例独立颜色槽 |
dynamic_image |
bool |
— | — | — | 模板图片公开每实例独立资源槽 |
hand_thickness |
int |
— | 默认 0; 0…65535 | — | 指针基础粗细 |
查看所有组件共享字段
| 字段 | 类型 | 必填 | 默认值 / 范围 | 可运行时更新 | 编译器定义 |
|---|---|---|---|---|---|
parent_name |
string |
— | — | — | 使用名称而不是索引指定父对象 |