responsive

package
v1.0.31-alpha.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 3 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Responsive

func Responsive(bps ...Breakpoint) base.Element

Responsive renders different views depending on the available width. Breakpoints are evaluated in order and the first match wins, so list the narrowest first and a fallback without MaxWidth last:

giode.Responsive(
	giode.Breakpoint{MaxWidth: 600, Name: "compact", View: phoneView},
	giode.Breakpoint{MaxWidth: 1024, Name: "medium", View: tabletView},
	giode.Breakpoint{View: desktopView},
)

Only the matching view is built each frame. MaxWidth is in dp and is compared with the width the parent container makes available, not the window's. Components inside the chosen view can ask which breakpoint matched with ActiveBreakpoint or Compact instead of having a flag passed down to them.

Types

type Breakpoint

type Breakpoint struct {
	// MaxWidth is the widest available width, in dp, that matches.
	MaxWidth int
	// Width is the widest available width in physical pixels.
	//
	// Deprecated: pixels depend on the display density, so a layout
	// tuned on a desktop switches at a different size on a phone. Use
	// MaxWidth, which is in dp. Width applies only when MaxWidth is 0.
	Width int
	// Name identifies the breakpoint to the content of its view
	// through ActiveBreakpoint while the view is laid out. Optional.
	Name string
	View func() base.Element
}

Breakpoint is a simplified media query: it matches when the available width is at most MaxWidth dp. A breakpoint with neither MaxWidth nor Width set always matches and can serve as the fallback when listed last.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL