Documentation ¶
Index ¶
- Variables
- func WithAlpha(c color.NRGBA, a uint8) color.NRGBA
- type Alignment
- type AlphaPalette
- type Axis
- type ButtonLayoutStyle
- type ButtonStyle
- type ChangeEvent
- type Clickable
- type Constraints
- type Dim
- type Dp
- type Editor
- func (e *Editor) CaretCoords() f32.Point
- func (e *Editor) CaretPos() (line, col int)
- func (e *Editor) ClearSelection()
- func (e *Editor) Delete(graphemeClusters int) (deletedRunes int)
- func (e *Editor) Insert(s string) (insertedRunes int)
- func (e *Editor) Layout(gtx layout.Context, lt *text.Shaper, font font.Font, size unit.Sp, ...) layout.Dimensions
- func (e *Editor) Len() int
- func (e *Editor) MoveCaret(startDelta, endDelta int)
- func (e *Editor) Read(p []byte) (int, error)
- func (e *Editor) Regions(start, end int, regions []Region) []Region
- func (e *Editor) Seek(offset int64, whence int) (int64, error)
- func (e *Editor) SelectedText() string
- func (e *Editor) Selection() (start, end int)
- func (e *Editor) SelectionLen() int
- func (e *Editor) SetCaret(start, end int)
- func (e *Editor) SetText(s string)
- func (e *Editor) Text() string
- func (e *Editor) Update(gtx layout.Context) (EditorEvent, bool)
- func (e *Editor) WriteTo(w io.Writer) (int64, error)
- type EditorEvent
- type Enum
- type Flex
- type FlexChild
- type Gx
- type Icon
- type IconButtonStyle
- type ImageButtonStyle
- type Inset
- type Label
- type List
- type ModalLayer
- type ModalNavDrawer
- type ModalSheet
- type ModalState
- type ModalStyle
- type NRGBA
- type NavDrawer
- func (nd *NavDrawer) AddNavItem(item NavItem)
- func (nd *NavDrawer) CurrentNavDestination() interface{}
- func (nd *NavDrawer) Layout(g Gx, th *Theme, c *Palette, anim *VisibilityAnimation) Dim
- func (nd *NavDrawer) LayoutContents(g Gx, th *Theme, c *Palette, anim *VisibilityAnimation) Dim
- func (nd *NavDrawer) NavDestinationChanged() bool
- func (nd *NavDrawer) SetNavDestination(tag interface{})
- func (nd *NavDrawer) UnselectNavDestination()
- type NavItem
- type Palette
- type Point
- 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 Rectangle
- type Region
- type Scrim
- type ScrimState
- type ScrimStyle
- type SelectEvent
- type Sheet
- type Sp
- type Spacer
- type Spacing
- type Stack
- type SubmitEvent
- type TextField
- func (in *TextField) Clear()
- func (in *TextField) ClearError()
- func (in TextField) IsActive() bool
- func (in *TextField) IsInvalid() bool
- func (in *TextField) Layout(g Gx, th *Theme, col *Palette, hint string) Dim
- func (in *TextField) SetError(err string)
- func (in *TextField) TextTooLong() bool
- func (in *TextField) Update(g Gx, th *Theme, col *Palette, hint string)
- type TextInfo
- type Theme
- 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(g Gx) float32
- func (v *VisibilityAnimation) String(g Gx) string
- func (v *VisibilityAnimation) ToggleVisibility(now time.Time)
- func (v VisibilityAnimation) Visible() bool
- type VisibilityAnimationState
- type Widget
- Bugs
Constants ¶
This section is empty.
Variables ¶
var ( Horizontal = _l.Horizontal Vertical = _l.Vertical Start = _l.Start End = _l.End Middle = _l.Middle Baseline = _l.Baseline SpaceSides = _l.SpaceSides SpaceStart = _l.SpaceStart SpaceEvenly = _l.SpaceEvenly SpaceAround = _l.SpaceAround SpaceBetween = _l.SpaceBetween SpaceEnd = _l.SpaceEnd )
Functions ¶
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 ButtonLayoutStyle ¶
type ButtonLayoutStyle = _m.ButtonLayoutStyle
type ButtonStyle ¶ added in v0.0.3
type ButtonStyle = _m.ButtonStyle
type ChangeEvent ¶
type ChangeEvent struct{}
A ChangeEvent is generated for every user change to the text.
type Constraints ¶
type Constraints = _l.Constraints
type Dim ¶
type Dim = _l.Dimensions
type Editor ¶
type Editor struct { // Alignment controls the alignment of text within the editor. Alignment text.Alignment // LineHeight determines the gap between baselines of text. If zero, a sensible // default will be used. LineHeight unit.Sp // LineHeightScale is multiplied by LineHeight to determine the final gap // between baselines. If zero, a sensible default will be used. LineHeightScale float32 // SingleLine force the text to stay on a single line. // SingleLine also sets the scrolling direction to // horizontal. SingleLine bool // ReadOnly controls whether the contents of the editor can be altered by // user interaction. If set to true, the editor will allow selecting text // and copying it interactively, but not modifying it. ReadOnly bool // Submit enabled translation of carriage return keys to SubmitEvents. // If not enabled, carriage returns are inserted as newlines in the text. Submit bool // Mask replaces the visual display of each rune in the contents with the given rune. // Newline characters are not masked. When non-zero, the unmasked contents // are accessed by Len, Text, and SetText. Mask rune // InputHint specifies the type of on-screen keyboard to be displayed. InputHint key.InputHint // MaxLen limits the editor content to a maximum length. Zero means no limit. MaxLen int // Filter is the list of characters allowed in the Editor. If Filter is empty, // all characters are allowed. Filter string // WrapPolicy configures how displayed text will be broken into lines. WrapPolicy text.WrapPolicy // contains filtered or unexported fields }
Editor implements an editable and scrollable text area.
func (*Editor) CaretCoords ¶
CaretCoords returns the coordinates of the caret, relative to the editor itself.
func (*Editor) ClearSelection ¶
func (e *Editor) ClearSelection()
ClearSelection clears the selection, by setting the selection end equal to the selection start.
func (*Editor) Delete ¶
Delete runes from the caret position. The sign of the argument specifies the direction to delete: positive is forward, negative is backward.
If there is a selection, it is deleted and counts as a single grapheme cluster.
func (*Editor) Layout ¶
func (e *Editor) Layout(gtx layout.Context, lt *text.Shaper, font font.Font, size unit.Sp, textMaterial, selectMaterial op.CallOp) layout.Dimensions
Layout lays out the editor using the provided textMaterial as the paint material for the text glyphs+caret and the selectMaterial as the paint material for the selection rectangle.
func (*Editor) MoveCaret ¶
MoveCaret moves the caret (aka selection start) and the selection end relative to their current positions. Positive distances moves forward, negative distances moves backward. Distances are in grapheme clusters, which closely match what users perceive as "characters" even when the characters are multiple code points long.
func (*Editor) SelectedText ¶
SelectedText returns the currently selected text (if any) from the editor.
func (*Editor) Selection ¶
Selection returns the start and end of the selection, as rune offsets. start can be > end.
func (*Editor) SelectionLen ¶
SelectionLen returns the length of the selection, in runes; it is equivalent to utf8.RuneCountInString(e.SelectedText()).
func (*Editor) SetCaret ¶
SetCaret moves the caret to start, and sets the selection end to end. start and end are in runes, and represent offsets into the editor text.
func (*Editor) Update ¶
func (e *Editor) Update(gtx layout.Context) (EditorEvent, bool)
Update the state of the editor in response to input events. Update consumes editor input events until there are no remaining events or an editor event is generated. To fully update the state of the editor, callers should call Update until it returns false.
type EditorEvent ¶
type EditorEvent interface {
// contains filtered or unexported methods
}
type IconButtonStyle ¶
type IconButtonStyle = _m.IconButtonStyle
type ImageButtonStyle ¶ added in v0.0.3
func ImageButton ¶ added in v0.0.3
func (ImageButtonStyle) Layout ¶ added in v0.0.3
func (b ImageButtonStyle) Layout(g Gx) Dim
type Label ¶
type Label struct { // Alignment specifies the text alignment. Alignment text.Alignment // MaxLines limits the number of lines. Zero means no limit. MaxLines int // Truncator is the text that will be shown at the end of the final // line if MaxLines is exceeded. Defaults to "…" if empty. Truncator string // WrapPolicy configures how displayed text will be broken into lines. WrapPolicy text.WrapPolicy // LineHeight controls the distance between the baselines of lines of text. // If zero, a sensible default will be used. LineHeight unit.Sp // LineHeightScale applies a scaling factor to the LineHeight. If zero, a // sensible default will be used. LineHeightScale float32 }
Label is a widget for laying out and drawing text. Labels are always non-interactive text. They cannot be selected or copied.
func (Label) Layout ¶
func (l Label) Layout(gtx layout.Context, lt *text.Shaper, font font.Font, size unit.Sp, txt string, textMaterial op.CallOp) layout.Dimensions
Layout the label with the given shaper, font, size, text, and material.
func (Label) LayoutDetailed ¶
func (l Label) LayoutDetailed(gtx layout.Context, lt *text.Shaper, font font.Font, size unit.Sp, txt string, textMaterial op.CallOp) (layout.Dimensions, TextInfo)
Layout the label with the given shaper, font, size, text, and material, returning metadata about the shaped text.
type ModalLayer ¶
type ModalLayer struct { VisibilityAnimation Scrim Widget func(g Gx, th *Theme, c *Palette, anim *VisibilityAnimation) Dim }
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.
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 st, imgButton *ImageButtonStyle) *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() Dim
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 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(g Gx, th *Theme, c *Palette, anim *VisibilityAnimation) Dim)
LayoutModal 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 lay out a modal. Modal content is layed centered atop a clickable scrim.
func Modal ¶
func Modal(th *Theme, c *Palette, 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(g Gx) Dim
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 NewNav ¶
func NewNav(title, subtitle st, imgButton *ImageButtonStyle) NavDrawer
NewNav configures a 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 (nd *NavDrawer) CurrentNavDestination() interface{}
CurrentNavDestination returns the tag of the navigation destination selected in the drawer.
func (*NavDrawer) LayoutContents ¶
func (*NavDrawer) NavDestinationChanged ¶
NavDestinationChanged returns whether the selected navigation destination has changed since the last frame.
func (*NavDrawer) SetNavDestination ¶
func (nd *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 (nd *NavDrawer) UnselectNavDestination()
type NavItem ¶
type NavItem struct { // Tag is an externally-provided identifier for the view that this item should // navigate to. Its value is opaque to navigation elements. // 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 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 Region ¶
type Region struct { // Bounds is the coordinates of the bounding box relative to the containing // widget. Bounds image.Rectangle // Baseline is the quantity of vertical pixels between the baseline and // the bottom of bounds. Baseline int }
Region describes the position and baseline of an area of interest within shaped text.
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.
type ScrimState ¶
type ScrimState struct { widget.Clickable VisibilityAnimation }
ScrimState defines persistent state for a scrim.
type ScrimStyle ¶
type ScrimStyle struct { *ScrimState Color NRGBA FinalAlpha uint8 }
ScrimStyle defines how to lay out a scrim.
func NewScrim ¶
func NewScrim(th *Theme, c *Palette, 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(g Gx) Dim
type SelectEvent ¶
type SelectEvent struct{}
A SelectEvent is generated when the user selects some text, or changes the selection (e.g. with a shift-click), including if they remove the selection. The selected text is not part of the event, on the theory that it could be a relatively expensive operation (for a large editor), most applications won't actually care about it, and those that do can call Editor.SelectedText() (which can be empty).
type Sheet ¶
type Sheet struct{}
Sheet implements the standard side sheet described here: https://material.io/components/sheets-side#usage
type SubmitEvent ¶
type SubmitEvent struct {
Text string
}
A SubmitEvent is generated when Submit is set and a carriage return key is pressed.
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 Label label // 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) IsInvalid ¶
IsInvalid if input is in an error state, usually when the validator returns an error.
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 TextInfo ¶
type TextInfo struct { // Truncated contains the number of runes of text that are represented by a truncator // symbol in the text. If zero, there is no truncator symbol. Truncated int }
TextInfo provides metadata about shaped text.
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(g Gx) 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 Gx to ensure that the next frame will be generated promptly.
func (*VisibilityAnimation) String ¶
func (v *VisibilityAnimation) String(g Gx) 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
Notes ¶
Bugs ¶
this method's definition of a "word" is currently whitespace-delimited. Languages that do not use whitespace to delimit words will experience counter-intuitive behavior when navigating by word.