gel

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2025 License: Unlicense Imports: 39 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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
)
View Source
var (
	Exact        = _l.Exact
	Pt           = _i.Pt
	Rigid        = _l.Rigid
	Flexed       = _l.Flexed
	UniformInset = _l.UniformInset
	Body1        = _m.Body1
	// Editor       = _m.Editor
	RadioButton = _m.RadioButton
	Slider      = _m.Slider
	Expanded    = _l.Expanded
	Stacked     = _l.Stacked
	FillShape   = _p.FillShape
	Fill        = _p.Fill
)

Functions

func WithAlpha

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

WithAlpha returns the input color with the new alpha value.

Types

type Alignment

type Alignment = _l.Alignment

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 Axis

type Axis = _l.Axis

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 Clickable

type Clickable = _w.Clickable

type Constraints

type Constraints = _l.Constraints

type Dim

type Dim = _l.Dimensions

type Dp

type Dp = _u.Dp

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

func (e *Editor) CaretCoords() f32.Point

CaretCoords returns the coordinates of the caret, relative to the editor itself.

func (*Editor) CaretPos

func (e *Editor) CaretPos() (line, col int)

CaretPos returns the line & column numbers of the caret.

func (*Editor) ClearSelection

func (e *Editor) ClearSelection()

ClearSelection clears the selection, by setting the selection end equal to the selection start.

func (*Editor) Delete

func (e *Editor) Delete(graphemeClusters int) (deletedRunes int)

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) Insert

func (e *Editor) Insert(s string) (insertedRunes int)

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) Len

func (e *Editor) Len() int

Len is the length of the editor contents, in runes.

func (*Editor) MoveCaret

func (e *Editor) MoveCaret(startDelta, endDelta int)

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) Read

func (e *Editor) Read(p []byte) (int, error)

Read implements io.Reader.

func (*Editor) Regions

func (e *Editor) Regions(start, end int, regions []Region) []Region

Regions returns visible regions covering the rune range [start,end).

func (*Editor) Seek

func (e *Editor) Seek(offset int64, whence int) (int64, error)

Seek implements io.Seeker.

func (*Editor) SelectedText

func (e *Editor) SelectedText() string

SelectedText returns the currently selected text (if any) from the editor.

func (*Editor) Selection

func (e *Editor) Selection() (start, end int)

Selection returns the start and end of the selection, as rune offsets. start can be > end.

func (*Editor) SelectionLen

func (e *Editor) SelectionLen() int

SelectionLen returns the length of the selection, in runes; it is equivalent to utf8.RuneCountInString(e.SelectedText()).

func (*Editor) SetCaret

func (e *Editor) SetCaret(start, end int)

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) SetText

func (e *Editor) SetText(s string)

func (*Editor) Text

func (e *Editor) Text() string

Text returns the contents of the editor.

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.

func (*Editor) WriteTo

func (e *Editor) WriteTo(w io.Writer) (int64, error)

WriteTo implements io.WriterTo.

type EditorEvent

type EditorEvent interface {
	// contains filtered or unexported methods
}

type Enum

type Enum = _w.Enum

type Flex

type Flex = _l.Flex

type FlexChild

type FlexChild = _l.FlexChild

type Gx

type Gx = _l.Context

type Icon

type Icon = _w.Icon

type IconButtonStyle

type IconButtonStyle = _m.IconButtonStyle

type ImageButtonStyle added in v0.0.3

type ImageButtonStyle struct {
	Size        Dp
	Button      *Clickable
	Description string
	image.Image
}

func ImageButton added in v0.0.3

func ImageButton(th *Theme, button *Clickable, img image.Image, description string) *ImageButtonStyle

func (ImageButtonStyle) Layout added in v0.0.3

func (b ImageButtonStyle) Layout(g Gx) Dim

type Inset

type Inset = _l.Inset

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 List

type List = _l.List

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.

func NewModal

func NewModal() *ModalLayer

NewModal creates an initializes a modal layer.

func (*ModalLayer) Layout

func (m *ModalLayer) Layout(g Gx, th *Theme, c *Palette) Dim

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

type ModalNavDrawer

type ModalNavDrawer struct {
	NavDrawer *NavDrawer
	// 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.

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 {
	*ModalState
	Scrim ScrimStyle
}

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

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 NRGBA

type NRGBA = _c.NRGBA
type NavDrawer struct {
	AlphaPalette

	Title    st
	Subtitle st
	*ImageButtonStyle

	// 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

	layout.List
	// 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 (nd *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 (nd *NavDrawer) CurrentNavDestination() interface{}

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

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

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

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 (nd *NavDrawer) UnselectNavDestination()
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.
	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 Palette

type Palette = _col.Palette

type Point

type Point = _i.Point

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.
	Reverse
)

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(g Gx) Dim

type Rectangle

type Rectangle = _i.Rectangle

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.

func (*Scrim) Layout

func (s *Scrim) Layout(g Gx, th *Theme, c *Palette, anim *VisibilityAnimation) Dim

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      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

func NewSheet

func NewSheet() Sheet

NewSheet returns a new sheet

func (Sheet) Layout

func (s Sheet) Layout(g Gx, th *Theme, c *Palette, anim *VisibilityAnimation, w Widget) Dim

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

type Sp

type Sp = _u.Sp

type Spacer

type Spacer = _l.Spacer

type Spacing

type Spacing = _l.Spacing

type Stack

type Stack = _l.Stack

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) IsActive

func (in TextField) IsActive() bool

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

func (*TextField) IsInvalid

func (in *TextField) IsInvalid() bool

IsInvalid if input is in an error state, usually when the validator returns an error.

func (*TextField) Layout

func (in *TextField) Layout(g Gx, th *Theme, col *Palette, hint string) Dim

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(g Gx, th *Theme, col *Palette, hint string)

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 Theme

type Theme = _m.Theme

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
	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

type Widget

type Widget = _l.Widget

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.

Jump to

Keyboard shortcuts

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