v0.4.0 Latest Latest

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

Go to latest
Published: Nov 29, 2023 License: MIT, Unlicense Imports: 20 Imported by: 103



Go Reference

This package provides various material design components for gio.


This package has no stable API, and should always be locked to a particular commit with go modules.

The included components attempt to conform to the material design specifications whenever possible, but they may not support unusual style tweaks or especially exotic configurations.

Implemented Components

The list of currently-Implemented components follows:

Navigation Drawer (static and modal)

The navigation drawer specified here is mostly implemented by the type NavDrawer, and the modal variant can be created with a ModalNavDrawer. The modal variant looks like this:

modal navigation drawer example screenshot


  • Animated drawer open/close.
  • Navigation items respond to hovering.
  • Navigation selection is animated.
  • Navigation item icons are optional.
  • Content can be anchored to the bottom of the drawer for pairing with a bottom app bar.

Modal features:

  • Swipe or touch scrim to close the drawer.

Known issues:

  • API targets a fairly static and simplistic menu. Sub-sections with dividers are not yet supported. An API-driven way to traverse the current menu options is also not yet supported. Contributions welcome!
App Bar (Top and Bottom)

The App Bar specified here is mostly implemented by the type AppBar. It looks like this:

Normal state:

modal navigation drawer example screenshot

Contextual state:

modal navigation drawer example screenshot


  • Action buttons and overflow menu contents can be changed easily.
  • Overflow button disappears when no items overflow.
  • Overflow menu can be dismissed by touching the scrim outside of it.
  • Action items disapper into overflow when screen is too narrow to fit them. This is animated.
  • Navigation button icon is customizable, and the button is not drawn if no icon is provided.
  • Contextual app bar can be triggered and dismissed programatically.
  • Bar supports use as a top and bottom app bar (animates the overflow menu in the proper direction).

Known Issues:

  • Compact and prominent App Bars are not yet implemented.
Side sheet (static and modal)

Side sheets (specified here) are implemented by the Sheet and ModalSheet types.


  • Animated appear/disappear

Modal features:

  • Swipe to close
  • Touch scrim to close

Known Issues:

  • Only sheets anchored on the left are currently supported (contributions welcome!)
Text Fields

Text Fields (specified here) are implemented by the TextField type.


  • Animated label transition when selected
  • Responds to hover events
  • Exposes underlying gio editor

Known Issues:

  • Icons, hint text, error text, prefix/suffix, and other features are not yet implemented.

The Divider type implements material dividers. You can customize the insets embedded in the type to change which kind of divider it is. Use the constructor functions to create nice defaults.


The Surface type is a rounded rectangle with a background color and a drop shadow. This isn't a material component per se, but is a useful building block nonetheless.


The Menu type defines contextual menus as described here.

first menu example screenshot

Known issues:

  • Does not support nested submenus (yet).

The MenuItem type provides widgets suitable for use within the Menu, though any widget can be used. Here are some MenuItems in action:

second menu example screenshot


The ContextArea type is a helper type that defines an area that accepts right-clicks. This area will display a widget when clicked (anchored at the click position). The displayed widget is overlaid on other content, and is therefore useful in displaying contextual menus.

Known issues:

  • the heuristic that ContextArea uses to attempt to avoid off-screen drawing of its contextual content can fail or backfire. Suggestions for improving this are welcome.

The Tooltip, TipArea, and TipIconButtonStyle types define a tooltip, a contextual area for displaying tooltips (on hover and long-press), and a wrapper around material.IconButtonStyle that provides a tooltip for the button.

tooltip example screenshot



Package component provides material design UI components as described by



This section is empty.


This section is empty.


func DividerSubheadingText

func DividerSubheadingText(th *material.Theme, label string) material.LabelStyle

DividerSubheadingText returns a LabelStyle suitable for use as a subheading in a divider.

func Interpolate

func Interpolate(a, b color.NRGBA, progress float32) color.NRGBA
func MenuHintText(th *material.Theme, label string) material.LabelStyle

MenuHintText returns a LabelStyle suitable for use as hint text in a MenuItemStyle.

func SimpleIconButton

func SimpleIconButton(bg, fg color.NRGBA, state *widget.Clickable, icon *widget.Icon) material.IconButtonStyle

SimpleIconButton creates an IconButtonStyle that is pre-configured to be the right size for use as an AppBarAction

func SwapGrounds

func SwapGrounds(p material.Palette) material.Palette

SwapGrounds swaps the foreground and background colors of both the contrast and non-constrast colors.

Bg <-> Fg ContrastBg <-> ContrastFg

func SwapPairs

func SwapPairs(p material.Palette) material.Palette

SwapPairs swaps the contrast and non-constrast colors.

Bg <-> ContrastBg Fg <-> ContrastFg

func WithAlpha

func WithAlpha(c color.NRGBA, a uint8) color.NRGBA

WithAlpha returns the input color with the new alpha value.


type AlphaPalette

type AlphaPalette struct {
	Hover, Selected uint8

AlphaPalette is the set of alpha values to be applied for certain material design states like hover, selected, etc...

type AppBar

type AppBar struct {
	NavigationButton       widget.Clickable
	NavigationIcon         *widget.Icon
	Title, ContextualTitle string
	// The modal layer is used to lay out the overflow menu. The nav
	// bar is not functional if this field is not supplied.
	// Anchor indicates whether the app bar is anchored at the
	// top or bottom edge of the interface. It defaults to Top, and
	// is used to orient the layout of menus relative to the bar.
	Anchor VerticalAnchorPosition
	// contains filtered or unexported fields

AppBar implements the material design App Bar documented here:

TODO(whereswaldon): implement support for RTL layouts

func NewAppBar

func NewAppBar(modal *ModalLayer) *AppBar

NewAppBar creates and initializes an App Bar.

func (*AppBar) CloseOverflowMenu

func (a *AppBar) CloseOverflowMenu(when time.Time)

CloseOverflowMenu requests that the overflow menu be closed if it is open.

func (*AppBar) Events

func (a *AppBar) Events(gtx layout.Context) []AppBarEvent

Events returns a slice of all AppBarActions to occur since the last frame.

func (*AppBar) Layout

func (a *AppBar) Layout(gtx layout.Context, theme *material.Theme, navDesc, overflowDesc string) layout.Dimensions

Layout renders the app bar. It will span all available horizontal space (gtx.Constraints.Max.X), but has a fixed height. The navDesc is an accessibility description for the navigation icon button, and the overflowDesc is an accessibility description for the overflow action button.

func (*AppBar) SetActions

func (a *AppBar) SetActions(actions []AppBarAction, overflows []OverflowAction)

SetActions configures the set of actions available in the action item area of the app bar. They will be displayed in the order provided (from left to right) and will collapse into the overflow menu from right to left. The provided OverflowActions will always be in the overflow menu in the order provided.

func (*AppBar) SetContextualActions

func (a *AppBar) SetContextualActions(actions []AppBarAction, overflows []OverflowAction)

SetContextualActions configures the actions that should be available in the next Contextual mode that this action bar enters.

func (*AppBar) StartContextual

func (a *AppBar) StartContextual(when time.Time, title string)

StartContextual causes the AppBar to transform into a contextual App Bar with a different set of actions than normal. If the App Bar is already in contextual mode, this has no effect. The title will be used as the contextual app bar title.

func (*AppBar) StopContextual

func (a *AppBar) StopContextual(when time.Time)

StopContextual causes the AppBar to stop showing a contextual menu if one is currently being displayed.

func (*AppBar) ToggleContextual

func (a *AppBar) ToggleContextual(when time.Time, title string)

ToggleContextual switches between contextual an noncontextual mode. If it transitions to contextual mode, the provided title is used.

type AppBarAction

type AppBarAction struct {
	Layout func(gtx layout.Context, bg, fg color.NRGBA) layout.Dimensions

AppBarAction configures an action in the App Bar's action items. The embedded OverflowAction provides the action information for when this item disappears into the overflow menu.

func SimpleIconAction

func SimpleIconAction(state *widget.Clickable, icon *widget.Icon, overflow OverflowAction) AppBarAction

SimpleIconAction configures an AppBarAction that functions as a simple IconButton. To receive events from the button, use the standard methods on the provided state parameter.

type AppBarContextMenuDismissed

type AppBarContextMenuDismissed struct{}

AppBarContextMenuDismissed indicates that the app bar context menu was dismissed during the last frame.

func (AppBarContextMenuDismissed) AppBarEvent

func (a AppBarContextMenuDismissed) AppBarEvent()

func (AppBarContextMenuDismissed) String

type AppBarEvent

type AppBarEvent interface {


type AppBarNavigationClicked

type AppBarNavigationClicked struct{}

AppBarNavigationClicked indicates that the navigation icon was clicked during the last frame.

func (AppBarNavigationClicked) AppBarEvent

func (a AppBarNavigationClicked) AppBarEvent()

func (AppBarNavigationClicked) String

func (a AppBarNavigationClicked) String() string

type AppBarOverflowActionClicked

type AppBarOverflowActionClicked struct {
	Tag interface{}

AppBarOverflowActionClicked indicates that an action in the app bar overflow menu was clicked during the last frame.

func (AppBarOverflowActionClicked) AppBarEvent

func (a AppBarOverflowActionClicked) AppBarEvent()

func (AppBarOverflowActionClicked) String

type C

type C = layout.Context

type ContextArea

type ContextArea struct {

	// Activation is the pointer Buttons within the context area
	// that trigger the presentation of the contextual widget. If this
	// is zero, it will default to pointer.ButtonSecondary.
	Activation pointer.Buttons
	// AbsolutePosition will position the contextual widget in the
	// relative to the position of the context area instead of relative
	// to the position of the click event that triggered the activation.
	// This is useful for controls (like button-activated menus) where
	// the contextual content should not be precisely attached to the
	// click position, but should instead be attached to the button.
	AbsolutePosition bool
	// PositionHint tells the ContextArea the closest edge/corner of the
	// window to where it is being used in the layout. This helps it to
	// position the contextual widget without it overflowing the edge of
	// the window.
	PositionHint layout.Direction
	// contains filtered or unexported fields

ContextArea is a region of the UI that responds to certain pointer events by displaying a contextual widget. The contextual widget is overlaid using an op.DeferOp. The contextual widget can be dismissed by primary-clicking within or outside of it.

func (*ContextArea) Activated

func (r *ContextArea) Activated() bool

Activated returns true if the context area has become active since the last call to Activated.

func (ContextArea) Active

func (r ContextArea) Active() bool

Active returns whether the ContextArea is currently active (whether it is currently displaying overlaid content or not).

func (*ContextArea) Dismiss

func (r *ContextArea) Dismiss()

Dismiss sets the ContextArea to not be active.

func (*ContextArea) Dismissed

func (r *ContextArea) Dismissed() bool

Dismissed returns true if the context area has been dismissed since the last call to Dismissed.

func (*ContextArea) Layout

func (r *ContextArea) Layout(gtx C, w layout.Widget) D

Layout renders the context area and -- if the area is activated by an appropriate gesture -- also the provided widget overlaid using an op.DeferOp.

func (*ContextArea) Update

func (r *ContextArea) Update(gtx C)

Update performs event processing for the context area but does not lay it out. It is automatically invoked by Layout() if it has not already been called during a given frame.

type D

type D = layout.Dimensions

type DiscloserArrowStyle

type DiscloserArrowStyle struct {
	Color color.NRGBA
	Size  unit.Dp
	State *DiscloserState
	Margin layout.Inset

DiscloserArrowStyle defines the presentation of a simple triangular Discloser control that rotates downward as the content is revealed.

func DiscloserArrow

func DiscloserArrow(th *material.Theme, style DiscloserStyle) DiscloserArrowStyle

DiscloserArrow creates and configures a DiscloserArrow for use with the provided DiscloserStyle.

func (DiscloserArrowStyle) DetailInset

func (d DiscloserArrowStyle) DetailInset() layout.Inset

DetailInset returns a layout.Inset that can be used to align a Discloser's details with its summary.

func (DiscloserArrowStyle) Layout

func (d DiscloserArrowStyle) Layout(gtx C) D

Layout the arrow.

func (DiscloserArrowStyle) Width

func (d DiscloserArrowStyle) Width() unit.Dp

Width returns the width of the arrow and surrounding whitespace.

type DiscloserState

type DiscloserState struct {

DiscloserState holds state for a widget that can hide and reveal content.

func (*DiscloserState) Layout

func (d *DiscloserState) Layout(gtx C) D

Layout updates the state of the Discloser.

type DiscloserStyle

type DiscloserStyle struct {
	// ControlSide defines whether the control widget is drawn to the
	// left or right of the summary widget.
	ControlSide Side

DiscloserStyle defines the presentation of a discloser widget.

func Discloser

func Discloser(th *material.Theme, state *DiscloserState) DiscloserStyle

Discloser configures a discloser from the provided theme and state.

func (DiscloserStyle) Layout

func (d DiscloserStyle) Layout(gtx C, control, summary, detail layout.Widget) D

Layout the discloser with the provided toggle control, summary widget, and detail widget. The toggle widget will be wrapped in a clickable area automatically.

The structure of the resulting discloser is:

control | summary

If d.ControlSide is set to Right, the control will appear after the summary instead of before it.

type DividerStyle

type DividerStyle struct {
	Thickness unit.Dp
	Fill      color.NRGBA

	Subheading      material.LabelStyle
	SubheadingInset layout.Inset

DividerStyle defines the presentation of a material divider, as specified here:

func Divider

func Divider(th *material.Theme) DividerStyle

Divider creates a simple full-bleed divider.

func SubheadingDivider

func SubheadingDivider(th *material.Theme, subheading string) DividerStyle

SubheadingDivider creates a full-bleed divider with a subheading.

func (DividerStyle) Layout

func (d DividerStyle) Layout(gtx C) D

Layout renders the divider. If gtx.Constraints.Min.X is zero, it will have zero size and render nothing.

type GridState

type GridState struct {
	VScrollbar widget.Scrollbar
	HScrollbar widget.Scrollbar

Grid holds the persistent state for a layout.List that has a scrollbar attached.

type GridStyle

type GridStyle struct {
	State           *GridState
	VScrollbarStyle material.ScrollbarStyle
	HScrollbarStyle material.ScrollbarStyle

GridStyle is the persistent state for the grid.

func Grid

func Grid(th *material.Theme, state *GridState) GridStyle

Grid makes a grid with its persistent state.

func (GridStyle) Layout

func (g GridStyle) Layout(gtx layout.Context, rows, cols int, dimensioner outlay.Dimensioner, cellFunc outlay.Cell) layout.Dimensions

Layout will draw a grid, using fixed column widths and row height.

type InvalidateDeadline

type InvalidateDeadline struct {
	// The time at which a frame needs to be drawn.
	Target time.Time
	// Whether the deadline is active.
	Active bool

InvalidateDeadline helps to ensure that a frame is generated at a specific point in time in the future. It does this by always requesting a future invalidation at its target time until it reaches its target time. This makes animating delays much cleaner.

func (*InvalidateDeadline) ClearTarget

func (i *InvalidateDeadline) ClearTarget()

ClearTarget cancels a request to invalidate in the future.

func (*InvalidateDeadline) Process

func (i *InvalidateDeadline) Process(gtx C) bool

Process checks the current frame time and either requests a future invalidation or does nothing. It returns whether the current frame is the frame requested by the last call to SetTarget.

func (*InvalidateDeadline) SetTarget

func (i *InvalidateDeadline) SetTarget(t time.Time)

SetTarget configures a specific time in the future at which a frame should be rendered.

type MenuItemStyle struct {
	State      *widget.Clickable
	HoverColor color.NRGBA

	LabelInset outlay.Inset
	Label      material.LabelStyle

	IconSize  unit.Dp
	IconInset outlay.Inset
	IconColor color.NRGBA

	Hint      material.LabelStyle
	HintInset outlay.Inset

MenuItemStyle defines the presentation of a Menu element that has a label and optionally an icon and a hint text.

func MenuItem(th *material.Theme, state *widget.Clickable, label string) MenuItemStyle

MenuItem constructs a default MenuItemStyle based on the theme, state, and label.

func (m MenuItemStyle) Layout(gtx C) D

Layout renders the MenuItemStyle. If gtx.Constraints.Min.X is zero, it will render itself to be as compact as possible horizontally.

type MenuState struct {
	OptionList layout.List
	Options    []func(gtx C) D

MenuState holds the state of a menu material design component across frames.

type MenuStyle struct {
	// Inset applied around the rendered contents of the state's Options field.

MenuStyle defines the presentation of a material design menu component.

func Menu(th *material.Theme, state *MenuState) MenuStyle

Menu constructs a menu with the provided state and a default Surface behind it.

func (m MenuStyle) Layout(gtx C) D

Layout renders the menu.

type ModalLayer

type ModalLayer struct {
	Widget func(gtx layout.Context, th *material.Theme, anim *VisibilityAnimation) layout.Dimensions

ModalLayer is a widget drawn on top of the normal UI that can be populated by other material components with dismissble modal dialogs. For instance, the App Bar can render its overflow menu within the modal layer, and the modal navigation drawer is entirely within the modal layer.

func NewModal

func NewModal() *ModalLayer

NewModal creates an initializes a modal layer.

func (*ModalLayer) Layout

func (m *ModalLayer) Layout(gtx layout.Context, th *material.Theme) layout.Dimensions

Layout renders the modal layer. Unless a modal widget has been triggered, this will do nothing.

type ModalNavDrawer

type ModalNavDrawer struct {
	// contains filtered or unexported fields

ModalNavDrawer implements the Material Design Modal Navigation Drawer described here:

func ModalNavFrom

func ModalNavFrom(nav *NavDrawer, modal *ModalLayer) *ModalNavDrawer

func NewModalNav

func NewModalNav(modal *ModalLayer, title, subtitle string) *ModalNavDrawer

NewModalNav configures a modal navigation drawer that will render itself into the provided ModalLayer

func (*ModalNavDrawer) Appear

func (m *ModalNavDrawer) Appear(when time.Time)

func (*ModalNavDrawer) Disappear

func (m *ModalNavDrawer) Disappear(when time.Time)

func (*ModalNavDrawer) Layout

func (m *ModalNavDrawer) Layout() layout.Dimensions

func (*ModalNavDrawer) ToggleVisibility

func (m *ModalNavDrawer) ToggleVisibility(when time.Time)

type ModalSheet

type ModalSheet struct {
	// MaxWidth constrains the maximum amount of horizontal screen real-estate
	// covered by the drawer. If the screen is narrower than this value, the
	// width will be inferred by reserving space for the scrim and using the
	// leftover area for the drawer. Values between 200 and 400 Dp are recommended.
	// The default value used by NewModalNav is 400 Dp.
	MaxWidth unit.Dp

	Modal *ModalLayer

	// contains filtered or unexported fields

ModalSheet implements the Modal Side Sheet component specified at

func NewModalSheet

func NewModalSheet(m *ModalLayer) *ModalSheet

NewModalSheet creates a modal sheet that can render a widget on the modal layer.

func (*ModalSheet) Appear

func (s *ModalSheet) Appear(when time.Time)

Appear triggers the appearance of the ModalSheet.

func (*ModalSheet) Disappear

func (s *ModalSheet) Disappear(when time.Time)

Disappear triggers the appearance of the ModalSheet.

func (*ModalSheet) LayoutModal

func (s *ModalSheet) LayoutModal(contents func(gtx layout.Context, th *material.Theme, anim *VisibilityAnimation) layout.Dimensions)

ConfigureModal requests that the sheet prepare the associated ModalLayer to render itself (rather than another modal widget).

func (*ModalSheet) ToggleVisibility

func (s *ModalSheet) ToggleVisibility(when time.Time)

ToggleVisibility triggers the appearance or disappearance of the ModalSheet.

type ModalState

type ModalState struct {
	// contains filtered or unexported fields

ModalState defines persistent state for a modal.

func (*ModalState) Show

func (m *ModalState) Show(now time.Time, w layout.Widget)

Show widget w in the modal, starting animation at now.

type ModalStyle

type ModalStyle struct {
	Scrim ScrimStyle

ModalStyle describes how to layout a modal. Modal content is layed centered atop a clickable scrim.

func Modal(th *material.Theme, modal *ModalState) ModalStyle

Modal lays out a content widget atop a clickable scrim. Clicking the scrim dismisses the modal.

func (ModalStyle) Layout

func (m ModalStyle) Layout(gtx C) D

Layout the scrim and content. The content is only laid out once the scrim is fully animated in, and is hidden on the first frame of the scrim's fade-out animation.

type NavDrawer struct {

	Title    string
	Subtitle string

	// Anchor indicates whether content in the nav drawer should be anchored to
	// the upper or lower edge of the drawer. This value should match the anchor
	// of an app bar if an app bar is used in conjunction with this nav drawer.
	Anchor VerticalAnchorPosition
	// contains filtered or unexported fields

NavDrawer implements the Material Design Navigation Drawer described here:

func NewNav

func NewNav(title, subtitle string) NavDrawer

NewNav configures a navigation drawer

func (m *NavDrawer) AddNavItem(item NavItem)

AddNavItem inserts a navigation target into the drawer. This should be invoked only from the layout thread to avoid nasty race conditions.

func (m *NavDrawer) CurrentNavDestination() interface{}

CurrentNavDestination returns the tag of the navigation destination selected in the drawer.

func (m *NavDrawer) LayoutContents(gtx layout.Context, th *material.Theme, anim *VisibilityAnimation) layout.Dimensions
func (m *NavDrawer) NavDestinationChanged() bool

NavDestinationChanged returns whether the selected navigation destination has changed since the last frame.

func (m *NavDrawer) SetNavDestination(tag interface{})

SetNavDestination changes the selected navigation item to the item with the provided tag. If the provided tag does not exist, it has no effect.

func (m *NavDrawer) UnselectNavDestination()
type NavItem struct {
	// Tag is an externally-provided identifier for the view
	// that this item should navigate to. It's value is
	// opaque to navigation elements.
	Tag  interface{}
	Name string

	// Icon, if set, renders the provided icon to the left of the
	// item's name. Material specifies that either all navigation
	// items should have an icon, or none should. As such, if this
	// field is nil, the Name will be aligned all the way to the
	// left. A mixture of icon and non-icon items will be misaligned.
	// Users should either set icons for all elements or none.
	Icon *widget.Icon

type OverflowAction

type OverflowAction struct {
	Name string
	Tag  interface{}

OverflowAction holds information about an action available in an overflow menu

type Progress

type Progress struct {
	// contains filtered or unexported fields

Progress is an animation primitive that tracks progress of time over a fixed duration as a float between [0, 1].

Progress is reversable.

Widgets map async UI events to state changes: stop, forward, reverse. Widgets then interpolate visual data based on progress value.

Update method must be called every tick to update the progress value.

func (Progress) Absolute

func (p Progress) Absolute() float32

Absolute reports the absolute progress, ignoring direction.

func (Progress) Direction

func (p Progress) Direction() ProgressDirection

Direction reports the current direction.

func (Progress) Finished

func (p Progress) Finished() bool

func (Progress) Progress

func (p Progress) Progress() float32

Progress reports the current progress as a float between [0, 1].

func (*Progress) Start

func (p *Progress) Start(began time.Time, direction ProgressDirection, duration time.Duration)

Start the progress in the given direction over the given duration.

func (Progress) Started

func (p Progress) Started() bool

Started reports true if progression has started.

func (*Progress) Stop

func (p *Progress) Stop()

Stop the progress.

func (*Progress) Update

func (p *Progress) Update(now time.Time)

type ProgressDirection

type ProgressDirection int

ProgressDirection specifies how to update progress every tick.

const (
	// Forward progresses from 0 to 1.
	Forward ProgressDirection = iota
	// Reverse progresses from 1 to 0.

func (ProgressDirection) String

func (d ProgressDirection) String() string

type Rect

type Rect struct {
	Color color.NRGBA
	Size  image.Point
	Radii int

func (Rect) Layout

func (r Rect) Layout(gtx C) D

type Resize

type Resize struct {
	// Axis defines how the widgets and the handle are laid out.
	Axis layout.Axis
	// Ratio defines how much space is available to the first widget.
	Ratio float32
	// contains filtered or unexported fields

Resize provides a draggable handle in between two widgets for resizing their area.

func (*Resize) Layout

func (rs *Resize) Layout(gtx layout.Context, w1, w2, handle layout.Widget) layout.Dimensions

Layout displays w1 and w2 with handle in between.

The widgets w1 and w2 must be able to gracefully resize their minimum and maximum dimensions in order for the resize to be smooth.

type Scrim

type Scrim struct {
	// FinalAlpha is the final opacity of the scrim on a scale from 0 to 255.
	FinalAlpha uint8

Scrim implments a clickable translucent overlay. It can animate appearing and disappearing as a fade-in, fade-out transition from zero opacity to a fixed maximum opacity.

func (*Scrim) Layout

Layout draws the scrim using the provided animation. If the animation indicates that the scrim is not visible, this is a no-op.

type ScrimState

type ScrimState struct {

ScrimState defines persistent state for a scrim.

type ScrimStyle

type ScrimStyle struct {
	Color      color.NRGBA
	FinalAlpha uint8

ScrimStyle defines how to layout a scrim.

func NewScrim

func NewScrim(th *material.Theme, scrim *ScrimState, alpha uint8) ScrimStyle

NewScrim allocates a ScrimStyle. Alpha is the final alpha of a fully "appeared" scrim.

func (ScrimStyle) Layout

func (scrim ScrimStyle) Layout(gtx C) D

type ShadowStyle

type ShadowStyle struct {
	// The radius of the corners of the rectangle casting the surface.
	// Non-rounded rectangles can just provide a zero.
	CornerRadius unit.Dp
	// Elevation is how high the surface casting the shadow is above
	// the background, and therefore determines how diffuse and large
	// the shadow is.
	Elevation unit.Dp
	// The colors of various components of the shadow. The Shadow()
	// constructor populates these with reasonable defaults.
	AmbientColor, PenumbraColor, UmbraColor color.NRGBA

ShadowStyle defines a shadow cast by a rounded rectangle.

TODO(whereswaldon): make this support RRects that do not have uniform corner radii.

func Shadow

func Shadow(radius, elevation unit.Dp) ShadowStyle

Shadow defines a shadow cast by a rounded rectangle with the given corner radius and elevation. It sets reasonable defaults for the shadow colors.

func (ShadowStyle) Layout

func (s ShadowStyle) Layout(gtx layout.Context) layout.Dimensions

Layout renders the shadow into the gtx. The shadow's size will assume that the rectangle casting the shadow is of size gtx.Constraints.Min.

type Sheet

type Sheet struct{}

Sheet implements the standard side sheet described here:

func NewSheet

func NewSheet() Sheet

NewSheet returns a new sheet

func (Sheet) Layout

func (s Sheet) Layout(gtx layout.Context, th *material.Theme, anim *VisibilityAnimation, widget layout.Widget) layout.Dimensions

Layout renders the provided widget on a background. The background will use the maximum space available.

type Side

type Side bool

Side represents a preference for left or right.

const (
	Left  Side = false
	Right Side = true

type SimpleDiscloserStyle

type SimpleDiscloserStyle struct {

SimpleDiscloserStyle configures a default discloser that uses a simple rotating triangle control and indents its details.

func SimpleDiscloser

func SimpleDiscloser(th *material.Theme, state *DiscloserState) SimpleDiscloserStyle

SimpleDiscloser creates a SimpleDiscloserStyle for the given theme and DiscloserState.

func (SimpleDiscloserStyle) Layout

func (sd SimpleDiscloserStyle) Layout(gtx C, summary, details layout.Widget) D

Layout the discloser with the provided summary and detail widget content.

type SurfaceStyle

type SurfaceStyle struct {
	// The CornerRadius and Elevation fields of the embedded shadow
	// style also define the corner radius and elevation of the card.
	// Theme background color will be used if empty.
	Fill color.NRGBA

SurfaceStyle defines the visual aspects of a material design surface with (optionally) rounded corners and a drop shadow.

func Surface

func Surface(th *material.Theme) SurfaceStyle

Surface creates a Surface style for the provided theme with sensible default elevation and rounded corners.

func (SurfaceStyle) Layout

func (c SurfaceStyle) Layout(gtx C, w layout.Widget) D

Layout renders the SurfaceStyle, taking the dimensions of the surface from gtx.Constraints.Min.

type TableStyle

type TableStyle GridStyle

TableStyle is the persistent state for a table with heading and grid.

func Table

func Table(th *material.Theme, state *GridState) TableStyle

Table makes a grid with its persistent state.

func (TableStyle) Layout

func (t TableStyle) Layout(gtx layout.Context, rows, cols int, dimensioner outlay.Dimensioner, headingFunc layout.ListElement, cellFunc outlay.Cell) layout.Dimensions

Layout will draw a table with a heading, using fixed column widths and row height.

type TextField

type TextField struct {
	// Editor contains the edit buffer.

	// Helper text to give additional context to a field.
	Helper string
	// CharLimit specifies the maximum number of characters the text input
	// will allow. Zero means "no limit".
	CharLimit uint
	// Prefix appears before the content of the text input.
	Prefix layout.Widget
	// Suffix appears after the content of the text input.
	Suffix layout.Widget
	// contains filtered or unexported fields

TextField implements the Material Design Text Field described here:

func (*TextField) Clear

func (in *TextField) Clear()

Clear the input text and reset any error status.

func (*TextField) ClearError

func (in *TextField) ClearError()

ClearError clears any errored status.

func (TextField) IsActive

func (in TextField) IsActive() bool

IsActive if input is in an active state (Active, Focused or Errored).

func (*TextField) IsErrored

func (in *TextField) IsErrored() bool

IsErrored if input is in an errored state. Typically this is when the validator has returned an error message.

func (*TextField) Layout

func (in *TextField) Layout(gtx C, th *material.Theme, hint string) D

func (*TextField) SetError

func (in *TextField) SetError(err string)

SetError puts the input into an errored state with the specified error text.

func (*TextField) TextTooLong

func (in *TextField) TextTooLong() bool

TextTooLong returns whether the current editor text exceeds the set character limit.

func (*TextField) Update

func (in *TextField) Update(gtx C, th *material.Theme, hint string)

type TipArea

type TipArea struct {
	Hover     InvalidateDeadline
	Press     InvalidateDeadline
	LongPress InvalidateDeadline

	// HoverDelay is the delay between the cursor entering the tip area
	// and the tooltip appearing.
	HoverDelay time.Duration
	// LongPressDelay is the required duration of a press in the area for
	// it to count as a long press.
	LongPressDelay time.Duration
	// LongPressDuration is the amount of time the tooltip should be displayed
	// after being triggered by a long press.
	LongPressDuration time.Duration
	// FadeDuration is the amount of time it takes the tooltip to fade in
	// and out.
	FadeDuration time.Duration
	// contains filtered or unexported fields

TipArea holds the state information for displaying a tooltip. The zero value will choose sensible defaults for all fields.

func (*TipArea) Layout

func (t *TipArea) Layout(gtx C, tip Tooltip, w layout.Widget) D

Layout renders the provided widget with the provided tooltip. The tooltip will be summoned if the widget is hovered or long-pressed.

type TipIconButtonStyle

type TipIconButtonStyle struct {
	State *TipArea

TipIconButtonStyle lays out an IconButton with a tooltip configured.

func TipIconButton

func TipIconButton(th *material.Theme, area *TipArea, button *widget.Clickable, label string, icon *widget.Icon) TipIconButtonStyle

TipIconButton creates a TipIconButtonStyle.

func (TipIconButtonStyle) Layout

func (t TipIconButtonStyle) Layout(gtx C) D

Layout renders the TipIconButton.

type Tooltip

type Tooltip struct {
	// Inset defines the interior padding of the Tooltip.
	// CornerRadius defines the corner radius of the RRect background.
	// of the tooltip.
	CornerRadius unit.Dp
	// Text defines the content of the tooltip.
	Text material.LabelStyle
	// Bg defines the color of the RRect background.
	Bg color.NRGBA

Tooltip implements a material design tool tip as defined at:

func DesktopTooltip

func DesktopTooltip(th *material.Theme, text string) Tooltip

DesktopTooltip constructs a tooltip suitable for use on desktop devices.

func MobileTooltip

func MobileTooltip(th *material.Theme, text string) Tooltip

MobileTooltip constructs a tooltip suitable for use on mobile devices.

func PlatformTooltip

func PlatformTooltip(th *material.Theme, text string) Tooltip

PlatformTooltip creates a tooltip styled to the current platform (desktop or mobile) by choosing based on the OS. This choice may not always be appropriate as it only uses the OS to decide.

func (Tooltip) Layout

func (t Tooltip) Layout(gtx C) D

Layout renders the tooltip.

type TruncatingLabelStyle deprecated

type TruncatingLabelStyle material.LabelStyle

TruncatingLabelStyle is a type that forces a label to fit on one line and adds a truncation indicator symbol to the end of the line if the text has been truncated.

Deprecated: You can set material.LabelStyle.MaxLines to achieve truncation without this type. This type has been reimplemented to do that internally.

func (TruncatingLabelStyle) Layout

Layout renders the label into the provided context.

type Validator

type Validator = func(string) string

Validator validates text and returns a string describing the error. Error is displayed as helper text.

type VerticalAnchorPosition

type VerticalAnchorPosition uint

VerticalAnchorPosition indicates the anchor position for the content of a component. Conventionally, this is use by AppBars and NavDrawers to decide how to allocate internal spacing and in which direction to animate certain actions.

const (
	Top VerticalAnchorPosition = iota

type VisibilityAnimation

type VisibilityAnimation struct {
	// How long does the animation last
	State   VisibilityAnimationState
	Started time.Time

VisibilityAnimation holds the animation state for animations that transition between a "visible" and "invisible" state for a fixed duration of time.

func (VisibilityAnimation) Animating

func (v VisibilityAnimation) Animating() bool

Animating() returns whether the animation is either in the process of appearsing or disappearing.

func (*VisibilityAnimation) Appear

func (v *VisibilityAnimation) Appear(now time.Time)

Appear triggers the animation to begin becoming visible at the provided time. It is a no-op if the animation is already visible.

func (*VisibilityAnimation) Disappear

func (v *VisibilityAnimation) Disappear(now time.Time)

Disappear triggers the animation to begin becoming invisible at the provided time. It is a no-op if the animation is already invisible.

func (*VisibilityAnimation) Revealed

func (v *VisibilityAnimation) Revealed(gtx layout.Context) float32

Revealed returns the fraction of the animated entity that should be revealed at the current time in the animation. This fraction is computed with linear interpolation.

Revealed should be invoked during every frame that v.Animating() returns true.

If the animation reaches its end this frame, Revealed will transition it to a non-animating state automatically.

If the animation is in the process of animating, calling Revealed will automatically add an InvalidateOp to the provided layout.Context to ensure that the next frame will be generated promptly.

func (*VisibilityAnimation) String

func (v *VisibilityAnimation) String(gtx layout.Context) string

func (*VisibilityAnimation) ToggleVisibility

func (v *VisibilityAnimation) ToggleVisibility(now time.Time)

ToggleVisibility will make an invisible animation begin the process of becoming visible and a visible animation begin the process of disappearing.

func (VisibilityAnimation) Visible

func (v VisibilityAnimation) Visible() bool

Visible() returns whether any part of the animated entity should be visible during the current animation frame.

type VisibilityAnimationState

type VisibilityAnimationState int

VisibilityAnimationState represents possible states that a VisibilityAnimation can be in.

const (
	Visible VisibilityAnimationState = iota

func (VisibilityAnimationState) String

func (v VisibilityAnimationState) String() string

Jump to

Keyboard shortcuts

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