Container
限制内容宽度并提供水平留白。
实时预览
正在加载预览…
参数配置
全部字段 4
ContainerOptions
Go 代码
Go
// Inside a view; c is *ui.Context, t is nui.Theme.
nui.Container(c.Key("container"), t, nui.ContainerOptions{MaxWidth: nui.Set(float32(480)), Padding: nui.Set(float32(16))}, func() {
nui.Card(c.Key("card"), t, nui.CardOptions{Title: "Contained content"}, func() { ui.Text(c, "Resize the browser to see the width constraint.") })
})使用说明
调整 MaxWidth 和 Padding,再缩窄浏览器查看内容如何受到宽度约束。这些尺寸使用 DIP;通过 nui.Set(0) 可以明确取消留白,而不是使用未设置的默认值。
API 参考
Container
源码func Container(c *ui.Context, t Theme, opts ContainerOptions, children func()) ui.ElementContainerOptions
源码type ContainerOptions struct {
MaxWidth, Padding Optional[float32]
Decoration
}| 字段 | 类型 | 说明 |
|---|---|---|
MaxWidth | Optional[float32]Go 零值: | 最大宽度,单位为 DIP。 |
Padding | Optional[float32]Go 零值: | 容器内边距,单位为 DIP。 |
UI | StylesGo 零值: | 以部件名称为键覆盖外观和间距。 |
Style | func(Slot, ui.Element)Go 零值: | 同步配置当前构建的部件;不要保留 Element。 |