Drawer
从底部展开可拖动的抽屉。
实时预览
正在加载预览…
参数配置
全部字段 19
DrawerOptions
Go 代码
Go
// Inside a view; c is *ui.Context, t is nui.Theme.
// Keep s (example state) outside the view. See the complete example.
nui.Button(c.Key("open"), t, "Open drawer", nui.ButtonOptions{}).OnClick(func() { s.Drawer.Open = true })
nui.Drawer(c.Key("drawer"), t, &s.Drawer, nui.DrawerOptions{ModalOptions: nui.ModalOptions{Title: "Quick actions", Dismissible: nui.Optional[bool]{}}, SnapPoints: []float32{0.5, 0.8}}, func(t nui.Theme) {
ui.Text(c, "Drag the bottom drawer handle.")
nui.Button(c.Key("close"), t, "Done", nui.ButtonOptions{}).OnClick(func() { s.Drawer.Open = false })
})使用说明
点击 Open drawer,从底部展开后拖动把手切换高度,Done 关闭。示例使用 50% 与 80% 两个停靠位置,DrawerState 在整个交互期间保持不变。
API 参考
Drawer
源码func Drawer(c *ui.Context, t Theme, s *DrawerState, o DrawerOptions, content func(Theme)) ui.ElementDrawerOptions
源码type DrawerOptions struct {
ModalOptions
// SnapPoints are ascending fractions of window height, in (0,1].
SnapPoints []float32
DismissDistance, DismissVelocity float32
OnSnap func(int)
}| 字段 | 类型 | 说明 |
|---|---|---|
Title | stringGo 零值: | 标题文字。 |
Description | stringGo 零值: | 补充说明文字。 |
CloseLabel | stringGo 零值: | 关闭操作的可访问名称。 |
Width | Optional[float32]Go 零值: | 宽度,单位为 DIP。 |
MaxHeight | Optional[float32]Go 零值: | 最大高度,单位为 DIP。 |
Dismissible | Optional[bool]Go 零值: | 允许 Escape 或外部点击关闭。 |
CloseButton | Optional[bool]Go 零值: | 显示关闭按钮。 |
Overlay | Optional[bool]Go 零值: | 控制遮罩或边缘渐隐层。 |
Fullscreen | boolGo 零值: | 让弹层填满窗口。 |
Header | func(*ui.Context, Theme)Go 零值: | 同步构建标题区域。 |
Footer | func(*ui.Context, Theme)Go 零值: | 同步构建底部区域。 |
OnClose | func()Go 零值: | 关闭组件时通知应用的回调。 |
ReturnFocus | *ui.HandleGo 零值: | 关闭后恢复焦点的持久 Handle。 |
UI | StylesGo 零值: | 以部件名称为键覆盖外观和间距。 |
Style | func(Slot, ui.Element)Go 零值: | 同步配置当前构建的部件;不要保留 Element。 |
SnapPoints | []float32Go 零值: | 从小到大的抽屉高度比例,范围 (0,1]。 |
DismissDistance | float32Go 零值: | 拖动关闭所需的距离阈值。 |
DismissVelocity | float32Go 零值: | 拖动关闭所需的速度阈值。 |
OnSnap | func(int)Go 零值: | 抽屉吸附位置变化时通知应用的回调。 |