列表
虚拟列表,共 count 行,每行等高。可见的行用 List::show 声明。
ui.list基本用法
ui.list(1000).row_height(24).h(120).bordered().rounded_md().show(|ui, i| { ui.row().px(10).h_fill().children(|ui| { ui.text(format_args!("Row {i} of 1000")).text_sm(); });});一行里有多个组件
ui.list(1000).row_height(32).h(128).show(|ui, i| { ui.row().w_fill().px(8).gap(8).children(|ui| { ui.icon(IconName::File); ui.text(format_args!("File {i}")); ui.spacer(); ui.text(format_args!("{} KB", 4 + i)).text_sm().muted(); });});接口
| 设置 | 说明 |
|---|---|
.row_height(height: impl Length) | 行高,单位是逻辑像素。默认用主题的行高。 |
.w(width: impl Into<Sizing>) | 宽度;直接写长度就是固定宽度。 |
.h(height: impl Into<Sizing>) | 高度;直接写长度就是固定高度。 |
.h_fill() | 占满剩余高度。 |
.fill() | 占满剩余的宽度和高度。 |
.bordered() | 1 逻辑像素宽的边框,颜色为主题的 border。 |
.rounded_md() | 主题的控件圆角 radius。 |
.style(style: Style) | 用 style 替换列表的样式。 |
.show(row: impl FnMut(&mut Ui<'a>, usize)) | 放入列表,返回交互结果。只为可见的行调用 row,每行以序号为键。不管滚动到哪里,都只构建、布局和绘制一屏的行。 |