按钮
用途
ui.themes.widgets.button 替代原生 Button。三种变体取 theme.button 令牌:
| variant | 样子 | 用在 |
|---|---|---|
normal(缺省) | 描边或浅底 | 取消、次要动作 |
primary | 实心反色 | 一扇窗里那个确定动作,只给一个 |
ghost | 无底无边 | 标题栏、翻页条图标 |
可以只给 text、只给 icon,或两者都给。trailing = true 时图标放在文字后(下拉 chip:text = "全部", icon = "arrow_drop_down")。
主要参数
| 字段 | 作用 |
|---|---|
text / icon | 文案、Material Symbols 名 |
variant | normal / primary / ghost |
width / height | 物理像素。缺省宽按内容加左右内边距,高取 control.height |
size | "small" 是工具条紧凑规格(caption 字号、小图标、小内边距) |
enabled | false 时文字与边框改 disabled 色,点按和长按都被吞掉,不会回调 |
callback / hold_callback | 点按、长按,互不影响 |
Button.heightOf(size) | 查询某种尺寸的高度 |
和三种风格的差异
纸本、高对比的普通按钮是白底黑边(高对比边更粗、按钮更高)。柔和普通按钮是浅灰底、同色边、胶囊圆角(control.radius=999)。三套的主按钮在灰度下都是黑底白字;打开彩色后改为主题色底、白字。
示例
local Button = require("ui.themes.widgets.button")Button:new{ text = _("确定"), variant = "primary", callback = on_ok }Button:new{ text = _("取消"), callback = on_cancel }Button:new{ icon = "close", variant = "ghost", callback = on_close }Button:new{ text = _("筛选"), icon = "arrow_drop_down", trailing = true, size = "small", callback = open_filters,}本文已加密,请输入访问密码