ui

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: MIT Imports: 20 Imported by: ? modules, 0 packages

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

Documentation

Overview

Package ui holds giokit's components, built only from package kit's exported API: anything here could be written outside giokit.

A component is a props struct laid out with a theme and its state:

ui.Combobox{ID: "city", Options: cities}.Layout(gtx, th, &v.city)

Props are values, set fresh each frame. State structs hold what must survive between frames; they contain event tags, so a state must not be copied or moved after its first use, and only the UI goroutine touches it. The zero value of every state is ready to use.

Values

Controlled values are the default: the value comes in through props (Checkbox.Checked, Select.Selected, Tabs.Selected, DateField.Value, Slider.Value, Accordion.Open, SelectableList.Selected), and the caller stores what the state's Update reports and passes it back next frame. The component never changes it behind the caller's back.

A few values are retained by the state instead, because they are interaction state that changes continuously or locally, and each is documented on its state type:

  • SplitState.Ratio: the divider position while dragging;
  • NumberFieldState's value and the text being edited (SetValue, Value);
  • TreeState's expanded nodes (SetExpanded);
  • DataTableState's sort column and direction;
  • the editor text of TextField, TextArea and Combobox, which lives in the widget.Editor the caller owns;
  • x.LogView's filters.

Input and events

Events are read in the handle pass, before layout, with the state's Update (or Clickable.Clicked for single-button components): kit's frame rule is to handle input, then draw. Update consumes the input it reports and returns at most one event per call. Components whose events are picks (Menu, Select, Toolbar, Breadcrumbs, Tabs, Accordion) report the first and leave the rest for the next call; value components (Slider, NumberField) apply every input of the frame in order and report the final value once.

Keys handled by kit's action dispatch (arrows, Home/End, Enter in focus groups) run after layout, when the frame's focus is known. A component that picks from such a key queues the pick and reports it from the next Update, asking for that frame with kit.Notify. Several keys in one frame each move on from the previous one.

Some components handle their input inside Layout, because it depends on their props or is not reported to the caller:

  • editors with suggestions: Combobox (its suggestions depend on Options) and CommandPalette (its results depend on Actions, and it runs the picked action itself);
  • self-contained overlays: Tooltip (hover timing), ToastHost (expiry and dismissal) and Split (its retained Ratio).

Navigation in text-field popups (Combobox, CommandPalette) wraps around; focus-group lists and menus clamp at the ends. Enter means Return or the keypad's Enter everywhere.

Index

Constants

View Source
const ToastDuration = 5 * time.Second

ToastDuration is how long a toast stays, by default, before it dismisses itself.

View Source
const TooltipDelay = 500 * time.Millisecond

TooltipDelay is how long the pointer must rest before a tooltip shows.

Variables

This section is empty.

Functions

func Danger

func Danger(th *kit.Theme, st kit.State) (kit.Surface, color.NRGBA)

Danger is destructive.

func Ghost

func Ghost(th *kit.Theme, st kit.State) (kit.Surface, color.NRGBA)

Ghost has no fill until hovered (toolbars).

func Move

func Move[T any](s []T, from, to int) bool

Move moves s[from] to index to, shifting the items between. It reports false (and changes nothing) for an out-of-range or no-op move.

func Primary

func Primary(th *kit.Theme, st kit.State) (kit.Surface, color.NRGBA)

Primary is an accent tint.

func Secondary

func Secondary(th *kit.Theme, st kit.State) (kit.Surface, color.NRGBA)

Secondary is an outlined surface: the default.

func Solid

func Solid(th *kit.Theme, st kit.State) (kit.Surface, color.NRGBA)

Solid is a solid accent fill: the one main action. Its ring is OnAccent, since an accent ring would vanish on the fill.

Types

type Accordion

type Accordion struct {
	ID       string             // the group's id; headers are ID/<section ID>
	Sections []AccordionSection // top to bottom
	Open     string             // the open section's ID; "" for none
}

Accordion is a stack of Disclosures with at most one open. Headers are ID/<section ID>.

func (Accordion) Layout

Layout draws one Disclosure per section, Open's section expanded, inside a named group. It remembers the sections and Open for s.Update, which reports header clicks.

type AccordionSection

type AccordionSection struct {
	// ID is the section's stable id, Title its header text and Summary an
	// optional pill after the title (Disclosure.Trailing).
	ID, Title, Summary string
	Body               layout.Widget // the section's content
}

AccordionSection is one section. IDs must stay stable when sections are reordered. Body is laid out only while the section is open.

type AccordionState

type AccordionState struct {
	// contains filtered or unexported fields
}

AccordionState holds the section headers, one per section ID. The zero value is ready to use; do not copy it after first use.

func (*AccordionState) Update

func (s *AccordionState) Update(gtx layout.Context) (string, bool)

Update returns the section to show open (or "" to close all) after a header was clicked since the last call.

type Artwork

type Artwork struct {
	ID, Label string  // semantic id and alternative text (kit.TagImage)
	Size      unit.Dp // the square's side
}

Artwork draws square, cropped artwork, or a placeholder while the image is not set. Label describes the image to screen readers and tests.

func (Artwork) Layout

func (a Artwork) Layout(gtx layout.Context, th *kit.Theme, im *kit.Image) layout.Dimensions

Layout draws im cropped to cover a Size square with the theme's corner radius, or an AccentBg placeholder while im holds no image. It reads im only; decode and Set it elsewhere. It takes no input.

type Badge

type Badge struct {
	Status kit.Status // picks the pill's text and fill colours
	Text   string     // the pill's text, in the user's language
}

Badge is a pill coloured by status.

func (Badge) Layout

func (b Badge) Layout(gtx layout.Context, th *kit.Theme) layout.Dimensions

Layout draws the pill at its natural size. It takes no input.

type Banner struct {
	Status      kit.Status // picks the icon, tint and border
	Title, Body string     // a bold line, then an optional wrapped paragraph
	// Action, if set, draws a control at the banner's end, such as a Link
	// or a small Button that resolves the message. It keeps its own state.
	Action layout.Widget
}

Banner is an inline alert: status icon, bold title, optional body.

func (Banner) Layout

func (b Banner) Layout(gtx layout.Context, th *kit.Theme) layout.Dimensions

Layout draws the banner stretched to the available width. It takes no input itself; Action, if set, handles its own.

type Breadcrumb struct {
	ID, Label string // the crumb's stable id and visible text
}

Breadcrumb is one location. IDs must be unique within the path.

type Breadcrumbs struct {
	ID   string       // the group's id; segments are ID/<crumb ID>
	Path []Breadcrumb // from the root to the current location
}

Breadcrumbs is a location path that wraps whole segments when the width is short. The last crumb is the current location, drawn as plain text; the earlier ones are Links, reported by BreadcrumbsState.Update. Segments are ID/<crumb ID>.

Layout draws the crumbs with separators, wrapping whole segments, the last as plain text and the others as Links from s. It remembers the linked crumbs for s.Update, which reports clicks.

type BreadcrumbsState struct {
	// contains filtered or unexported fields
}

BreadcrumbsState holds the links, one per crumb ID. The zero value is ready to use; do not copy it after first use.

func (s *BreadcrumbsState) Update(gtx layout.Context) (string, bool)

Update returns the ID of a crumb clicked since the last call. Call it in the handle pass.

type Button

type Button struct {
	ID    string          // the button's semantic id
	Text  string          // the visible text
	Icon  kit.Icon        // optional, before the text
	Label string          // spoken name when Text is not enough; default Text
	Style ButtonStyle     // nil is Secondary
	Size  kit.ControlSize // ControlDefault is the theme's size
}

Button is a push button with text and an optional leading icon.

ui.Button{ID: "save", Text: "Save", Style: ui.Solid}.Layout(gtx, th, &v.save)

Read clicks with Clickable.Clicked in the handle pass.

func (Button) Layout

func (b Button) Layout(gtx layout.Context, th *kit.Theme, c *kit.Clickable) layout.Dimensions

Layout draws the button with Style for c's hover, press and focus state. It registers c as the press and focus target; read clicks with c.Clicked in the handle pass. Inside th.Disable it is dimmed and inert.

type ButtonStyle

type ButtonStyle func(th *kit.Theme, st kit.State) (kit.Surface, color.NRGBA)

ButtonStyle draws a button in a state: its surface (fill, border, ring) and content colour. Secondary (the default), Primary, Ghost, Danger and Solid cover the usual variants; an app adds its own as a plain function.

type Checkbox

type Checkbox struct {
	ID      string // the control's semantic id
	Label   string // drawn beside the box and spoken; "" draws the box alone
	Checked bool   // the controlled value
}

Checkbox is a check box with an optional label; the label is part of the click target. Flip your bool when the Clickable reports a click.

ui.Checkbox{ID: "agree", Label: "I agree", Checked: v.agreed}.Layout(gtx, th, &v.agree)

func (Checkbox) Layout

func (cb Checkbox) Layout(gtx layout.Context, th *kit.Theme, c *kit.Clickable) layout.Dimensions

Layout draws the box, checked or not, and its label for c's state, and registers c as the press and focus target. It does not flip Checked: read c.Clicked in the handle pass and flip your value.

type Choice

type Choice struct {
	ID    string // unique within its list, non-empty and stable across frames
	Label string // the visible and spoken text; may repeat or be translated
}

Choice is one stable item of a list: ID never changes, Label is shown and spoken.

type Collapsible

type Collapsible struct {
	kit.Clickable      // the header's press target
	Open          bool // whether the Disclosure shows its body
}

Collapsible is ready-made state for a Disclosure that keeps its own Open: call Update in the handle pass, lay out with Open and &Clickable. The zero value is closed; it embeds an event tag, so do not copy it after first use.

func (*Collapsible) Update

func (c *Collapsible) Update(gtx layout.Context) bool

Update flips Open when the header was clicked, and reports it.

type Combobox

type Combobox struct {
	ID          string          // the field's id; see the type doc for its parts
	Placeholder string          // dim hint text drawn while the editor is empty
	Options     []Choice        // IDs must be unique and stable
	Size        kit.ControlSize // ControlDefault is the theme's
}

Combobox is a text field that suggests Options as you type. Any text is allowed: the options are suggestions, and taking one puts its Label in the field. Read the value with state.Editor.Text().

Typing filters the options (case-insensitive substring of the Label), showing at most eight. An option whose Label equals the whole text, case aside, is not suggested: the field already holds it. Down/Up choose (wrapping through "no choice"), Down on a closed list shows every option, Enter (Return or keypad) or a click takes the choice, Escape closes the list.

Like the other editors, a Combobox handles its input in Layout (see the package doc): its suggestions depend on Options. Ids: the field ID, the list ID/list, suggestions ID/opt/<option ID>.

func (Combobox) Layout

func (c Combobox) Layout(gtx layout.Context, th *kit.Theme, s *ComboboxState) layout.Dimensions

Layout handles this frame's input (suggestion clicks, keys, edits) before drawing, then draws the field and, while open, the suggestions in a popover as wide as the field. Taking a suggestion writes its Label into s.Editor; there is no Update.

type ComboboxState

type ComboboxState struct {
	// Editor holds the field's text, the combobox's value. Read and set it
	// directly; Layout sets its SingleLine.
	Editor widget.Editor
	// contains filtered or unexported fields
}

ComboboxState is a Combobox's interaction state: its editor and the suggestion list. The zero value is an empty, closed field; do not copy it after first use.

func (*ComboboxState) Opened

func (s *ComboboxState) Opened() bool

Opened reports whether the suggestion list is open.

type CommandPalette

type CommandPalette struct {
	ID      string        // the dialog's id; see the type doc for its parts
	Actions *kit.Actions  // searched with Actions.Search; must not be nil
	Page    layout.Widget // the window's content, drawn under the dialog
}

CommandPalette is a modal, searchable action picker over Actions. Call state.Open from a shortcut, and wrap the window's Page with it each frame. Query field ID/query, results ID/<action ID>.

func (CommandPalette) Layout

Layout draws Page and, while p is open, the modal palette over it. It handles input itself: typing filters the results, Up/Down move the highlight (wrapping), and Enter or a click runs the action with Actions.Run and closes the palette. There is no Update.

type CommandPaletteState

type CommandPaletteState struct {
	// Dialog is the palette's modal. Prefer Open and Close, which also
	// reset the query and move focus.
	Dialog kit.Dialog
	// Editor holds the query text.
	Editor widget.Editor
	// contains filtered or unexported fields
}

CommandPaletteState is a CommandPalette's state: its dialog, query and results. The zero value is closed; like other states it holds event tags, so do not copy it after first use.

func (*CommandPaletteState) Close

func (p *CommandPaletteState) Close()

Close hides the palette.

func (*CommandPaletteState) Open

func (p *CommandPaletteState) Open()

Open shows the palette with an empty query.

type ContextMenu

type ContextMenu struct {
	ID      string        // the panel's id; the area is ID/area, items ID/<item ID>
	Items   []MenuItem    // the rows, top to bottom
	Content layout.Widget // the region that opens the menu
}

ContextMenu lays out Content; a right-click inside it opens the menu at the pointer, and Shift+F10 (kit.ActContextMenu) while focus is inside it opens the menu at the content's top-left corner. Read picks with MenuState.Update, as for a Menu. The area's id is ID/area.

Content has no focus of its own to return to: after Escape, focus is not restored to the control inside Content that had it.

func (ContextMenu) Layout

func (cm ContextMenu) Layout(gtx layout.Context, th *kit.Theme, m *MenuState) layout.Dimensions

Layout draws Content, opens m on a right-click or Shift+F10 inside it, and draws the open item panel at the pointer. m.Update reports the pick.

type DataColumn

type DataColumn struct {
	// ID names the column: its sort header is <table ID>/sort/<column ID>.
	// It must be unique within the table, non-empty and stable: not the
	// translated title.
	ID    string
	Title string // the header's visible and spoken text
	// Width is the column's width; 0 shares the leftover space.
	Width unit.Dp
	// Align places each cell's content: layout.W (the zero value's
	// meaning) or layout.E.
	Align layout.Direction
	// Compare, if set, orders two of the column's cell texts when sorting
	// by it: negative when a sorts before b. Use it for numbers, dates and
	// sizes. nil compares the texts case-insensitively, so "10" sorts
	// before "9".
	Compare func(a, b string) int
}

DataColumn is one DataTable column.

type DataRow

type DataRow struct {
	// ID names the row: unique, non-empty and stable across frames.
	ID string
	// Cells are the row's text, one per column: sorted on, spoken (joined
	// with ", ") and drawn unless DataTable.Cell is set. A missing cell is
	// empty.
	Cells []string
}

DataRow has a stable ID and one text cell per column.

type DataTable

type DataTable struct {
	ID      string       // the table's id; see the type doc for its parts
	Columns []DataColumn // left to right
	Rows    []DataRow    // in model order; the table sorts a copy of the order
	// Selected is the selected row's ID (controlled); "" selects nothing.
	Selected string
	// Cell, if set, draws row r's cell in column col (a status badge, a
	// progress bar). It is called for every column, whether or not r has a
	// cell there.
	Cell func(gtx layout.Context, r DataRow, col int) layout.Dimensions
	// Multiple and Chosen: as for SelectableList (ranges follow the sort order).
	Multiple bool
	Chosen   map[string]bool // the chosen IDs while Multiple; nil is none
}

DataTable is a table with a sticky header that sorts (click a header, again to reverse), aligned columns and one selected row, or several with Multiple; rows virtualize within the available height. Headers are ID/sort/<column ID>, the rows ID/rows (a grid) and each row ID/<row ID>.

The rows are sorted afresh on every layout, so Rows may change between frames, in place or not.

func (DataTable) Layout

func (dt DataTable) Layout(gtx layout.Context, th *kit.Theme, s *DataTableState) layout.Dimensions

Layout sorts the row order by the state's sort, then draws the sticky header and the visible rows, filling the available size, with Selected (and Chosen) highlighted. It handles the rows' keys and type-ahead while laying out; s.Update runs the sort headers and reports the selection.

type DataTableState

type DataTableState struct {
	List kit.List // the rows' scroll position (see SelectableListState.List)
	// SortColumn is the index in Columns of the column the rows are sorted
	// by, when Sorted. An index out of range sorts nothing.
	SortColumn int
	Descending bool // sort from last to first
	// Sorted reports whether the rows are sorted: a header was clicked, or
	// the app set it.
	Sorted bool
	// contains filtered or unexported fields
}

DataTableState is a DataTable's scroll, sort and selection state. The zero value is ready and unsorted; it must not be copied after first use.

The sort is retained interaction state: header clicks change it, and the app may preset or read it.

func (*DataTableState) Update

func (s *DataTableState) Update(gtx layout.Context) (SelectionEvent, bool)

Update runs the sort headers and reports a selection change made since the last call (see SelectableListState.Update).

type DateField

type DateField struct {
	ID          string          // the calendar panel's id; see the type doc for its parts
	Value       time.Time       // the controlled value; zero shows Placeholder
	Placeholder string          // the field's text while Value is zero
	Format      string          // field text layout; default Theme.Strings.DateFormat
	SundayFirst bool            // weeks start on Sunday instead of Monday
	Size        kit.ControlSize // ControlDefault is the theme's
}

DateField is a field showing Value (zero shows Placeholder) that opens a calendar. It is controlled: set Value from what Update returns.

The calendar works in civil dates. Value's calendar day in its own location is authoritative (its time of day is ignored), and Update returns the picked day at midnight in that location: time.Local while Value is zero. Today is the day of gtx.Now in time.Local.

The calendar has three views. The title (ID/view) zooms out from days to months to years; picking a year zooms into its months, a month into its days. Prev/next (ID/prev, ID/next) step by a month, a year or a decade; a day that does not exist in the target month (January 31 to February) becomes that month's last day. Ids: days ID/YYYY-MM-DD, months ID/YYYY-MM, years ID/YYYY; the panel is ID, the field ID/field. Keyboard: arrows move within the view (by day and week, or across the 3-column month and year grids), PageUp/PageDown step like prev/next, Enter picks, Escape closes. Month and weekday names come from Theme.Strings.

func (DateField) Layout

Layout draws the field showing Value in Format and, while s is open, the calendar in a popover. It handles the calendar's view, paging and arrow keys while laying out, and keeps Value's zone and the week start for s.Update, which reports a picked day.

type DateFieldState

type DateFieldState struct {
	// Trigger is the field's press target; Update toggles the calendar
	// when it is clicked.
	Trigger kit.Clickable
	// contains filtered or unexported fields
}

DateFieldState is a DateField's interaction state. The zero value is closed; do not copy it after first use.

func (*DateFieldState) Opened

func (s *DateFieldState) Opened() bool

Opened reports whether the calendar is open.

func (*DateFieldState) Update

func (s *DateFieldState) Update(gtx layout.Context) (time.Time, bool)

Update returns a date picked since the last call, and handles the calendar's navigation. Call it in the handle pass. A pick closes the calendar and returns focus to the field.

type DialogContent

type DialogContent struct {
	Title   string          // the dialog's heading
	Body    layout.Widget   // the content under the heading; nil for none
	Actions []layout.Widget // buttons, laid out left to right at the bottom right
}

DialogContent is the standard dialog body for kit's Modal: a title, a body, and buttons right-aligned at the bottom (pass the primary action last).

func (DialogContent) Layout

func (dc DialogContent) Layout(gtx layout.Context, th *kit.Theme) layout.Dimensions

Layout draws the heading, body and action row; th.Modal provides the panel, focus trap and dismissal around it. It takes no input itself.

type Disclosure

type Disclosure struct {
	ID       string        // the header's id
	Title    string        // the header's visible and spoken text
	Trailing string        // a count or summary pill after the title
	Open     bool          // the controlled value: whether Body shows
	Body     layout.Widget // laid out only while Open
}

Disclosure is a section with a clickable header (chevron, title, an optional trailing count) that shows or hides Body. Flip Open when the Clickable reports a click (Enter/Space on the header too). The header id is ID.

if v.more.Clicked(gtx) { v.moreOpen = !v.moreOpen }
ui.Disclosure{ID: "more", Title: "More", Open: v.moreOpen, Body: body}.Layout(gtx, th, &v.more)

func (Disclosure) Layout

func (dc Disclosure) Layout(gtx layout.Context, th *kit.Theme, c *kit.Clickable) layout.Dimensions

Layout draws the header for c's state and, while Open, Body below it. It registers c as the header's press and focus target, with its semantic selected state following Open. It does not flip Open: read c.Clicked.

type EmptyState

type EmptyState struct {
	// ID is the group's id, Title its name and heading, Body the
	// explanation under it.
	ID, Title, Body string
	// Action, if set, draws a control below (a Button), with its own state.
	Action layout.Widget
}

EmptyState gives an empty view a title, explanation and optional action (a normal component, with its own focus and semantics).

func (EmptyState) Layout

func (es EmptyState) Layout(gtx layout.Context, th *kit.Theme) layout.Dimensions

Layout draws the message centred, at most th.ReadingWidth wide, inside a group named by Title. It handles no input; Action handles its own.

type FieldError

type FieldError struct {
	Message string // the error, in the user's language; "" draws nothing
}

FieldError draws an error message under a field; nothing when empty.

func (FieldError) Layout

func (f FieldError) Layout(gtx layout.Context, th *kit.Theme) layout.Dimensions

Layout draws Message as small text in the theme's Bad colour. It takes no input and has no semantic id.

type Form

type Form struct {
	ID     string      // the form's group id; rows are ID/<field ID>
	Fields []FormField // the rows, top to bottom
}

Form lays out labeled fields. At narrow widths it stacks labels above controls; wider, it aligns them in two columns. Errors and help text stay with their field in either layout. Rows are ID/<field ID>.

func (Form) Layout

func (f Form) Layout(gtx layout.Context, th *kit.Theme) layout.Dimensions

Layout draws the rows: two columns (labels at th.LabelWidth, capped at a third of the width) or, below th.NarrowWidth, labels stacked above their controls. It records the form and each row as named groups and handles no input itself; the controls handle theirs.

type FormField

type FormField struct {
	// ID names the row (ID/<field ID>) and Label is its visible and spoken
	// name. Help is a dim line under the control; Error, when set,
	// replaces it in the theme's Bad colour.
	ID, Label, Help, Error string
	// Control draws the control, stretched to the row's width.
	Control layout.Widget
}

FormField is one labeled control. Control draws the control with its own state and id (a TextField, a Select...); ID names the row.

type IconButton

type IconButton struct {
	ID     string   // the button's semantic id
	Icon   kit.Icon // nil draws an empty button
	Label  string   // the spoken name; required, since there is no text
	Active bool     // draw the icon at rest, not only while hovered
}

IconButton is a small square icon-only button. It stays quiet until hovered, or until Active (its row is hovered or selected) shows it at rest.

func (IconButton) Layout

func (b IconButton) Layout(gtx layout.Context, th *kit.Theme, c *kit.Clickable) layout.Dimensions

Layout draws the icon in a square hit target for c's state. It registers c as the press and focus target; read clicks with c.Clicked.

type Kbd

type Kbd struct {
	Chord string // a display chord, keys joined by "+" (kit.FormatChord's form)
}

Kbd renders a key chord as key caps: "Ctrl+K" is [Ctrl] [K], and "Ctrl++" is [Ctrl] [+]. Show a bound shortcut with Kbd{Chord: keymap.HintFor("file.save")}.

func (Kbd) Layout

func (k Kbd) Layout(gtx layout.Context, th *kit.Theme) layout.Dimensions

Layout draws one key cap per key, in a row. It takes no input.

type Link struct {
	ID   string // the link's semantic id
	Text string // the visible and spoken text
}

Link is an underlined text button, for navigation inside text-heavy UI.

func (Link) Layout

func (l Link) Layout(gtx layout.Context, th *kit.Theme, c *kit.Clickable) layout.Dimensions

Layout draws Text underlined, in the accent colour at rest and in Fg while hovered or focused. It registers c as the press and focus target; read clicks with c.Clicked. It opens nothing itself.

type Menu struct {
	ID      string        // the panel's id; items are ID/<item ID>
	Items   []MenuItem    // the rows, top to bottom
	Trigger layout.Widget // draws the opener with the state's Trigger
}

Menu is a dropdown menu: Trigger (drawn with the state's Trigger Clickable) and, while open, the items in a floating panel below it.

if id, ok := v.file.Update(gtx); ok { ... }   // handle pass
ui.Menu{ID: "file", Items: items, Trigger: func(gtx layout.Context) layout.Dimensions {
	return ui.Button{ID: "file:open", Text: "File", Style: ui.Ghost}.Layout(gtx, th, &v.file.Trigger)
}}.Layout(gtx, th, &v.file)

Keyboard: Enter/Space on the trigger opens it; the open menu is one focus group: Down/Up enter and move through the items (Home/End jump); Enter picks; Escape closes; Tab closes and returns focus to the trigger.

func (mn Menu) Layout(gtx layout.Context, th *kit.Theme, m *MenuState) layout.Dimensions

Layout draws Trigger and, while m is open, the item panel in a popover below it. It handles the panel's arrow keys, Enter and Tab; m.Update reports the pick and toggles the menu on trigger clicks.

type MenuItem struct {
	ID       string   // reported by Update; item ids are <menu id>/<ID>
	Label    string   // the row's visible and spoken text
	Icon     kit.Icon // optional, leading
	Shortcut string   // optional hint on the right ("Ctrl+S"); bind it in your Keymap
	Danger   bool     // destructive: drawn in Bad
	Disabled bool     // drawn dimmed; arrows skip it and it cannot be picked
	Divider  bool     // a separator line; other fields ignored
}

MenuItem is one row of a Menu or ContextMenu. The zero value of each field is the common case.

type MenuState struct {
	Trigger kit.Clickable // draw the Menu's trigger with it
	// contains filtered or unexported fields
}

MenuState is a Menu's or ContextMenu's interaction state. The zero value is closed; it holds event tags, so do not copy it after first use.

func (m *MenuState) Hide()

Hide closes the menu. Focus is not moved: a component closing it on the user's behalf returns focus itself.

func (m *MenuState) Opened() bool

Opened reports whether the menu is open.

func (m *MenuState) Show()

Show opens the menu: below its trigger, or for a ContextMenu where it last opened.

func (m *MenuState) Toggle()

Toggle opens a closed menu and closes an open one.

func (m *MenuState) Update(gtx layout.Context) (string, bool)

Update returns the id of an item chosen since the last call, and toggles the menu when its trigger is clicked. Call it in the handle pass. A pick closes the menu and returns focus to the trigger.

type NavItem struct {
	ID         string      // the entry's semantic id
	Label      string      // the visible and spoken text
	Trailing   string      // an optional value at the right edge (a count)
	TrailColor color.NRGBA // zero is Dim
	Active     bool        // the current page
}

NavItem is a full-width sidebar or list entry with an optional trailing value. A click focuses it quietly (no ring); inside a FocusGroup the group takes focus, so arrows work right after. Layout sets the Clickable's FocusOnClick: the Clickable belongs to this NavItem.

func (n NavItem) Layout(gtx layout.Context, th *kit.Theme, c *kit.Clickable) layout.Dimensions

Layout draws the entry at the full available width, highlighted while Active or hovered, and registers c as its press and focus target. Read c.Clicked to navigate.

type NumberField

type NumberField struct {
	ID          string // the editor's id; the buttons are ID/minus and ID/plus
	Placeholder string // dim hint text drawn while the editor is empty
	// Label is the spoken name of the field and names the value in the
	// buttons' spoken labels ("Increase Quantity"). Default Placeholder; one
	// of the two is required.
	Label string
	// Min and Max bound the value when Max > Min: steps clamp to them, and
	// typed text outside them is an error. Use math.Inf for a one-sided
	// bound (Min: 0, Max: math.Inf(1)). Otherwise the value is unbounded.
	Min, Max float64
	Step     float64         // the buttons' and arrow keys' step; 0 is 1
	Size     kit.ControlSize // ControlDefault is the theme's
}

NumberField is a numeric editor with − and + buttons (ID/minus, ID/plus); Up/Down in the field step too.

Its value is state-owned (see the package doc): the text being edited and the last valid number live in NumberFieldState. Set the value with SetValue, read changes from Update.

func (NumberField) Layout

Layout draws the editor and its − and + buttons from s. On first layout it writes s's value (0 unless SetValue ran) into the editor. It keeps the bounds and step for the next Update, which consumes the typing, the button clicks and the Up/Down keys.

type NumberFieldState

type NumberFieldState struct {
	// Editor holds the text being edited. Prefer SetValue to writing it.
	Editor      widget.Editor
	Minus, Plus kit.Clickable // the step buttons
	// contains filtered or unexported fields
}

NumberFieldState holds the editor, the buttons and the parsed value. The zero value is ready to use and starts at 0; like other states it must not be copied after first use.

func (*NumberFieldState) Error

func (s *NumberFieldState) Error(th *kit.Theme) string

Error is why the editor's text is not a valid value, in th's Strings, or "" when it is valid. Show it with FieldError.

func (*NumberFieldState) SetValue

func (s *NumberFieldState) SetValue(v float64)

SetValue sets the value and the editor's text, clearing any error.

func (*NumberFieldState) Update

func (s *NumberFieldState) Update(gtx layout.Context) (float64, bool)

Update returns the value when buttons, keys or typing changed it since the last call. Call it in the handle pass. All of a frame's input is applied in order and the final value returned once.

func (*NumberFieldState) Valid

func (s *NumberFieldState) Valid() bool

Valid reports whether the editor's text is a valid value.

func (*NumberFieldState) Value

func (s *NumberFieldState) Value() float64

Value is the last valid value: set by SetValue, a step, or text that parses within the bounds. Invalid text leaves it unchanged.

type Radio

type Radio struct {
	ID       string // the option's semantic id
	Label    string // drawn beside the circle and spoken
	Selected bool   // whether this option is the group's value
}

Radio is one option of a single-choice group: give each option its own Clickable (a kit.Pool keyed by value works) and set your value when one is clicked.

func (Radio) Layout

func (r Radio) Layout(gtx layout.Context, th *kit.Theme, c *kit.Clickable) layout.Dimensions

Layout draws the circle, with a dot when Selected, and the label for c's state, and registers c as the press and focus target. Read c.Clicked and set your value to this option.

type ReorderList

type ReorderList struct {
	ID string // the list's id; see the type doc for the row parts
	// Items are the rows, in order. Their IDs must be unique and non-empty.
	Items []Choice
	// Item, if set, draws an item's content: title, artwork, metadata. It
	// gets the row's fixed height. Without it the row shows the label.
	Item func(gtx layout.Context, c Choice) layout.Dimensions
}

ReorderList is a scrollable queue whose rows can be reordered: drag a row's handle (ID/<item>/drag; Up/Down while it is focused) or use its buttons (ID/<item>/up, ID/<item>/down). Rows have a fixed height, so a drag maps to an index without measuring offscreen content. Apply the moves Update reports to your items (Move does it for a slice).

func (ReorderList) Layout

Layout draws the visible rows at a fixed height, filling the available size, each with its drag handle and move buttons. It remembers the order and row height for s.Update, which turns drags, keys and button clicks into a move; Layout itself never reorders Items.

type ReorderListState

type ReorderListState struct {
	// List is the scroll position, anchored to the first visible item's
	// ID so a move does not make the view jump.
	List kit.AnchoredList
	// contains filtered or unexported fields
}

ReorderListState is a ReorderList's scroll, drag and button state. The zero value is ready; it must not be copied after first use.

func (*ReorderListState) Update

func (s *ReorderListState) Update(gtx layout.Context) (from, to int, ok bool)

Update reports a move requested since the last call: the item at index from moves to index to, shifting the items between. Apply it to your items in the handle pass, before Layout.

A button or arrow key moves an item one place. A drag moves it by the rows the pointer travelled between press and release, rounded to the nearest row and clamped to the list: past half a row it moves.

One move a frame: every request is computed against the order as last laid out, so any other request in the same frame is dropped.

type Select

type Select struct {
	ID string // the select's id; see the type doc for its parts
	// Options are the choices: Label is shown in the field, spoken, and drawn
	// unless Option is set; ID addresses the option and is what Update
	// reports. IDs must be unique and stable.
	Options  []Choice
	Selected string // the selected option's ID; "" (or an unknown ID) shows an empty field
	// Option, if set, draws an option's row content (an avatar beside a
	// name); the option's Label still names it for screen readers. It must
	// only draw (see kit.MenuRow.Content).
	Option func(gtx layout.Context, c Choice) layout.Dimensions
	Size   kit.ControlSize // ControlDefault is the theme's
}

Select is a dropdown field showing the selected option; it lists the options in a floating panel, the selected one checked and focused (so arrows start from it). Field id ID/field, options ID/<option ID>, the list ID/list (scrolls past Theme.ListMaxHeight). The panel is at least as wide as the field.

if id, ok := v.size.Update(gtx); ok { v.sizeID = id }   // handle pass
ui.Select{ID: "size", Options: sizes, Selected: v.sizeID}.Layout(gtx, th, &v.size)

func (Select) Layout

func (sl Select) Layout(gtx layout.Context, th *kit.Theme, s *SelectState) layout.Dimensions

Layout draws the field with the selected option's label and, while s is open, the option list in a popover at least as wide as the field. It handles the list's keys; s.Update reports the pick and toggles the list on field clicks.

type SelectState

type SelectState struct {
	// contains filtered or unexported fields
}

SelectState is a Select's interaction state. The zero value is closed; do not copy it after first use.

func (*SelectState) Hide

func (s *SelectState) Hide()

Hide closes the option list.

func (*SelectState) Opened

func (s *SelectState) Opened() bool

Opened reports whether the option list is open.

func (*SelectState) Show

func (s *SelectState) Show()

Show opens the option list.

func (*SelectState) Update

func (s *SelectState) Update(gtx layout.Context) (string, bool)

Update returns the ID of an option picked since the last call, and toggles the dropdown when the field is clicked. Call it in the handle pass, then draw with the new selection. A pick closes the list and returns focus to the field.

type SelectableList

type SelectableList struct {
	ID string // the listbox's id; rows are ID/<choice ID>
	// Items are the rows, in order. Their IDs must be unique and non-empty.
	Items []Choice
	// Selected is the selected item's ID (controlled); "" selects nothing.
	Selected string
	// Item, if set, draws item i's content inside the row (its label is
	// still spoken).
	Item func(gtx layout.Context, i int) layout.Dimensions
	// Multiple allows choosing several items: Ctrl/Cmd-click toggles,
	// Shift-click and Shift+Up/Down select a range, Ctrl/Cmd+A all. Chosen is
	// the set (yours, controlled); Selected stays the focused item. The
	// control reads Chosen during layout and never modifies it.
	Multiple bool
	Chosen   map[string]bool // the chosen IDs while Multiple; nil is none
}

SelectableList is a scrolling list with one selected item, or several with Multiple. It is one Tab stop; Up/Down/Home/End move the selection and typing a label's first letters jumps to it. Rows are ID/<choice ID>, with role option in a listbox.

if e, ok := v.list.Update(gtx); ok { v.sel = e.Selected }        // handle pass
ui.SelectableList{ID: "files", Items: files, Selected: v.sel}.Layout(gtx, th, &v.list)

func (SelectableList) Layout

Layout draws the visible rows, filling the available size, with Selected (and Chosen) highlighted, and makes them one focus group. It handles the arrow keys and type-ahead while laying out and queues the change for s.Update, which also reports clicks.

type SelectableListState

type SelectableListState struct {
	// List is the scroll position. Read or set it between frames
	// (List.ScrollIntoView, the embedded Position) to save or restore it.
	List kit.List
	// contains filtered or unexported fields
}

SelectableListState is a SelectableList's scroll and selection state. The zero value is ready; it must not be copied after first use.

func (*SelectableListState) Update

Update reports a selection change made by clicks and keys since the last call: call it in the handle pass, before Layout. Several moves in one frame are reported together as one event.

type SelectionEvent

type SelectionEvent struct {
	// Selected is the selected item; with Multiple, the focused one. It is
	// set on every event, changed or not.
	Selected string
	// Chosen is a Multiple control's chosen set after the change: a new map
	// the control does not keep, or the props' own Chosen when only Selected
	// changed. It is nil for single selection.
	Chosen map[string]bool
}

SelectionEvent is a change reported by the Update of a SelectableList, Tree or DataTable: a click or key chose a new item, or (with Multiple) a new chosen set. Apply it to the props you pass next frame.

type Shortcut

type Shortcut struct {
	Title  string   // what the shortcut does
	Chords []string // display chords (kit.FormatChord's form), any of which works
}

Shortcut is one row of a ShortcutList: what it does and the chords that do it.

func ShortcutsFrom

func ShortcutsFrom(km *kit.Keymap) []Shortcut

ShortcutsFrom lists a keymap's bindings as rows, in the order bound, merging bindings that share a title into one row with several chords.

type ShortcutGroup

type ShortcutGroup struct {
	Title string // a caption over the rows; "" for none
	Items []Shortcut
}

ShortcutGroup is a titled set of rows in a ShortcutList.

type ShortcutList

type ShortcutList struct {
	Groups []ShortcutGroup
}

ShortcutList lays out groups of keyboard shortcuts, for a help dialog: each group's caption, then a row per shortcut with its title on the left and its chords as key caps on the right. It fills the width and takes no input.

func (ShortcutList) Layout

func (s ShortcutList) Layout(gtx layout.Context, th *kit.Theme) layout.Dimensions

Layout draws the groups top to bottom.

type Slider

type Slider struct {
	ID    string  // the slider's semantic id
	Label string  // spoken name
	Value float32 // the controlled value, 0..1
}

Slider is a horizontal slider over 0..1. It is controlled: set Value from what SliderState.Update returns. Values outside 0..1 are drawn clamped.

Press or drag anywhere on it to set the value. It is focusable: Left/Right (or Down/Up) step by 5%, Home/End jump to the ends, and the wheel adjusts it while focused. Unfocused, or already at the end it is pushed toward, it leaves the wheel to its parent (the page scrolls). Keys it does not use (Enter, shortcuts) reach the enclosing KeyContext.

func (Slider) Layout

func (sl Slider) Layout(gtx layout.Context, th *kit.Theme, s *SliderState) layout.Dimensions

Layout draws the track and knob at Value across the full available width and registers s for drags, focus, keys and (while focused) the wheel. It keeps the geometry and Value for s.Update, which consumes that input. Inside th.Disable it registers no handlers.

type SliderState

type SliderState struct {
	// contains filtered or unexported fields
}

SliderState is a Slider's interaction state and last frame's geometry, so Update can resolve input before layout. The zero value is ready to use. It is its own event tag: do not copy it after first use.

func (*SliderState) Dragging

func (s *SliderState) Dragging() bool

Dragging reports whether the slider is being dragged.

func (*SliderState) Update

func (s *SliderState) Update(gtx layout.Context) (float32, bool)

Update returns the value input set since the last call (drag, click, wheel, keys). Call it in the handle pass. All of a frame's events are applied in order, and the last value is returned.

type Split

type Split struct {
	ID   string        // the divider's id
	Axis layout.Axis   // Horizontal: panes side by side; Vertical: stacked
	Min  unit.Dp       // minimum pane size; 0 is Theme.PaneMinSize
	A, B layout.Widget // the first (left or top) and second panes
}

Split is a resizable two-pane layout. Drag the divider, or focus it (Tab) and use the arrow keys; keys it does not use reach the enclosing KeyContext. The divider's id is ID.

Split fills its maximum constraints. Each pane keeps at least Min along the axis while there is room for both; when there is not, the panes share the space equally. With no room at all (zero size), both panes are laid out with zero size.

func (Split) Layout

func (sp Split) Layout(gtx layout.Context, th *kit.Theme, s *SplitState) layout.Dimensions

Layout draws both panes and the divider at s.Ratio, filling its maximum constraints. It handles the divider's drags, hover and arrow keys itself (see the package doc), clamps s.Ratio and leaves the result in it; there is no Update.

type SplitState

type SplitState struct {
	Ratio float32 // the first pane's share, 0..1; see above
	// contains filtered or unexported fields
}

SplitState holds the divider position. Unlike most component values it is owned by the state: dragging is continuous interaction, so the split keeps its own Ratio rather than round-tripping it through props.

Ratio is the first pane's share of the space along the axis, in 0..1; 0 means unset and becomes 0.5 at the first layout. Set it before layout to restore a saved split; it is clamped to keep both panes at least Min. Read it after layout to save it with your app state. A SplitState is its own event tag: do not copy it after first use.

type Stat

type Stat struct {
	Title, Value string      // an uppercase caption above a large value
	ValueColor   color.NRGBA // zero is Fg
}

Stat is a card with a caption and a big value; it fills the width (use it inside Flexed for equal-width rows).

func (Stat) Layout

func (s Stat) Layout(gtx layout.Context, th *kit.Theme) layout.Dimensions

Layout draws the card at the full available width. It takes no input.

type Stepper

type Stepper struct {
	ID         string      // the stepper's id; buttons are ID/minus and ID/plus
	Label      string      // names the value in the buttons' spoken labels ("Increase %s"); required
	Value      string      // the value, formatted by the caller
	ValueColor color.NRGBA // zero is Fg
	Active     bool        // show the buttons at rest (its row is hovered)
}

Stepper is "− value +" around a value you own; its buttons are ID/minus and ID/plus. Change the value when their Clickables report clicks.

func (Stepper) Layout

func (sp Stepper) Layout(gtx layout.Context, th *kit.Theme, s *StepperState) layout.Dimensions

Layout draws "− value +" with the value centred in a fixed width. It registers the two buttons and changes nothing itself.

type StepperState

type StepperState struct {
	Minus, Plus kit.Clickable // the − and + buttons
}

StepperState holds the two buttons: read Minus.Clicked and Plus.Clicked in the handle pass. The zero value is ready to use; do not copy it after first use.

type Switch

type Switch struct {
	ID    string // the control's semantic id
	Label string // drawn beside the track and spoken
	On    bool   // the controlled value; the thumb animates toward it
}

Switch is an on/off toggle whose thumb slides. Flip your bool when the Clickable reports a click. The label is part of the click target.

func (Switch) Layout

func (sw Switch) Layout(gtx layout.Context, th *kit.Theme, c *kit.Clickable) layout.Dimensions

Layout draws the track, the thumb and the label for c's state, and registers c as the press and focus target. It does not flip On: read c.Clicked in the handle pass and flip your value.

type TabStyle

type TabStyle int

TabStyle picks how Tabs draws its selection.

const (
	TabsUnderline TabStyle = iota // text tabs with a sliding underline
	TabsSegmented                 // a segmented control: a sliding pill on a track
)

type Tabs

type Tabs struct {
	ID string // the tab list's id; tabs are ID/<item ID>
	// Items are the tabs: Label is shown and spoken, ID addresses the tab
	// and is what Update reports. IDs must be unique and stable; labels may
	// repeat or be translated.
	Items    []Choice
	Selected string   // the selected item's ID; "" (or an unknown ID) selects none
	Style    TabStyle // TabsUnderline (the zero value) or TabsSegmented
}

Tabs is a row of tabs with one selected. It is one Tab stop (WAI-ARIA tabs): Left/Right move the selection, Home/End jump to the ends, Enter/Space re-pick the focused tab. Ids are ID/<item ID>.

if id, ok := v.tabs.Update(gtx); ok { v.tab = id }        // handle pass
ui.Tabs{ID: "view", Items: views, Selected: v.tab}.Layout(gtx, th, &v.tabs)

func (Tabs) Layout

func (tb Tabs) Layout(gtx layout.Context, th *kit.Theme, s *TabsState) layout.Dimensions

Layout draws the tabs with the animated indicator under Selected and makes them one focus group. It handles the arrow, Home and End keys while laying out and queues the keyboard pick for s.Update, which also reports clicks.

type TabsState

type TabsState struct {
	// contains filtered or unexported fields
}

TabsState is a Tabs' interaction state and animated indicator. The zero value is ready to use; do not copy it after first use.

func (*TabsState) Update

func (s *TabsState) Update(gtx layout.Context) (string, bool)

Update returns the ID of a tab picked (clicked, or moved to with the keyboard) since the last call. A click on the selected tab reports it too. Keys are handled while Tabs lays out, so a keyboard pick is reported by the next frame's Update (Tabs asks for that frame). It reports one pick per call, the keyboard's first, and leaves further clicks for the next call.

type TextArea

type TextArea struct {
	ID          string // the field's semantic id; the editor's area carries it
	Placeholder string // dim hint text drawn while the editor is empty
	Label       string // spoken name; default Placeholder
	Lines       int    // minimum height in text lines; below 1 is 1
}

TextArea is a multi-line input (Enter inserts a newline) at least Lines lines tall; it grows with its text.

func (TextArea) Layout

func (f TextArea) Layout(gtx layout.Context, th *kit.Theme, e *widget.Editor) layout.Dimensions

Layout draws the field chrome and the multi-line editor e inside it. It clears e.SingleLine every frame. Read text changes from e's own events.

type TextField

type TextField struct {
	ID          string          // the field's semantic id; the editor's area carries it
	Placeholder string          // dim hint text drawn while the editor is empty
	Label       string          // spoken name; default Placeholder
	Icon        kit.Icon        // optional leading icon (IconSearch for a search box)
	Password    bool            // mask the text (the value is unchanged); it sets the editor's Mask
	Size        kit.ControlSize // ControlDefault is the theme's
}

TextField is a single-line input around a widget.Editor. Read and set the text on the editor; set e.Submit yourself if Enter should submit. The border becomes a focus ring while the editor is focused.

ui.TextField{ID: "name", Placeholder: "Name"}.Layout(gtx, th, &v.name)

func (TextField) Layout

func (f TextField) Layout(gtx layout.Context, th *kit.Theme, e *widget.Editor) layout.Dimensions

Layout draws the field chrome and the editor e inside it. It sets e.SingleLine and e.Mask from the props every frame, so do not set those on e yourself. Read text changes and submits from e's own events.

type ToastHost

type ToastHost struct {
	ID       string        // the toasts' ids are ID/<n>; "" is "toasts"
	Page     layout.Widget // the window's content, drawn under the toasts
	Duration time.Duration // how long each toast stays; 0 is ToastDuration
}

ToastHost lays out Page with the toasts stacked above it, bottom right, the newest at the bottom. Each closes itself after Duration, or with its dismiss button. Wrap the whole window with it.

Toasts are ToastWidth wide, narrowed to fit a smaller window inside the margins; a window with no room inside the margins shows none, though they still expire.

func (ToastHost) Layout

func (host ToastHost) Layout(gtx layout.Context, th *kit.Theme, ts *Toasts) layout.Dimensions

Layout drops expired and dismissed toasts from ts, draws Page, then the remaining toasts in a kit.Layer. It schedules a frame for the next expiry, so toasts leave on time without input; there is no Update.

type Toasts

type Toasts struct {
	// contains filtered or unexported fields
}

Toasts is a stack of transient notifications shown by a ToastHost. Push from the handle pass or a Spawn callback; the UI goroutine owns it. The zero value is empty; do not copy it after first use.

func (*Toasts) Len

func (ts *Toasts) Len() int

Len is the number of toasts showing.

func (*Toasts) Push

func (ts *Toasts) Push(s kit.Status, title, body string)

Push adds a toast; it shows on the next frame. Toasts are numbered from 1 in push order: the host shows toast n as <host ID>/n with its dismiss button <host ID>/n/dismiss.

type Toolbar

type Toolbar struct {
	ID      string          // the group's id; actions are ID/<action ID>
	Actions []ToolbarAction // left to right, wrapping
}

Toolbar is a row of actions that wraps onto another line when space is short. Each action keeps its full text and normal focus behaviour. The group is named by Theme.Strings.Toolbar; action ids are ID/<action ID>.

if id, ok := v.tools.Update(gtx); ok { ... }   // handle pass
ui.Toolbar{ID: "tools", Actions: actions}.Layout(gtx, th, &v.tools)

func (Toolbar) Layout

func (tb Toolbar) Layout(gtx layout.Context, th *kit.Theme, s *ToolbarState) layout.Dimensions

Layout draws one Button per action from s's buttons, wrapping onto new lines, and records the toolbar group. It remembers the actions for s.Update, which reports clicks; it drops buttons of departed actions.

type ToolbarAction

type ToolbarAction struct {
	ID, Text string      // stable id within the toolbar, and visible text
	Icon     kit.Icon    // optional, before the text
	Style    ButtonStyle // nil is Secondary
	Disabled bool        // dimmed, out of the Tab order, never reported
}

ToolbarAction is one toolbar button, reported by ToolbarState.Update with its ID. IDs must be unique within the toolbar and stable.

type ToolbarState

type ToolbarState struct {
	// contains filtered or unexported fields
}

ToolbarState holds a Toolbar's buttons, one per action ID. Buttons of actions that leave the toolbar are dropped a few frames later. The zero value is ready to use; do not copy it after first use.

func (*ToolbarState) Update

func (s *ToolbarState) Update(gtx layout.Context) (string, bool)

Update returns the ID of an action clicked since the last call. Call it in the handle pass; a second click in the same frame is returned by the next call.

type Tooltip

type Tooltip struct {
	ID      string        // the tooltip node's id while it shows
	Text    string        // the tip, in the user's language
	Content layout.Widget // the control the tip describes
}

Tooltip shows Text below Content after the pointer rests on it for TooltipDelay, and at once while focus is inside Content (a focused button shows its tooltip). Escape hides it until the pointer leaves and focus moves on. Clicks still reach the content.

While showing, the tooltip is a node of its own: id ID, role tooltip, labelled Text. It supplements Content, which still needs its own label.

func (Tooltip) Layout

func (tt Tooltip) Layout(gtx layout.Context, th *kit.Theme, s *TooltipState) layout.Dimensions

Layout draws Content and, while the tip shows, a fading bubble below it in a kit.Layer. It handles hover timing and Escape itself, scheduling the frame that shows the tip; there is no Update.

type TooltipState

type TooltipState struct {
	// contains filtered or unexported fields
}

TooltipState is a Tooltip's hover timing and fade. The zero value is hidden; it holds an event tag, so do not copy it after first use.

type Tree

type Tree struct {
	ID string // the tree's id; see the type doc for the row parts
	// Roots are the top-level nodes, in order.
	Roots []TreeNode
	// Selected is the selected node's ID (controlled); "" selects nothing.
	Selected string
	// Node, if set, draws a node's content inside its row (an icon beside
	// the label); the label is still spoken.
	Node func(gtx layout.Context, n TreeNode) layout.Dimensions
	// Multiple and Chosen: as for SelectableList (ranges follow the visible rows).
	Multiple bool
	Chosen   map[string]bool // the chosen IDs while Multiple; nil is none
}

Tree is a scrolling tree with one selected node, or several with Multiple. Keyboard (WAI-ARIA): Up/Down/Home/End move; Right opens a closed node or moves to its first child; Left closes an open node or moves to its parent; typing a label's first letters jumps to it. Rows are ID/<node ID> (role treeitem), expand toggles ID/<node ID>/toggle.

Which nodes are expanded is retained interaction state, owned by TreeState rather than passed in props: the user opens and closes nodes, and the app may preset or read them with SetExpanded and Expanded.

func (Tree) Layout

func (t Tree) Layout(gtx layout.Context, th *kit.Theme, s *TreeState) layout.Dimensions

Layout draws the visible rows (nodes under expanded ancestors), filling the available size, indented by depth, with Selected highlighted, and makes them one focus group. It handles the arrow keys (Right and Left expand and collapse in s) and type-ahead while laying out; s.Update reports the selection change and runs the expand toggles.

type TreeNode

type TreeNode struct {
	ID, Label string     // the node's stable id and visible, spoken text
	Children  []TreeNode // nil or empty for a leaf
}

TreeNode is a nested item; IDs must be unique, non-empty and stable across frames.

type TreeState

type TreeState struct {
	List kit.List // the scroll position (see SelectableListState.List)
	// contains filtered or unexported fields
}

TreeState is a Tree's scroll, expansion and selection state. The zero value is ready, with every node closed; it must not be copied after first use.

func (*TreeState) Expanded

func (s *TreeState) Expanded(id string) bool

Expanded reports whether node id is open.

func (*TreeState) SetExpanded

func (s *TreeState) SetExpanded(id string, open bool)

SetExpanded opens or closes node id. It takes effect at the next layout; expansion is kept for ids that are not (or no longer) in the tree.

func (*TreeState) Update

func (s *TreeState) Update(gtx layout.Context) (SelectionEvent, bool)

Update runs the expand toggles and reports a selection change made since the last call (see SelectableListState.Update).

Jump to

Keyboard shortcuts

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