Container

限制内容宽度并提供水平留白。

实时预览

正在加载预览…

参数配置

全部字段 4

ContainerOptions

Styles · 0

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.Element

ContainerOptions

源码
type ContainerOptions struct {
	MaxWidth, Padding Optional[float32]
	Decoration
}
字段类型说明
MaxWidthOptional[float32]

Go 零值: unset

最大宽度,单位为 DIP。

PaddingOptional[float32]

Go 零值: unset

容器内边距,单位为 DIP。

UIStyles

Go 零值: zero value

以部件名称为键覆盖外观和间距。

Stylefunc(Slot, ui.Element)

Go 零值: nil

同步配置当前构建的部件;不要保留 Element。