列表(`gsp_list`)
纵向滚动列表,支持固定数据和应用数据源。
当你需要以列表形式展示或选择一组重复条目时(例如联系人列表、设置菜单),使用 List。
本地交互预览
Section titled “本地交互预览”先按兼容性页的工具命令配置 gspc 和 gsp_sim_host,再在解压后的组件或公共仓库根目录运行:
mkdir -p gsp-out/widget-previewgspc pack \ examples/usage/widgets/list/list.json \ --deployable -o gsp-out/widget-preview/list.gspbgsp_sim_host \ --bundle gsp-out/widget-preview/list.gspb --frames 0这些命令会编译当前示例,并在 ESP-GSP 模拟器中打开浏览器预览。
能完整放入视口的短 items 列表直接绘制。固定条目超过可见行数时,GSPC 会生成可回收的
行模板,需要用 (ui, NULL, NULL) 调用一次生成的 Bind Helper,由框架提供编译文字。
显式 row_template 使用应用行 Binder。保存返回的 Handle 跨场景复用;更新数据时调用
set_total、refresh,不要重复绑定。
List 生成的行按场景中的声明顺序绘制。后面声明的前景对象(如 Drawer)会覆盖在行上方。如果你有一个需要始终显示在 List 上方的覆盖层,请把它放在场景中 List 之后的位置。
活动的 List/Wheel 视口发生重叠时,从共同可见区域开始的拖动会选择后绘制的视口, 不受应用绑定顺序影响。
需要从应用代码读写的对象,请给它一个稳定的 name。GSPC 会为每个命名对象生成下方列出的类型化函数。
{"screen":"widget_list","w":480,"h":320,"screen_bg":"#101827","font":"../../../common/fonts/DejaVuSans.ttf","objects":[{"type":"list","parent":-1,"name":"devices","x":65,"y":25,"w":350,"h":270,"items":["Living room display","Kitchen sensor","Bedroom lamp","Studio speaker","Front door camera","Garage controller","Garden monitor"],"item_height":48,"snap_to_item":true,"font_size":16,"bg_color":"#142033","fg_color":"#E2E8F0","border_color":"#2D425F","border_width":1,"radius":12}]}规范示例来自 examples/usage/widgets/list/list.json。复制时请一并复制它引用的相对资源。
此场景生成的 C API
Section titled “此场景生成的 C API”const gsp_component_directory_t *const * gsp_list_docs_component_directories(uint16_t *out_count)esp_err_t gsp_widget_list_devices_animate_selected(esp_gsp_handle_t gsp, uint32_t from, uint32_t to, uint32_t duration_ms, esp_gsp_ease_t ease)esp_err_t gsp_widget_list_devices_animate_selected_to(esp_gsp_handle_t gsp, uint32_t to, uint32_t duration_ms, esp_gsp_ease_t ease)esp_err_t gsp_widget_list_devices_get_effective_visible(esp_gsp_handle_t gsp, bool *out_visible)esp_err_t gsp_widget_list_devices_get_info(esp_gsp_handle_t gsp, esp_gsp_component_info_t *out_info)esp_err_t gsp_widget_list_devices_get_selected(esp_gsp_handle_t gsp, uint32_t *out_value)esp_err_t gsp_widget_list_devices_get_value(esp_gsp_handle_t gsp, int32_t *out_value)esp_err_t gsp_widget_list_devices_play_selected(esp_gsp_handle_t gsp, uint32_t from, uint32_t to, const esp_gsp_animation_config_t *config)esp_err_t gsp_widget_list_devices_refresh(esp_gsp_handle_t gsp, esp_gsp_list_t list)esp_err_t gsp_widget_list_devices_set_selected(esp_gsp_handle_t gsp, uint32_t new_value)esp_err_t gsp_widget_list_devices_set_text( esp_gsp_handle_t gsp, esp_gsp_widget_t widget, const char *utf8)esp_err_t gsp_widget_list_devices_set_total(esp_gsp_handle_t gsp, esp_gsp_list_t list, uint32_t total)esp_err_t gsp_widget_list_devices_set_value(esp_gsp_handle_t gsp, int32_t value)esp_err_t gsp_widget_list_devices_stop_selected(esp_gsp_handle_t gsp)esp_gsp_config_t gsp_list_docs_config(void)esp_gsp_err_t gsp_widget_list_devices_row_set_text( esp_gsp_handle_t gsp, esp_gsp_row_t row, const char *utf8)esp_gsp_list_t gsp_widget_list_devices_bind( esp_gsp_handle_t gsp, esp_gsp_list_bind_cb_t bind_item, void *user_ctx)esp_gsp_widget_t gsp_widget_list_devices_create( esp_gsp_handle_t gsp, int16_t x, int16_t y)size_t gsp_list_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> |
fg_color |
color |
— | — | — | 前景颜色(根据控件类型用于文字、旋钮、线条或标记) |
bg_color |
color |
— | — | 是 | 背景/填充颜色(#RRGGBB 或 #RRGGBBAA) |
radius |
int |
— | 默认 0; 0…65535 | 场景: 不支持; 模板: 不支持 | 圆角半径(像素) |
border_color |
color |
— | — | — | 边框描边颜色 |
border_width |
int |
— | 0…65535 | — | 边框描边宽度(需要 border_color) |
font_size |
int |
— | 1…255 | — | 单个对象的字体像素尺寸 |
items |
string_list |
— | — | — | 条目文字(list/wheel/dropdown/tabview) |
item_height |
int |
— | 默认 0; 0…65535 | — | 列表/滚轮行高 |
snap_to_item |
bool |
— | 默认 false |
— | 滚动结束时吸附到行边界 |
查看此控件支持的其他字段
| 字段 | 类型 | 必填 | 默认值 / 范围 | 可运行时更新 | 编译器定义 |
|---|---|---|---|---|---|
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 显示) |
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_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 | — | 运行时图片最大缩放比例 |
selected |
int |
— | 默认 0; 0…65535 | 是 | 初始选中条目索引 |
items_per_page |
int |
— | 默认 0; 0…65535 | — | TabView 每页条目数 |
visible_rows |
int |
— | 默认 0; 0…65535 | — | 可见行数(item_height 的替代配置) |
row_template |
identifier |
— | — | — | 复用的行模板 |
item_count |
int |
— | 0…4294967295 | — | 动态条目初始数量 |
scroll_snapshot |
bool |
— | 默认 false |
— | 滚动时缓存两个视口帧;内存不足时回退到实时渲染 |
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 |
— | — | — | 模板图片公开每实例独立资源槽 |
查看所有组件共享字段
| 字段 | 类型 | 必填 | 默认值 / 范围 | 可运行时更新 | 编译器定义 |
|---|---|---|---|---|---|
parent_name |
string |
— | — | — | 使用名称而不是索引指定父对象 |