Documentation
¶
Index ¶
- Constants
- Variables
- func ContainerContentSize(container Element) image.Point
- func ElementBounds(root, target Element) (image.Rectangle, bool)
- func ReducedMotion() bool
- func SetScrollbarDefault(mode ScrollbarMode)
- func VisitWidgets(root Element, metric unit.Metric, visit func(core.Widget, image.Rectangle))
- func WriteClipboard(text string)
- type Align
- type Context
- func (cx *Context) Action(name string, fn func())
- func (cx *Context) ActionAt(targetID, action string, fn func())
- func (cx *Context) After(key any, d time.Duration, fn func())
- func (cx *Context) AfterEnabled(id string, key any, d time.Duration, fn func())
- func (cx *Context) Animating()
- func (cx *Context) Cache(key any, build func() Element) Element
- func (cx *Context) ClickModifiers() key.Modifiers
- func (cx *Context) Countdown(id string, key any, d time.Duration, paused bool, fn func())
- func (cx *Context) Enabled(id string) bool
- func (cx *Context) Focus(id string)
- func (cx *Context) FocusVisible(id string) bool
- func (cx *Context) FocusWithin(id string) bool
- func (cx *Context) Focused(id string) bool
- func (cx *Context) Hovered(id string) bool
- func (cx *Context) InputAction(id string, action InputAction)
- func (cx *Context) InputSelection(id string) (InputEdit, bool)
- func (cx *Context) LastSize(id string) (width, height float32)
- func (cx *Context) LayoutSize(element Element) (width, height float32)
- func (cx *Context) Mount(key any, view View)
- func (cx *Context) Mounted(key any) bool
- func (cx *Context) MountedView(key any) View
- func (cx *Context) Now() time.Time
- func (cx *Context) Overlay(key any, layer *Layer)
- func (cx *Context) PaintGeometry() (origin image.Point, viewport image.Rectangle)
- func (cx *Context) Perform(targetID, action string) bool
- func (cx *Context) PixelScale() float32
- func (cx *Context) ScrollBy(dy int) int
- func (cx *Context) ScrollIntoView(id string, top, bottom float32)
- func (cx *Context) ScrollIntoViewX(id string, left, right float32)
- func (cx *Context) ScrollState(id string) (offset, viewport, content float32)
- func (cx *Context) ScrollStateX(id string) (offset, viewport, content float32)
- func (cx *Context) ScrollTo(id string, offset float32)
- func (cx *Context) ScrollToX(id string, offset float32)
- func (cx *Context) SelectInput(id string, start, end int)
- func (cx *Context) Shortcut(chord string, fn func())
- func (cx *Context) Themed(p theme.Palette, v View) *DivEl
- func (cx *Context) Unmount(key any)
- func (cx *Context) ViewportSize() (width, height float32)
- type DivEl
- type DragEvent
- type DragKind
- type Edges
- type Element
- type InputAction
- type InputContent
- type InputDocument
- func (d *InputDocument) Content() InputContent
- func (d *InputDocument) ReplaceWithToken(token InputToken) error
- func (d *InputDocument) Select(r InputRange) error
- func (d *InputDocument) SelectedToken() (InputToken, bool)
- func (d *InputDocument) Selection() InputRange
- func (d *InputDocument) SetContent(c InputContent)
- func (d *InputDocument) SetText(text string) error
- type InputEdit
- type InputEl
- func (e *InputEl) AutoGrow(minRows, maxRows int) *InputEl
- func (e *InputEl) Bind(p *string) *InputEl
- func (e *InputEl) CaptureKeys(names ...string) *InputEl
- func (e *InputEl) Document(d *InputDocument) *InputEl
- func (e *InputEl) Filter(chars string) *InputEl
- func (e *InputEl) MaxLen(n int) *InputEl
- func (e *InputEl) OnChange(fn func(string)) *InputEl
- func (v *InputEl) OnPaste(fn func(core.ClipboardData) bool) *InputEl
- func (v *InputEl) OnPasteError(fn func(error)) *InputEl
- func (e *InputEl) OnSubmit(fn func(string)) *InputEl
- func (e *InputEl) OnTokenActivate(fn func(InputToken)) *InputEl
- func (e *InputEl) Password() *InputEl
- func (v *InputEl) PasteReader(reader core.ClipboardReader) *InputEl
- func (e *InputEl) Placeholder(s string) *InputEl
- func (e *InputEl) ReadOnly(on bool) *InputEl
- func (e *InputEl) SelectOnFocus(on bool) *InputEl
- func (e *InputEl) TokenRenderer(fn InputTokenRenderer) *InputEl
- func (e *InputEl) Transform(fn func(InputEdit) InputEdit) *InputEl
- func (e *InputEl) TransformEdit(fn func(before, after InputEdit) InputEdit) *InputEl
- type InputRange
- type InputToken
- type InputTokenRenderer
- type InputTokenSpan
- type KeyEvent
- type KeyState
- type Layer
- func (l *Layer) Arrow(on bool) *Layer
- func (l *Layer) BeforeDismiss(fn func() bool) *Layer
- func (l *Layer) KeepOnEscape() *Layer
- func (l *Layer) KeepOnOutsidePress() *Layer
- func (l *Layer) MatchAnchorWidth() *Layer
- func (l *Layer) Modal() *Layer
- func (l *Layer) Offset(dp float32) *Layer
- func (l *Layer) OnDismiss(fn func()) *Layer
- func (l *Layer) OnEscape(fn func() bool) *Layer
- func (l *Layer) Owner(id string) *Layer
- func (l *Layer) Placement(side Side, align Align) *Layer
- func (l *Layer) Scrim(on bool) *Layer
- func (l *Layer) TopInset(dp float32) *Layer
- func (l *Layer) TrapFocus() *Layer
- type Length
- type Node
- type RootWidget
- type ScrollEvent
- type ScrollRange
- type ScrollbarMode
- type Side
- type Style
- type Styled
- func (s *Styled[T]) Absolute() *T
- func (s *Styled[T]) Active(fn func(*Style)) *T
- func (s *Styled[T]) AspectRatio(ratio float32) *T
- func (s *Styled[T]) Bg(c color.NRGBA) *T
- func (s *Styled[T]) BgGradient(g theme.Gradient) *T
- func (s *Styled[T]) Bold() *T
- func (s *Styled[T]) Border(dp float32, c color.NRGBA) *T
- func (s *Styled[T]) BorderDashed(on bool) *T
- func (s *Styled[T]) Bottom(dp float32) *T
- func (s *Styled[T]) Center() *T
- func (s *Styled[T]) Child(children ...Element) *T
- func (s *Styled[T]) Children(children []Element) *T
- func (s *Styled[T]) Col() *T
- func (s *Styled[T]) ColSpan(columns int) *T
- func (s *Styled[T]) ContentBottom(target Element) *T
- func (s *Styled[T]) Cursor(c pointer.Cursor) *T
- func (s *Styled[T]) CursorPointer() *T
- func (s *Styled[T]) Decorate(fn func(gtx core.C, draw func())) *T
- func (s *Styled[T]) Disabled(v bool) *T
- func (s *Styled[T]) DisabledStyle(fn func(*Style)) *T
- func (s *Styled[T]) DragAccept(fn func(dx, dy float32) bool) *T
- func (s *Styled[T]) Flex(w float32) *T
- func (s *Styled[T]) FocusOnPress(id string) *T
- func (s *Styled[T]) FocusStyle(fn func(*Style)) *T
- func (s *Styled[T]) FocusTrap(on bool) *T
- func (s *Styled[T]) Focusable(on bool) *T
- func (s *Styled[T]) Gap(dp float32) *T
- func (s *Styled[T]) Grid(columns int) *T
- func (s *Styled[T]) Grow() *T
- func (s *Styled[T]) H(l Length) *T
- func (s *Styled[T]) HFull() *T
- func (s *Styled[T]) Hidden(h bool) *T
- func (s *Styled[T]) Hover(fn func(*Style)) *T
- func (s *Styled[T]) ID(id string) *T
- func (s *Styled[T]) IsHidden() bool
- func (s *Styled[T]) Items(a Align) *T
- func (s *Styled[T]) Justify(a Align) *T
- func (s *Styled[T]) KeepBottomOn(version int) *T
- func (s *Styled[T]) KeyContext(name string) *T
- func (s *Styled[T]) Left(dp float32) *T
- func (s *Styled[T]) LineHeight(scale float32) *T
- func (s *Styled[T]) M(v float32) *T
- func (s *Styled[T]) MaxH(l Length) *T
- func (s *Styled[T]) MaxLines(n int) *T
- func (s *Styled[T]) MaxW(l Length) *T
- func (s *Styled[T]) Mb(v float32) *T
- func (s *Styled[T]) Medium() *T
- func (s *Styled[T]) MinH(l Length) *T
- func (s *Styled[T]) MinW(l Length) *T
- func (s *Styled[T]) Ml(v float32) *T
- func (s *Styled[T]) Mono() *T
- func (s *Styled[T]) Mr(v float32) *T
- func (s *Styled[T]) Mt(v float32) *T
- func (s *Styled[T]) Mx(v float32) *T
- func (s *Styled[T]) My(v float32) *T
- func (s *Styled[T]) Name(name string) *T
- func (s *Styled[T]) NoShrink() *T
- func (s *Styled[T]) OnClick(fn func()) *T
- func (s *Styled[T]) OnContextMenu(fn func()) *T
- func (s *Styled[T]) OnDoubleClick(fn func()) *T
- func (s *Styled[T]) OnDrag(fn func(DragEvent)) *T
- func (s *Styled[T]) OnKey(fn func(KeyEvent) bool) *T
- func (s *Styled[T]) OnMousePress(button pointer.Buttons, fn func()) *T
- func (s *Styled[T]) OnScroll(x, y ScrollRange, fn func(ScrollEvent)) *T
- func (s *Styled[T]) Opacity(a float32) *T
- func (s *Styled[T]) P(v float32) *T
- func (s *Styled[T]) Pb(v float32) *T
- func (s *Styled[T]) PinLeft(dp float32) *T
- func (s *Styled[T]) PinRight(dp float32) *T
- func (s *Styled[T]) Pl(v float32) *T
- func (s *Styled[T]) Pr(v float32) *T
- func (s *Styled[T]) Pt(v float32) *T
- func (s *Styled[T]) Px(v float32) *T
- func (s *Styled[T]) Py(v float32) *T
- func (s *Styled[T]) Reveal(fraction float32) *T
- func (s *Styled[T]) Right(dp float32) *T
- func (s *Styled[T]) Role(role string) *T
- func (s *Styled[T]) Rounded(dp float32) *T
- func (s *Styled[T]) RoundedCorners(topLeft, topRight, bottomRight, bottomLeft float32) *T
- func (s *Styled[T]) Row() *T
- func (s *Styled[T]) ScrollOffset(x, y float32) *T
- func (s *Styled[T]) ScrollToEndOn(version int) *T
- func (s *Styled[T]) ScrollX() *T
- func (s *Styled[T]) ScrollY() *T
- func (s *Styled[T]) Scrollbars(mode ScrollbarMode) *T
- func (s *Styled[T]) Selected(v bool) *T
- func (s *Styled[T]) Shadow(e theme.Elevation) *T
- func (s *Styled[T]) Size(l Length) *T
- func (s *Styled[T]) StickToBottom() *T
- func (s *Styled[T]) TabIndex(index int) *T
- func (s *Styled[T]) TabStop(on bool) *T
- func (s *Styled[T]) TextAlign(a Align) *T
- func (s *Styled[T]) TextColor(c color.NRGBA) *T
- func (s *Styled[T]) TextSize(sp float32) *T
- func (s *Styled[T]) Top(dp float32) *T
- func (s *Styled[T]) Translate(x, y float32) *T
- func (s *Styled[T]) Value(v string) *T
- func (s *Styled[T]) W(l Length) *T
- func (s *Styled[T]) WFull() *T
- func (s *Styled[T]) When(cond bool, fn func(*T)) *T
- func (s *Styled[T]) Wrap() *T
- func (s *Styled[T]) WrapFit() *T
- type TextEl
- type TextRange
- type View
- type ViewFunc
- type WidgetEl
Constants ¶
const ScrollbarLinger = 900 * time.Millisecond
ScrollbarLinger is the idle delay before Scrolling mode hides the bars.
Variables ¶
var Auto = Length{}
Auto sizes an element to its content, or stretches it where the parent aligns items with Stretch.
var Full = Frac(1)
Full is Frac(1).
Functions ¶
func ContainerContentSize ¶
ContainerContentSize reports a container's laid-out content size in pixels, before its own Min/Max dimensions or Reveal are applied. Call after layout, for example from Decorate. Text, input and widget leaves return zero.
func ElementBounds ¶
ElementBounds returns target's border box relative to root after layout, before scrolling translations. Hidden and unrelated elements return false. Call from Decorate, using elements from the current tree.
func ReducedMotion ¶
func ReducedMotion() bool
ReducedMotion returns the application override; platforms without a native preference bridge default to false. Set through theme.SetReducedMotion.
func SetScrollbarDefault ¶ added in v0.0.5
func SetScrollbarDefault(mode ScrollbarMode)
SetScrollbarDefault sets the mode of scroll containers that do not choose one, ScrollbarAlways by default. Pass ScrollbarSystem to follow the platform. Windows redraw on their next frame.
func VisitWidgets ¶
VisitWidgets visits widgets in tree order with their content bounds relative to root, after layout. It includes widgets outside the viewport, skips hidden elements, and reports layout coordinates before any ScrollY translations.
func WriteClipboard ¶
func WriteClipboard(text string)
WriteClipboard copies text to the system clipboard. Call it from a handler, e.g. a copy button's OnClick; it takes effect in the current frame.
Types ¶
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context is passed to Render.
func (*Context) Action ¶
Action handles a named action from the keymap (core.Bind) while the window has focus and this view is rendered: every chord bound to name runs fn. Rebinding takes effect on the next frame; an unbound action does nothing.
func (*Context) ActionAt ¶
ActionAt handles an action while focus is within targetID, resolving chords through its current KeyContext ancestry and then core.Bind. Declare it every frame. Do not also register the same action through the global Action method. The innermost focused target wins for repeated actions or chords; ties use declaration order. An inner empty binding also suppresses outer handlers. Perform runs the handler as if from targetID (see Perform).
func (*Context) After ¶
After declares a one-shot timer with a comparable key unique to this root. Declare the key on every Render while the timer is alive; omitting it cancels it. Changing d restarts the timer. A fired timer does not rearm until omitted for a frame. Do not declare timers in Cache builders, which may not run again.
func (*Context) AfterEnabled ¶
AfterEnabled is After scoped to a visible, enabled element ID. Its full delay restarts after that element or an ancestor is disabled, hidden, or covered by a modal layer. Declare it every Render, like After.
func (*Context) Animating ¶
func (cx *Context) Animating()
Animating requests the next animation frame without spawning a goroutine.
func (*Context) Cache ¶
Cache returns the element built for key, calling build only when key was not used in the previous frame. While the width it is given stays the same, the element's layout is reused too, so long, mostly unchanging content (a chat history, a rendered document) costs little per frame. key must be comparable and change whenever the element would look different; the element must not depend on anything else. Entries unused for a frame are dropped. Applying a theme also rebuilds cached elements.
func (*Context) ClickModifiers ¶
ClickModifiers reports modifier keys during the current pointer click callback (including double click); outside that callback it returns zero.
func (*Context) Countdown ¶
Countdown is a one-shot timer scoped to a visible, enabled owner. Pausing, hiding, disabling or covering the owner preserves the remaining delay. Changing d restarts it; omitting the declaration cancels it, like After.
func (*Context) Enabled ¶
Enabled reports whether the last declared element with id accepts input, including ancestor disabled state and modal blocking. Missing IDs are false. During Render this describes the previous declaration, like FocusWithin.
func (*Context) Focus ¶
Focus requests focus by ID in this root. It is applied after painting. The first visible Focusable element or input with that ID wins. An empty ID clears focus; missing, hidden or off-screen targets leave the current focus alone. Call from Render or its callbacks; IDs should be unique within a root.
func (*Context) FocusVisible ¶ added in v0.0.4
FocusVisible reports whether the element with id has focus that should show a ring: focus from the keyboard or a program, not from a pointer press. Controls that draw their ring on a part use it with a transparent FocusStyle on the focusable element.
func (*Context) FocusWithin ¶
FocusWithin reports whether the element with id, or anything inside it, had focus in the last painted frame. Tooltips use it for keyboard focus.
func (*Context) Hovered ¶
Hovered reports the last processed pointer position for a visible ID. Disabled elements and elements behind a modal layer are never hovered.
func (*Context) InputAction ¶
func (cx *Context) InputAction(id string, action InputAction)
InputAction queues a command for the next paint of an enabled input. Read-only inputs reject Cut/Paste; password inputs reject Copy/Cut. Paste uses the system clipboard's asynchronous text path and the input's normal filter/transform.
func (*Context) InputSelection ¶
InputSelection returns the input's last editor text and rune selection. Missing or disabled inputs return false. It does not change focus.
func (*Context) LastSize ¶
LastSize returns the last painted border-box size of an identified element, in dp. Read during Render; zero means the element has not been painted or was clipped out. Unlike scroll state, geometry also updates on disabled frames.
func (*Context) LayoutSize ¶
LayoutSize returns an element's final border-box size in dp. Read it only during Decorate, after layout has finished; it also works for clipped rows.
func (*Context) Mount ¶ added in v0.0.5
Mount renders view with this root every frame until Unmount(key). Mounting a key again replaces its view in place. Call it from Render or a callback; the view shows from the next render.
func (*Context) MountedView ¶ added in v0.0.5
MountedView returns the view mounted at key, or nil.
func (*Context) Overlay ¶
Overlay declares a layer in paint order. key must be comparable and unique within this root. Omission closes the layer; OnDismiss asks the owner to omit it. Declare outside Cache builders. Root supports full-window layers; Embed uses its maximum constraints and deferred painting as a best-effort fallback.
func (*Context) PaintGeometry ¶
PaintGeometry reports the current element's origin and clipped viewport in root coordinates. Use it only from Decorate, while the element is painted. It lets input handlers keep a pointer stationary as ancestors scroll.
func (*Context) Perform ¶ added in v0.0.5
Perform runs the handler a key press bound to action would run with focus at targetID: the innermost ActionAt declared on targetID or an element enclosing it, else a global Action handler. It works without any key bound, which is what menus and command palettes need. Call it from a callback; it sees this frame's declarations and reports whether a handler ran. Hidden or disabled targets run nothing.
func (*Context) PixelScale ¶
PixelScale returns the current number of physical pixels per dp. It is available during Render and defaults to one for an unset metric.
func (*Context) ScrollBy ¶
ScrollBy schedules a pixel delta on the nearest enclosing ScrollY container and returns the amount it can scroll. Call during Decorate. The next frame applies it before drawing children, so their input and painting agree.
func (*Context) ScrollIntoView ¶
ScrollIntoView scrolls the ScrollY element with id as little as needed to show [top, bottom], in dp of its content. It applies when the element is next painted, so call it from Render or a callback.
func (*Context) ScrollIntoViewX ¶
ScrollIntoViewX minimally reveals [left, right] in a ScrollX content box.
func (*Context) ScrollState ¶
ScrollState reports, in dp, the scroll offset, viewport height and content height of the ScrollY element with id as last painted; all zero before its first frame. Virtual lists use it to build only the rows that show.
func (*Context) ScrollStateX ¶
ScrollStateX is ScrollState for the horizontal axis; values are in dp.
func (*Context) ScrollTo ¶
ScrollTo sets a ScrollY offset in dp on its next paint. The new content size clamps it then, so callers can preserve an anchor as content changes. It does nothing before the container's first paint or in read-only layout.
func (*Context) ScrollToX ¶
ScrollToX sets a ScrollX offset in dp on its next paint. Content bounds clamp it during painting. Missing containers and read-only layout are ignored.
func (*Context) SelectInput ¶
SelectInput schedules rune-based selection in an input after its next Bind synchronization. It does not change text or focus. Missing or disabled inputs are ignored, and the editor clamps the endpoints to its content.
func (*Context) Shortcut ¶
Shortcut binds a key chord such as "mod+s" to fn while the window has focus and this view is rendered. It panics on an invalid chord.
func (*Context) Themed ¶
Themed renders a view with another palette, for a part of the window in different colors: a dark sidebar in a light window, a preview of a theme. The palette applies while the view renders and while it paints, so kit components and custom drawing inside follow it; the rest of the window keeps the global theme. The wrapper stretches its child; set its background to fill the area.
func (*Context) ViewportSize ¶
ViewportSize returns this root's available width and height in dp. It is available during Render, before child layout, for sizing window-bound overlays.
type DivEl ¶
DivEl is a box: the only element with children.
func Div ¶
func Div() *DivEl
Div creates an empty box. Children stack top to bottom unless Row is set.
func KeyHint ¶
KeyHint builds a hint for the first chord resolved at targetID. Resolution happens after the current element tree is built, before measuring it, so initial-frame hints see the target's current KeyContext ancestry. Missing, hidden or disabled targets and unbound actions render no content. The builder must return display-only content, without declaring overlays or shortcuts.
type DragEvent ¶
type DragEvent struct {
Kind DragKind
Canceled bool // DragEnd caused by cancellation rather than release
X, Y, W, H float32
}
DragEvent reports a pointer drag in dp, relative to the element's top left corner; W and H are the element's size, so X/W is a fraction of its width. X and Y may fall outside 0..W and 0..H while the pointer is outside.
type Edges ¶
type Edges struct{ Top, Right, Bottom, Left float32 }
Edges are per-side lengths in dp.
type Element ¶
type Element interface {
// contains filtered or unexported methods
}
Element is a node of the tree a View renders each frame. Build elements with Div, Text, Input and Widget; they are cheap, and a new tree is built on every frame.
type InputAction ¶
type InputAction uint8
InputAction is an editing command directed to one identified input.
const ( InputCopy InputAction = iota InputCut InputPaste InputSelectAll )
type InputContent ¶
type InputContent = inputcontent.Content
func NewInputContent ¶
func NewInputContent(text string, tokens ...InputTokenSpan) (InputContent, error)
NewInputContent validates UTF-8 byte ranges and returns an immutable draft.
type InputDocument ¶
type InputDocument struct {
// contains filtered or unexported fields
}
InputDocument retains reference metadata, selection and undo history for one input. Do not attach the same document to multiple live editors.
func (*InputDocument) Content ¶
func (d *InputDocument) Content() InputContent
func (*InputDocument) ReplaceWithToken ¶
func (d *InputDocument) ReplaceWithToken(token InputToken) error
func (*InputDocument) Select ¶
func (d *InputDocument) Select(r InputRange) error
func (*InputDocument) SelectedToken ¶
func (d *InputDocument) SelectedToken() (InputToken, bool)
SelectedToken returns a completely selected reference.
func (*InputDocument) Selection ¶
func (d *InputDocument) Selection() InputRange
func (*InputDocument) SetContent ¶
func (d *InputDocument) SetContent(c InputContent)
func (*InputDocument) SetText ¶
func (d *InputDocument) SetText(text string) error
type InputEl ¶
InputEl is a text box. Its editing state (content, caret, selection) is kept per element, so give it an ID when siblings may change.
func TextArea ¶
func TextArea() *InputEl
TextArea creates a multi-line text box; Enter inserts a newline.
func (*InputEl) AutoGrow ¶
AutoGrow sizes a multiline input to its wrapped text, between minRows and maxRows lines. Overflow scrolls inside the editor. Invalid ranges are ignored. Passing (0, 0) restores the default height. Single-line inputs ignore this.
func (*InputEl) Bind ¶
Bind keeps *p and the box in sync: typing writes *p, and a program change to *p shows in the box on the next frame.
func (*InputEl) CaptureKeys ¶
CaptureKeys reserves named, unmodified keys for OnKey before the single-line editor handles them. The handler owns these keys even when it returns false. Ordinary editing shortcuts with modifiers remain with the editor.
func (*InputEl) Document ¶
func (e *InputEl) Document(d *InputDocument) *InputEl
Document binds an atomic-reference draft. It owns text and undo; Bind, Transform, password masks, Filter and MaxLen are not applied in this mode.
func (*InputEl) Filter ¶
Filter accepts only the runes in chars as typed or pasted input; "" accepts all.
func (*InputEl) OnPaste ¶
func (v *InputEl) OnPaste(fn func(core.ClipboardData) bool) *InputEl
OnPaste handles clipboard contents before default text insertion. Return true to consume them. It applies to keyboard and InputPaste commands; nil restores ordinary text paste. Read-only and disabled inputs do not invoke the handler.
func (*InputEl) OnPasteError ¶
OnPasteError reports read failures before fallback or rejection of oversized text. It runs on the UI thread; nil suppresses error reporting.
func (*InputEl) OnTokenActivate ¶
func (e *InputEl) OnTokenActivate(fn func(InputToken)) *InputEl
OnTokenActivate runs for an unmodified token click, including in read-only fields. Dragging a selection and disabled fields do not activate references.
func (*InputEl) PasteReader ¶
func (v *InputEl) PasteReader(reader core.ClipboardReader) *InputEl
PasteReader supplies rich clipboard contents. Without one, OnPaste receives Gio's text contents. Failed reads fall back to the Gio text path.
func (*InputEl) Placeholder ¶
Placeholder is shown while the box is empty; agents also see it as the name when Name is not set.
func (*InputEl) SelectOnFocus ¶
SelectOnFocus selects the complete value when the input gains focus.
func (*InputEl) TokenRenderer ¶
func (e *InputEl) TokenRenderer(fn InputTokenRenderer) *InputEl
type InputRange ¶
type InputRange = inputcontent.Range
type InputToken ¶
type InputToken = inputcontent.Token
InputToken identifies an atomic reference. Text is the submitted/copied value; Label, when nonempty, is its visible name.
type InputTokenRenderer ¶
type InputTokenRenderer func(core.C, InputToken) core.D
InputTokenRenderer lays out passive reference content in physical pixels. It is measured with a disabled context, then painted at the resulting inline position. Honor Constraints and return a baseline (distance from the bottom). Do not mutate application state or install input handlers; use OnTokenActivate. Nil restores the default label pill. Content is clipped to the input viewport.
type InputTokenSpan ¶
type InputTokenSpan = inputcontent.Span
type Layer ¶
type Layer struct {
// contains filtered or unexported fields
}
Layer describes an overlay for one Render. Declare it again while open.
func (*Layer) Arrow ¶
Arrow adds a 6dp pointer to an anchored layer. Offset measures to its tip. It follows the actual placement, including flips, and uses the panel background.
func (*Layer) BeforeDismiss ¶
BeforeDismiss may reject Esc/outside dismissal. Owner removal bypasses it.
func (*Layer) KeepOnEscape ¶
KeepOnEscape consumes Esc without dismissing this layer or layers below it.
func (*Layer) KeepOnOutsidePress ¶
KeepOnOutsidePress stops presses outside the layer from calling OnDismiss; Esc still does. A destructive confirmation uses it so a stray click on the scrim cannot cancel it. A modal layer still blocks the press.
func (*Layer) MatchAnchorWidth ¶
MatchAnchorWidth sizes the layer to its anchor's width, as a dropdown matches its trigger.
func (*Layer) OnEscape ¶
OnEscape handles an Escape press before normal dismissal. Returning true consumes the press and keeps the layer open; false permits normal dismissal. KeepOnEscape takes precedence. Outside presses do not call this callback.
func (*Layer) Owner ¶
Owner ties a layer's lifetime to an enabled element in the current tree. Use this for modals declared by a component nested in a disabled or hidden container. The owner controls eligibility, not position or modality.
func (*Layer) Placement ¶
Placement places an Anchored layer at side of its anchor. On a Modal it places the content against that edge of the root instead of centering it, e.g. a sheet: Modal(panel).Placement(Right, Start).
type Length ¶
type Length struct {
// contains filtered or unexported fields
}
Length is a size along one axis: automatic, a fixed number of dp or sp, or a fraction of the parent's content box.
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Node holds what an element was built with and, after layout, where it is.
type RootWidget ¶
type RootWidget struct {
// contains filtered or unexported fields
}
RootWidget renders a View as a core.Widget.
func Embed ¶
func Embed(v View) *RootWidget
Embed renders v as an ordinary widget sized to its content, e.g. inside hand-written Gio layout or a window that pads and scrolls its content.
func Root ¶
func Root(v View) *RootWidget
Root makes v the whole content of a window: it fills the window, with the theme background, and the window adds no padding or scrolling of its own.
window.Open(window.Options{Title: "Orders", Content: el.Root(&Orders{})})
func (*RootWidget) FillsWindow ¶
func (r *RootWidget) FillsWindow() bool
FillsWindow tells ui/window to give the root the whole window.
type ScrollEvent ¶
type ScrollEvent struct{ X, Y float32 }
ScrollEvent reports scroll deltas in dp. Gio does not identify discrete wheels versus trackpads or expose a gesture-end phase on this event.
type ScrollRange ¶
type ScrollRange struct{ Min, Max float32 }
ScrollRange is the signed range of scroll deltas accepted in dp. A zero range passes that axis to enclosing scroll handlers.
type ScrollbarMode ¶
type ScrollbarMode uint8
ScrollbarMode controls when an overflowing scroll container shows its bars. It applies to both axes and does not change the content's layout or offset.
const ( ScrollbarAlways ScrollbarMode = iota // visible whenever content overflows ScrollbarHover // visible while the pointer is inside the viewport or dragging a bar ScrollbarScrolling // visible during offset changes and briefly afterward // ScrollbarSystem follows the platform's setting: macOS "Show scroll // bars", Windows "Automatically hide scroll bars". Elsewhere it is Always. ScrollbarSystem )
func SystemScrollbars ¶ added in v0.0.5
func SystemScrollbars() ScrollbarMode
SystemScrollbars is the platform's preference as last read: Scrolling where bars hide at rest, otherwise Always. ui/window reads the setting into theme.SystemScrollbarsAutoHide.
type Style ¶
type Style struct {
// contains filtered or unexported fields
}
Style is everything an element can look like. Build it with the methods shared by all elements (see Styled); Hover and Active take a func that changes a Style, whose methods mirror the element ones.
func (*Style) Bg ¶
Visual changes, usable in Hover and Active. They return the Style so calls chain.
func (*Style) BgGradient ¶
BgGradient fills the background with a linear gradient instead of a solid color; a later Bg replaces it. A zero gradient changes nothing, so a theme's optional gradient can be passed as is.
func (*Style) BorderDashed ¶
BorderDashed switches the border between dashed and solid.
type Styled ¶
type Styled[T any] struct { // contains filtered or unexported fields }
Styled carries the builder methods every element shares. T is the element type, so each method returns it and calls chain: Div().P(8).Bg(c).Child(...).
func (*Styled[T]) Absolute ¶
func (s *Styled[T]) Absolute() *T
Absolute takes the element out of flow and places it by Top/Right/Bottom/Left within its parent's padding box.
func (*Styled[T]) AspectRatio ¶
AspectRatio derives an automatic height from a resolved width (width/height). Explicit heights take precedence. Zero clears the ratio; invalid values are ignored.
func (*Styled[T]) BgGradient ¶
BgGradient fills the background with a linear gradient; see Style.BgGradient.
func (*Styled[T]) BorderDashed ¶
BorderDashed draws 4dp dashes with 3dp gaps; false restores a solid border.
func (*Styled[T]) Col ¶
func (s *Styled[T]) Col() *T
Col lays children out top to bottom (the default).
func (*Styled[T]) ColSpan ¶
ColSpan sets how many tracks a child occupies in a Grid. Values are clamped to 1..the parent's column count; a cell that does not fit starts a new row.
func (*Styled[T]) ContentBottom ¶
ContentBottom selects an in-flow descendant whose border-box bottom aligns with siblings in a row using Items(ContentBottom). Nil, hidden, or missing descendants fall back to this element's bottom. This is geometric alignment, not a font baseline. Pass an element from the current render tree.
func (*Styled[T]) Cursor ¶
Cursor sets the pointer shape over the element, e.g. pointer.CursorColResize on a splitter.
func (*Styled[T]) CursorPointer ¶
func (s *Styled[T]) CursorPointer() *T
CursorPointer shows a hand over the element.
func (*Styled[T]) Decorate ¶
Decorate wraps painting with custom operations, e.g. a shared input area around a subtree. gtx uses the element's coordinate system and exact size. Call draw once to paint the element and its children. This does not run during measurement, and must not change the element tree or its layout.
func (*Styled[T]) DisabledStyle ¶
func (*Styled[T]) DragAccept ¶
DragAccept decides once, after the initial movement exceeds 3dp, whether this element captures a drag. dx/dy are pointer displacement in dp (not scroll deltas). Rejection emits a canceled DragEnd and leaves enclosing handlers free to capture. Nil restores ordinary OnDrag behavior. Presses on interactive descendants are left to those descendants. The predicate must not mutate UI state. Use with OnDrag.
func (*Styled[T]) Flex ¶
Flex grows like Grow, taking free space in proportion to w: a child with Flex(2) gets twice the share of one with Flex(1) or Grow.
func (*Styled[T]) FocusOnPress ¶
FocusOnPress makes a press anywhere in this box that no child takes focus the element with id, such as the input inside a field's frame: clicking the frame's padding or beside the text then focuses the text. The box shows the text cursor; it gets no role and no Tab stop. It needs an ID of its own. An Input already does this for its own padding.
func (*Styled[T]) FocusStyle ¶
FocusStyle sets a visual keyboard/programmatic focus style, like Hover. Pointer focus on non-input elements does not show it. Inputs always show it. It does not change layout. The default focus style is a 2dp Primary border inside the element bounds.
func (*Styled[T]) FocusTrap ¶
FocusTrap cycles Tab and Shift+Tab within this subtree while it contains focus. Nested traps use the innermost focused scope. Pointer and explicit Context.Focus requests can move to another scope; this does not open a modal, focus on mount, or restore focus on removal. Use Layer.TrapFocus for overlays. Targets belong to this el root; independently embedded widgets own their focus.
func (*Styled[T]) Focusable ¶
Focusable adds the element to the native Tab order and focuses it on press. Input and TextArea already manage their native editor focus.
func (*Styled[T]) Grid ¶
Grid lays children in equal-width columns (at least one), in row order. Columns honor fixed/minimum child widths; rows size to their tallest child. Gap applies between columns and rows. Children can span tracks with ColSpan.
func (*Styled[T]) Grow ¶
func (s *Styled[T]) Grow() *T
Grow lets the element take free space along its parent's main axis.
func (*Styled[T]) ID ¶
ID names the element among its siblings. State that outlives a frame, such as hover, scroll position and text box content, is kept per ID; give items of lists that change an ID so their state follows them.
func (*Styled[T]) IsHidden ¶
IsHidden reports the element's declared visibility, before ancestor inheritance. Composite views can use it to keep adjoining controls hidden with their body.
func (*Styled[T]) Items ¶
Items aligns children across the main axis: Start, Center, End or Stretch (default for columns: children fill the width).
func (*Styled[T]) Justify ¶
Justify places children along the main axis: Start, Center, End, SpaceBetween, SpaceAround.
func (*Styled[T]) KeepBottomOn ¶
KeepBottomOn keeps the distance from the bottom of a ScrollY element when version changes, so content inserted above (older chat history) does not move what is on screen. Bump version in the same callback that inserts.
func (*Styled[T]) KeyContext ¶
KeyContext names a keymap scope inherited by descendants. Nested scopes override outer ones per action; an empty name adds no scope. Pair it with core.BindIn and Context.ActionAt for focused command handling.
func (*Styled[T]) LineHeight ¶
LineHeight sets the distance between lines as a multiple of the text size, e.g. 1.5 for long paragraphs; descendants inherit it.
func (*Styled[T]) Medium ¶
func (s *Styled[T]) Medium() *T
Medium sets a weight between regular and Bold, for emphasis that should not shout: selected tabs, table headers.
func (*Styled[T]) Mono ¶
func (s *Styled[T]) Mono() *T
Mono sets theme.MonoFace: code and numbers that must line up.
func (*Styled[T]) NoShrink ¶
func (s *Styled[T]) NoShrink() *T
NoShrink keeps the element from shrinking below its content size.
func (*Styled[T]) OnClick ¶
func (s *Styled[T]) OnClick(fn func()) *T
OnClick runs fn on a primary click. It runs before the next render, so the frame that follows already shows its effects.
func (*Styled[T]) OnContextMenu ¶
func (s *Styled[T]) OnContextMenu(fn func()) *T
OnContextMenu runs fn on a secondary pointer press. It does not consume primary clicks; add an OnKey handler for a keyboard context-menu action.
func (*Styled[T]) OnDoubleClick ¶
func (s *Styled[T]) OnDoubleClick(fn func()) *T
OnDoubleClick runs fn on a double click (OnClick also sees both clicks).
func (*Styled[T]) OnDrag ¶
OnDrag reports presses, moves and releases on the element, e.g. for a slider thumb or a splitter. A press also starts an OnClick if both are set.
func (*Styled[T]) OnKey ¶
OnKey handles keys from a focused Focusable element, bubbling through its ancestors. Return true to stop bubbling and suppress default activation. Tab remains platform focus navigation; use Context.Shortcut for global keys.
func (*Styled[T]) OnMousePress ¶
OnMousePress observes a primary, secondary or tertiary press without consuming descendant events or adding a Tab stop. Chords are ignored. It shares a handler with OnContextMenu; the last call wins. Zero clears it; invalid buttons are ignored.
func (*Styled[T]) OnScroll ¶
func (s *Styled[T]) OnScroll(x, y ScrollRange, fn func(ScrollEvent)) *T
OnScroll receives scroll input within the supplied axis ranges. Excess is routed by Gio to enclosing handlers. Descendant handlers have priority. Nil removes the handler; disabled/hidden ancestors suppress delivery.
func (*Styled[T]) PinLeft ¶
PinLeft keeps an element at an offset from its nearest ScrollX viewport's left edge. It retains layout space and paints above unpinned siblings.
func (*Styled[T]) Reveal ¶
Reveal exposes a fraction of this element's natural height, clipping both painting and input. Children retain their full layout, so text does not reflow vertically during an expand/collapse animation. NaN becomes zero.
func (*Styled[T]) Rounded ¶
Rounded rounds the corners by dp; backgrounds, borders and hit areas follow.
func (*Styled[T]) RoundedCorners ¶
RoundedCorners rounds each corner separately, in dp: top left, top right, bottom right, bottom left. Joined controls, such as a button group, use it to round only their outer corners. A later Rounded makes them uniform again.
func (*Styled[T]) Row ¶
func (s *Styled[T]) Row() *T
Row lays children out left to right. The default is top to bottom.
func (*Styled[T]) ScrollOffset ¶
ScrollOffset controls absolute x/y offsets in dp for ScrollX/ScrollY. Offsets are clamped at paint time, including disabled frames. Omit it to allow user scrolling; when supplied, native scroll gestures and scrollbars are omitted.
func (*Styled[T]) ScrollToEndOn ¶
ScrollToEndOn scrolls a ScrollY container to the end whenever version changes, and resumes StickToBottom: pass the number of messages so that sending one jumps to it even after the user scrolled up to read.
func (*Styled[T]) ScrollX ¶
func (s *Styled[T]) ScrollX() *T
ScrollX clips and scrolls children horizontally. Set W or constrain the width through the parent. ScrollX and ScrollY can be combined.
func (*Styled[T]) ScrollY ¶
func (s *Styled[T]) ScrollY() *T
ScrollY clips the children and scrolls them vertically. The element needs a definite height: set H, or let it Grow in a column.
func (*Styled[T]) Scrollbars ¶
func (s *Styled[T]) Scrollbars(mode ScrollbarMode) *T
Scrollbars selects the display mode for this ScrollX/ScrollY element. Invalid modes are ignored. Hidden bars have no pointer hit area; scrolling and keyboard navigation remain available. ScrollOffset still hides all bars. Elements without a mode use SetScrollbarDefault's.
func (*Styled[T]) Shadow ¶
Shadow lifts the element with a soft shadow below it, in theme.Shadow's color: theme.ElevationMd for popovers and menus, ElevationLg for dialogs. The shadow is drawn outside the element and does not change its size.
func (*Styled[T]) StickToBottom ¶
func (s *Styled[T]) StickToBottom() *T
StickToBottom keeps a ScrollY container scrolled to the end while content grows, as long as the user has not scrolled away from the end: a chat that follows a streaming answer but lets the user read back.
func (*Styled[T]) TabIndex ¶
TabIndex orders stops by ascending index, with tree order breaking ties. Negative indexes skip Tab traversal. The default index is zero.
func (*Styled[T]) TabStop ¶
TabStop controls sequential Tab traversal without disabling pointer/programmatic focus. Explicit Tab configuration is scoped to this el root and its active trap.
func (*Styled[T]) TextAlign ¶
TextAlign sets alignment within wrapped text. Descendants inherit it. Start, Center and End are accepted; other values leave the style unchanged.
func (*Styled[T]) Translate ¶
Translate moves painting, hit areas and anchors by dp without changing layout.
func (*Styled[T]) WFull ¶
func (s *Styled[T]) WFull() *T
WFull and HFull fill the parent's content box.
type TextEl ¶
TextEl is a run of text. It wraps to the available width.
func Text ¶
Text creates a text element; style it like any element (TextColor, TextSize, Bold) or let it inherit from its parent.
func (*TextEl) Ranges ¶
Ranges copies color ranges without changing text measurement or shaping. Shimmer, when present, takes precedence over ranges.
type TextRange ¶
TextRange colors a half-open Unicode rune interval. Later ranges take priority. Any overlapping shaping cluster is colored as a whole; bitmap glyphs keep their colors.
type View ¶
View is anything that renders an element tree: usually a struct holding the state of a screen, whose event handlers change its fields directly.
type Counter struct{ n int }
func (c *Counter) Render(cx *el.Context) el.Element {
return el.Div().Child(el.Text(strconv.Itoa(c.n)), el.Div().OnClick(func() { c.n++ }).Child(el.Text("+1")))
}
Render runs every frame, after event handlers, under the UI lock (see ui/core). Code on other goroutines changes views through core.Update.
Source Files
¶
- border.go
- clipboard.go
- content_bottom.go
- drag.go
- drag_accept.go
- element.go
- flow.go
- focus.go
- input.go
- input_actions.go
- input_document.go
- input_document_events.go
- input_document_paint.go
- input_objects.go
- input_paste.go
- input_transform.go
- key_context.go
- layout.go
- mount.go
- overlay.go
- overlay_arrow.go
- paint.go
- root.go
- scroll_event.go
- scrollbar.go
- scrollbar_mode.go
- state.go
- style.go
- tab.go
- text_ranges.go
- text_shimmer.go
- time.go
- viewport.go