README ¶
component
This package provides various material design components for gio.
State
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:
Features:
- 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:
Contextual state:
Features:
- 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.
Features:
- 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.
Features:
- 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.
Dividers
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.
Surfaces
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.
Menu
The Menu
type defines contextual menus as described here.
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 MenuItem
s in action:
ContextArea
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.
Tooltips
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.
Documentation ¶
Overview ¶
Package component provides material design UI components as described by https://material.io
Index ¶
- func DividerSubheadingText(th *material.Theme, label string) material.LabelStyle
- func Interpolate(a, b color.NRGBA, progress float32) color.NRGBA
- func MenuHintText(th *material.Theme, label string) material.LabelStyle
- func SimpleIconButton(bg, fg color.NRGBA, state *widget.Clickable, icon *widget.Icon) material.IconButtonStyle
- func SwapGrounds(p material.Palette) material.Palette
- func SwapPairs(p material.Palette) material.Palette
- func WithAlpha(c color.NRGBA, a uint8) color.NRGBA
- type AlphaPalette
- type AppBar
- func (a *AppBar) CloseOverflowMenu(when time.Time)
- func (a *AppBar) Events(gtx layout.Context) []AppBarEvent
- func (a *AppBar) Layout(gtx layout.Context, theme *material.Theme, navDesc, overflowDesc string) layout.Dimensions
- func (a *AppBar) SetActions(actions []AppBarAction, overflows []OverflowAction)
- func (a *AppBar) SetContextualActions(actions []AppBarAction, overflows []OverflowAction)
- func (a *AppBar) StartContextual(when time.Time, title string)
- func (a *AppBar) StopContextual(when time.Time)
- func (a *AppBar) ToggleContextual(when time.Time, title string)
- type AppBarAction
- type AppBarContextMenuDismissed
- type AppBarEvent
- type AppBarNavigationClicked
- type AppBarOverflowActionClicked
- type C
- type ContextArea
- type D
- type DiscloserArrowStyle
- type DiscloserState
- type DiscloserStyle
- type DividerStyle
- type GridState
- type GridStyle
- type InvalidateDeadline
- type MenuItemStyle
- type MenuState
- type MenuStyle
- type ModalLayer
- type ModalNavDrawer
- type ModalSheet
- type ModalState
- type ModalStyle
- type NavDrawer
- func (m *NavDrawer) AddNavItem(item NavItem)
- func (m *NavDrawer) CurrentNavDestination() interface{}
- func (m *NavDrawer) Layout(gtx layout.Context, th *material.Theme, anim *VisibilityAnimation) layout.Dimensions
- func (m *NavDrawer) LayoutContents(gtx layout.Context, th *material.Theme, anim *VisibilityAnimation) layout.Dimensions
- func (m *NavDrawer) NavDestinationChanged() bool
- func (m *NavDrawer) SetNavDestination(tag interface{})
- func (m *NavDrawer) UnselectNavDestination()
- type NavItem
- type OverflowAction
- type Progress
- func (p Progress) Absolute() float32
- func (p Progress) Direction() ProgressDirection
- func (p Progress) Finished() bool
- func (p Progress) Progress() float32
- func (p *Progress) Start(began time.Time, direction ProgressDirection, duration time.Duration)
- func (p Progress) Started() bool
- func (p *Progress) Stop()
- func (p *Progress) Update(now time.Time)
- type ProgressDirection
- type Rect
- type Resize
- type Scrim
- type ScrimState
- type ScrimStyle
- type ShadowStyle
- type Sheet
- type Side
- type SimpleDiscloserStyle
- type SurfaceStyle
- type TableStyle
- type TextField
- func (in *TextField) Clear()
- func (in *TextField) ClearError()
- func (in TextField) IsActive() bool
- func (in *TextField) IsErrored() bool
- func (in *TextField) Layout(gtx C, th *material.Theme, hint string) D
- func (in *TextField) SetError(err string)
- func (in *TextField) TextTooLong() bool
- func (in *TextField) Update(gtx C, th *material.Theme, hint string)
- type TipArea
- type TipIconButtonStyle
- type Tooltip
- type TruncatingLabelStyle
- type Validator
- type VerticalAnchorPosition
- type VisibilityAnimation
- func (v VisibilityAnimation) Animating() bool
- func (v *VisibilityAnimation) Appear(now time.Time)
- func (v *VisibilityAnimation) Disappear(now time.Time)
- func (v *VisibilityAnimation) Revealed(gtx layout.Context) float32
- func (v *VisibilityAnimation) String(gtx layout.Context) string
- func (v *VisibilityAnimation) ToggleVisibility(now time.Time)
- func (v VisibilityAnimation) Visible() bool
- type VisibilityAnimationState
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 MenuHintText ¶
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 ¶
SwapGrounds swaps the foreground and background colors of both the contrast and non-constrast colors.
Bg <-> Fg ContrastBg <-> ContrastFg
Types ¶
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 { 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. *ModalLayer // 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: https://material.io/components/app-bars-top
TODO(whereswaldon): implement support for RTL layouts
func NewAppBar ¶
func NewAppBar(modal *ModalLayer) *AppBar
NewAppBar creates and initializes an App Bar.
func (*AppBar) CloseOverflowMenu ¶
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 ¶
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 ¶
StopContextual causes the AppBar to stop showing a contextual menu if one is currently being displayed.
type AppBarAction ¶
type AppBarAction struct { OverflowAction 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 ¶
func (a AppBarContextMenuDismissed) String() string
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 ¶
func (a AppBarOverflowActionClicked) String() string
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 // same place no matter where the activating interaction occurred. 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 Side 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) Width ¶
func (d DiscloserArrowStyle) Width() unit.Dp
Width returns the width of the arrow and surrounding whitespace.
type DiscloserState ¶
type DiscloserState struct { VisibilityAnimation widget.Clickable }
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 { *DiscloserState // 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 ----------------- detail
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 layout.Inset Subheading material.LabelStyle SubheadingInset layout.Inset }
DividerStyle defines the presentation of a material divider, as specified here: https://material.io/components/dividers
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 GridStyle ¶
type GridStyle struct { State *GridState VScrollbarStyle material.ScrollbarStyle HScrollbarStyle material.ScrollbarStyle material.AnchorStrategy }
GridStyle is the persistent state for the grid.
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 ¶
type MenuItemStyle struct { State *widget.Clickable HoverColor color.NRGBA LabelInset outlay.Inset Label material.LabelStyle *widget.Icon 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 (MenuItemStyle) Layout ¶
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 MenuStyle ¶
type MenuStyle struct { *MenuState *material.Theme // Inset applied around the rendered contents of the state's Options field. layout.Inset SurfaceStyle }
MenuStyle defines the presentation of a material design menu component.
type ModalLayer ¶
type ModalLayer struct { VisibilityAnimation Scrim 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 (*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: https://material.io/components/navigation-drawer
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 Sheet // contains filtered or unexported fields }
ModalSheet implements the Modal Side Sheet component specified at https://material.io/components/sheets-side#modal-side-sheet
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 { ScrimState // contains filtered or unexported fields }
ModalState defines persistent state for a modal.
type ModalStyle ¶
type ModalStyle struct { *ModalState Scrim ScrimStyle }
ModalStyle describes how to layout a modal. Modal content is layed centered atop a clickable scrim.
func Modal ¶
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 ¶
type NavDrawer struct { // 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: https://material.io/components/navigation-drawer
func (*NavDrawer) AddNavItem ¶
AddNavItem inserts a navigation target into the drawer. This should be invoked only from the layout thread to avoid nasty race conditions.
func (*NavDrawer) CurrentNavDestination ¶
func (m *NavDrawer) CurrentNavDestination() interface{}
CurrentNavDestination returns the tag of the navigation destination selected in the drawer.
func (*NavDrawer) Layout ¶
func (m *NavDrawer) Layout(gtx layout.Context, th *material.Theme, anim *VisibilityAnimation) layout.Dimensions
func (*NavDrawer) LayoutContents ¶
func (m *NavDrawer) LayoutContents(gtx layout.Context, th *material.Theme, anim *VisibilityAnimation) layout.Dimensions
func (*NavDrawer) NavDestinationChanged ¶
NavDestinationChanged returns whether the selected navigation destination has changed since the last frame.
func (*NavDrawer) SetNavDestination ¶
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 (*NavDrawer) UnselectNavDestination ¶
func (m *NavDrawer) UnselectNavDestination()
type NavItem ¶
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. // 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) Direction ¶
func (p Progress) Direction() ProgressDirection
Direction reports the current direction.
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. Reverse )
func (ProgressDirection) String ¶
func (d ProgressDirection) String() string
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.
type Scrim ¶
type Scrim struct { // FinalAlpha is the final opacity of the scrim on a scale from 0 to 255. FinalAlpha uint8 widget.Clickable }
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 ¶
func (s *Scrim) Layout(gtx layout.Context, th *material.Theme, anim *VisibilityAnimation) layout.Dimensions
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 { widget.Clickable VisibilityAnimation }
ScrimState defines persistent state for a scrim.
type ScrimStyle ¶
type ScrimStyle struct { *ScrimState 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: https://material.io/components/sheets-side#usage
type SimpleDiscloserStyle ¶
type SimpleDiscloserStyle struct { DiscloserStyle DiscloserArrowStyle }
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.
type SurfaceStyle ¶
type SurfaceStyle struct { *material.Theme // The CornerRadius and Elevation fields of the embedded shadow // style also define the corner radius and elevation of the card. ShadowStyle // 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.
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. widget.Editor // 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: https://material.io/components/text-fields
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) IsErrored ¶
IsErrored if input is in an errored state. Typically this is when the validator has returned an error message.
func (*TextField) SetError ¶
SetError puts the input into an errored state with the specified error text.
func (*TextField) TextTooLong ¶
TextTooLong returns whether the current editor text exceeds the set character limit.
type TipArea ¶
type TipArea struct { VisibilityAnimation 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.
type TipIconButtonStyle ¶
type TipIconButtonStyle struct { Tooltip material.IconButtonStyle 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. layout.Inset // 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: https://material.io/components/tooltips#specs
func DesktopTooltip ¶
DesktopTooltip constructs a tooltip suitable for use on desktop devices.
func MobileTooltip ¶
MobileTooltip constructs a tooltip suitable for use on mobile devices.
func PlatformTooltip ¶
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.
type TruncatingLabelStyle ¶
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.
func (TruncatingLabelStyle) Layout ¶
func (t TruncatingLabelStyle) Layout(gtx layout.Context) layout.Dimensions
Layout renders the label into the provided context.
type Validator ¶
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 Bottom )
type VisibilityAnimation ¶
type VisibilityAnimation struct { // How long does the animation last time.Duration 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 Disappearing Appearing Invisible )
func (VisibilityAnimationState) String ¶
func (v VisibilityAnimationState) String() string