Skip to content

Background

A Background paints a stack of layers behind the content of a VStack or HStack: linear gradients and images. Each appended layer is drawn on top of the previous ones, so add the image first and a gradient for readability afterwards. For a plain color use BackgroundColor instead.

Background

return HStack(
	VStack(Text("AppendLinearGradient").Color(ColorWhite)).
		Background(Background{}.AppendLinearGradient("#1940BF", "#FA2C7F")).
		Frame(Frame{}.Size(L320, L160)).
		Border(Border{}.Radius(L16)),
	VStack(Text("two layers").Color(ColorWhite)).
		Background(Background{}.
			AppendLinearGradient("#01BA6C", "#1CCDFB").
			AppendLinearGradient("#00000000", "#000000AA"),
		).
		Frame(Frame{}.Size(L320, L160)).
		Border(Border{}.Radius(L16)),
).Gap(L16).BackgroundColor(ColorCardBody).Padding(Padding{}.All(L16))

The gradients run from top to bottom. Theme colors like M5 can be used as gradient colors as well.

Methods

MethodDescription
AppendLinearGradient(colors ...Color) BackgroundAppends a gradient equally distributed between all given colors on top of the prior layers.
AppendURI(uri core.URI) BackgroundAppends the image at the given URI on top of the prior layers.
Fit(fit ObjectFit) BackgroundSets how images are fitted, e.g. FitCover or FitContain.

Related