Documentation
¶
Index ¶
- Constants
- func PlayLongPressFeedback()
- func SetLongPressFeedback(fn func())
- type BoxElement
- func (b *BoxElement) Animate(key any) *BoxElement
- func (b *BoxElement) Animation(a *KeyframeAnimation) *BoxElement
- func (b *BoxElement) CacheSafe() bool
- func (b *BoxElement) Describe() string
- func (b *BoxElement) FlexPercent(axis layout.Axis) int
- func (b *BoxElement) FlexWeight(axis layout.Axis) int
- func (b *BoxElement) GridPlacement() (col, row properties.GridSpan)
- func (b *BoxElement) Hovered() bool
- func (b *BoxElement) Layout(gtx layout.Context) layout.Dimensions
- func (b *BoxElement) OnClick(fn func(e ClickEvent)) *BoxElement
- func (b *BoxElement) OnHover(st styles.Styles) *BoxElement
- func (b *BoxElement) Pressable() *Pressable
- func (b *BoxElement) ZIndex() int
- type ClickEvent
- type ClickSource
- type DragEvent
- type Keyframe
- type KeyframeAnimation
- func (a *KeyframeAnimation) Alternate(on bool) *KeyframeAnimation
- func (a *KeyframeAnimation) Delay(d time.Duration) *KeyframeAnimation
- func (a *KeyframeAnimation) Done() bool
- func (a *KeyframeAnimation) Easing(e properties.Easing) *KeyframeAnimation
- func (a *KeyframeAnimation) KeepEnd(on bool) *KeyframeAnimation
- func (a *KeyframeAnimation) OnDone(fn func()) *KeyframeAnimation
- func (a *KeyframeAnimation) Pause()
- func (a *KeyframeAnimation) Repeat(n int) *KeyframeAnimation
- func (a *KeyframeAnimation) Restart()
- func (a *KeyframeAnimation) Resume()
- type MouseButton
- type PressState
- type Pressable
- func (p *Pressable) Click()
- func (p *Pressable) Content(content func(s PressState) base.Element) *Pressable
- func (p *Pressable) Describe() string
- func (p *Pressable) Disabled(v bool) *Pressable
- func (p *Pressable) DragThreshold(dp float32) *Pressable
- func (p *Pressable) Dragging() bool
- func (p *Pressable) FlexPercent(axis layout.Axis) int
- func (p *Pressable) FlexWeight(axis layout.Axis) int
- func (p *Pressable) Focusable(v bool) *Pressable
- func (p *Pressable) Focused() bool
- func (p *Pressable) Hovered() bool
- func (p *Pressable) Label(label string) *Pressable
- func (p *Pressable) Layout(gtx layout.Context) layout.Dimensions
- func (p *Pressable) OnClick(fn func(e ClickEvent)) *Pressable
- func (p *Pressable) OnDoubleClick(fn func(e ClickEvent)) *Pressable
- func (p *Pressable) OnDragEnd(fn func(e DragEvent)) *Pressable
- func (p *Pressable) OnDragMove(fn func(e DragEvent)) *Pressable
- func (p *Pressable) OnDragStart(fn func(e DragEvent)) *Pressable
- func (p *Pressable) OnLongPress(fn func(e ClickEvent)) *Pressable
- func (p *Pressable) OnPress(fn func(e ClickEvent)) *Pressable
- func (p *Pressable) OnPrimaryClick(fn func(e ClickEvent)) *Pressable
- func (p *Pressable) OnSecondaryClick(fn func(e ClickEvent)) *Pressable
- func (p *Pressable) Pressed() bool
- func (p *Pressable) Semantics(fn func(n *base.SemanticNode)) *Pressable
- func (p *Pressable) State() PressState
- func (p *Pressable) Styles(st styles.Styles) *Pressable
- func (p *Pressable) ZIndex() int
Constants ¶
const LongPressDuration = 500 * time.Millisecond
LongPressDuration is how long a touch must be held still for OnLongPress.
Variables ¶
This section is empty.
Functions ¶
func PlayLongPressFeedback ¶
func PlayLongPressFeedback()
PlayLongPressFeedback plays the long-press feedback: a haptic tap, as the app sets it. Elements that start something with a long press (a touch drag) call it.
func SetLongPressFeedback ¶
func SetLongPressFeedback(fn func())
SetLongPressFeedback sets what plays when OnLongPress fires - the app sets it to a haptic tap; component authors don't need to.
Types ¶
type BoxElement ¶
type BoxElement struct {
// Contextual gives it a context menu (Context).
base.Contextual
// contains filtered or unexported fields
}
BoxElement is a container element: a flex container and a containing block for absolutely positioned children.
func Box ¶
func Box(st styles.Styles, children ...base.Element) *BoxElement
Box is a container element: children are laid along FlexDirection with Align, Justify, Gap and Wrap. Chain OnHover to add hover styles.
func Grid ¶
func Grid(st styles.Styles, children ...base.Element) *BoxElement
Grid lays children out on a grid: Box with Display DisplayGrid. st's GridColumns sizes the columns ("200 1fr", "repeat(3, 1fr)", "repeat(auto-fill, minmax(220, 1fr))"), Gap and RowGap space them, and each child's GridColumn and GridRow place it (Span, Cell), or it takes the next free cells in reading order.
func Row ¶
func Row(st styles.Styles, children ...base.Element) *BoxElement
Row lays children out horizontally. It is Box with flex direction forced to row.
func Stack ¶
func Stack(st styles.Styles, children ...base.Element) *BoxElement
Stack lays children out vertically. It is Box with flex direction forced to column. Note that this is not Gio's layout.Stack.
func (*BoxElement) Animate ¶
func (b *BoxElement) Animate(key any) *BoxElement
Animate makes the box animate every change of its styles, under key: when the styles it's built with differ from the last frame's - a state changed, a row was selected, a panel expanded - it moves to the new ones over the styles' Transition (Duration and Easing), from wherever it was. A box is rebuilt every frame, so key (any comparable value, unique among animated boxes: a row's ID) keeps its animation between frames.
giode.Box(giode.Styles{
Height: ifThen(open, 240, 48),
Background: ifThen(selected, "theme.primary/0.1", "theme.surface"),
Transition: giode.StyleTransition{Duration: 200 * time.Millisecond},
}, children...).Animate("panel-" + id)
Colors, Opacity, Transform, BorderRadius, BorderWidth, the shadow, Padding, Gap, and fixed Width and Height interpolate; other properties change at once. With reduced motion every change is immediate. It returns b for chaining.
func (*BoxElement) Animation ¶
func (b *BoxElement) Animation(a *KeyframeAnimation) *BoxElement
Animation plays a keyframe animation on the box (see Keyframes): its frames' styles are merged over the box's. It returns b for chaining.
func (*BoxElement) CacheSafe ¶
func (b *BoxElement) CacheSafe() bool
CacheSafe reports whether the box's output depends only on things a cache watches: its own styles, which don't change after it's built, and children that are CacheSafe themselves.
func (*BoxElement) Describe ¶
func (b *BoxElement) Describe() string
Describe names the box for diagnostics: its kind and the first text inside it, which is usually enough to find it in the code.
func (*BoxElement) FlexPercent ¶
func (b *BoxElement) FlexPercent(axis layout.Axis) int
func (*BoxElement) FlexWeight ¶
func (b *BoxElement) FlexWeight(axis layout.Axis) int
func (*BoxElement) GridPlacement ¶
func (b *BoxElement) GridPlacement() (col, row properties.GridSpan)
func (*BoxElement) Hovered ¶
func (b *BoxElement) Hovered() bool
Hovered reports whether the pointer was over the element on the last frame.
func (*BoxElement) Layout ¶
func (b *BoxElement) Layout(gtx layout.Context) layout.Dimensions
Layout resolves the box size and paints the background stack (shadow, fill, gradient, image, border) with the content replayed on top.
A box with OnHover or OnClick is kept and laid out every frame as the same element; when all its content is CacheSafe it replays the output recorded last time until its hover or press state, its content's state, its constraints or its direction change.
func (*BoxElement) OnClick ¶
func (b *BoxElement) OnClick(fn func(e ClickEvent)) *BoxElement
OnClick makes the box clickable, as if wrapped in a Pressable: the pointer cursor shows on hover, Enter/Space activate it when focused, and clickable children keep their own clicks. Its text stays selectable, like a clickable element on the web: in a SelectionArea, or Selectable text, a mouse drag selects instead of clicking. Like OnHover, it needs a box created once and reused every frame (or looked up with Keyed), since press state lives in the element.
func (*BoxElement) OnHover ¶
func (b *BoxElement) OnHover(st styles.Styles) *BoxElement
OnHover sets styles applied while the pointer is over the element, merged on top of its base styles for both layout and painting:
card := giode.Box(base, children...).OnHover(giode.Styles{
Background: "#1e40af",
Cursor: giode.CursorPointer,
})
Set Transition on the base styles to animate the change.
Hover state lives in the element, so create it once and reuse it every frame; rebuilding it in the view function resets the hover on each frame.
func (*BoxElement) Pressable ¶
func (b *BoxElement) Pressable() *Pressable
Pressable returns the Pressable behind OnClick, to set a label, double-click handlers or disable it; nil before OnClick.
func (*BoxElement) ZIndex ¶
func (b *BoxElement) ZIndex() int
type ClickEvent ¶
type ClickEvent struct {
// Clicks is 1 for a single click, 2 for a double click, and so on.
Clicks int
// Button is the mouse button; MousePrimary for keyboard and
// programmatic clicks.
Button MouseButton
// Modifiers holds the keys held down (key.ModCtrl, key.ModShift,
// ...); see Ctrl and Shift.
Modifiers key.Modifiers
// Source says how the click was produced.
Source ClickSource
// Position is where the pointer was, relative to the Pressable,
// in pixels; zero for keyboard and programmatic clicks.
Position image.Point
// PositionDp is Position in dp, the unit of Styles.
PositionDp f32.Point
// WindowPosition is where the pointer was in the window, in pixels,
// so a row can open a menu where it was right-clicked (see
// Menu.OpenAtClick). For keyboard and programmatic clicks it's the
// Pressable's bottom-left corner, as of the last frame.
WindowPosition image.Point
}
ClickEvent describes a click.
func (ClickEvent) Ctrl ¶
func (e ClickEvent) Ctrl() bool
Ctrl reports whether Ctrl (or Command on macOS) was held.
type ClickSource ¶
type ClickSource int
ClickSource says how a click was produced.
const ( // ClickPointer is a mouse, pen or touch click. ClickPointer ClickSource = iota // ClickKeyboard is Enter or Space on a focused Pressable. ClickKeyboard // ClickProgrammatic is a call to Pressable.Click (or automation). ClickProgrammatic )
type DragEvent ¶
type DragEvent struct {
// Position is where the pointer is, relative to the Pressable, in
// pixels.
Position image.Point
// PositionDp is Position in dp, the unit of Styles.
PositionDp f32.Point
// WindowPosition is where the pointer is in the window, in pixels.
WindowPosition image.Point
// DeltaDp is how far the pointer has moved since the press, in dp,
// measured in the window: it stays right while the Pressable itself
// moves with the drag (a tab being reordered, a dragged card).
DeltaDp f32.Point
// Button is the mouse button held; MousePrimary for touch.
Button MouseButton
// Modifiers holds the keys held down.
Modifiers key.Modifiers
// Touch is set for a finger, unset for a mouse or pen.
Touch bool
// Cancelled is set on OnDragEnd when the drag didn't end with a
// release: the system took the pointer (another gesture won, the
// window lost it) or the Pressable was disabled. Treat it as no
// drop.
Cancelled bool
}
DragEvent describes a drag on a Pressable: a press that moved further than a click may, from the start of the drag to its end.
type Keyframe ¶
Keyframe is a step of a keyframe animation: Styles at At, a fraction of the animation from 0 to 1. Its styles are merged over the box's, so a keyframe sets only what it animates.
type KeyframeAnimation ¶
type KeyframeAnimation struct {
// contains filtered or unexported fields
}
KeyframeAnimation plays styles through keyframes on a Box (BoxElement.Animation), like CSS @keyframes: a pulse, a shake, an entrance. It keeps its own time, so create it once. With reduced motion a repeating animation doesn't play, and a finite one jumps to its end.
func Keyframes ¶
func Keyframes(d time.Duration, frames ...Keyframe) *KeyframeAnimation
Keyframes returns an animation through frames over d, played once. Frames are sorted by At; without one at 0 or 1 the box's own styles stand in at that end.
func (*KeyframeAnimation) Alternate ¶
func (a *KeyframeAnimation) Alternate(on bool) *KeyframeAnimation
Alternate plays every other repetition backwards. It returns a for chaining.
func (*KeyframeAnimation) Delay ¶
func (a *KeyframeAnimation) Delay(d time.Duration) *KeyframeAnimation
Delay waits d before playing. It returns a for chaining.
func (*KeyframeAnimation) Done ¶
func (a *KeyframeAnimation) Done() bool
Done reports whether it has finished playing.
func (*KeyframeAnimation) Easing ¶
func (a *KeyframeAnimation) Easing(e properties.Easing) *KeyframeAnimation
Easing eases each step between two keyframes (EaseInOut by default). It returns a for chaining.
func (*KeyframeAnimation) KeepEnd ¶
func (a *KeyframeAnimation) KeepEnd(on bool) *KeyframeAnimation
KeepEnd keeps the last keyframe's styles once it has played (the default); off, the box goes back to its own styles. It returns a for chaining.
func (*KeyframeAnimation) OnDone ¶
func (a *KeyframeAnimation) OnDone(fn func()) *KeyframeAnimation
OnDone sets a function run when it finishes playing. It returns a for chaining.
func (*KeyframeAnimation) Pause ¶
func (a *KeyframeAnimation) Pause()
Pause holds it where it is; Resume goes on from there.
func (*KeyframeAnimation) Repeat ¶
func (a *KeyframeAnimation) Repeat(n int) *KeyframeAnimation
Repeat plays it n times; 0 repeats it forever. It returns a for chaining.
func (*KeyframeAnimation) Restart ¶
func (a *KeyframeAnimation) Restart()
Restart plays it again from the start, on the next frame.
type MouseButton ¶
type MouseButton int
MouseButton identifies which button produced a click.
const ( MousePrimary MouseButton = iota MouseSecondary MouseMiddle )
type PressState ¶
type PressState struct {
Hovered bool
Pressed bool
Focused bool
Disabled bool
// Dragging is set while a press that moved is being dragged (see
// Pressable.OnDragStart).
Dragging bool
}
PressState is the interaction state a Pressable's content is built with, so it can restyle itself.
type Pressable ¶
type Pressable struct {
// Contextual gives it a context menu (Context).
base.Contextual
// contains filtered or unexported fields
}
Pressable makes any content clickable. Its content is rebuilt every frame with the current PressState, so it can restyle itself:
card := giode.Pressable(func(s giode.PressState) giode.Element {
bg := "theme.surface"
if s.Hovered {
bg = "theme.border"
}
return giode.Box(giode.Styles{Background: bg, Padding: giode.UniformInset(12)},
giode.Text("Open project"))
}).OnClick(func(e giode.ClickEvent) { open() })
The hit area sits beneath the content, like Gio's widget.Clickable, so clickable children (an expand arrow, a delete button) keep their own clicks. It shows a pointer cursor on hover, can be focused with Tab and activated with Enter or Space, stays clickable inside a frameless window's drag area, and appears to automation (the MCP server) as a button.
Like every stateful component, create it once and reuse it every frame - or, for items of a list that changes, look it up by key with Keyed.
func NewPressable ¶
NewPressable returns a Pressable around content. The styles argument is optional and styles a box wrapped around the content: padding, background, FlexGrow, Width, ... and Cursor (default pointer).
func (*Pressable) Click ¶
func (p *Pressable) Click()
Click runs the click handlers as a programmatic click. Call it on the UI goroutine (from a handler, or through App.Post).
func (*Pressable) Content ¶
func (p *Pressable) Content(content func(s PressState) base.Element) *Pressable
Content replaces the content builder. It returns p for chaining.
func (*Pressable) Disabled ¶
Disabled turns input off: no events, no focus, default cursor, and PressState.Disabled set for the content. It returns p for chaining.
func (*Pressable) DragThreshold ¶
DragThreshold sets how far, in dp, a press moves before it's a drag (OnDragStart); 6dp by default. 0 starts the drag on the first move, as a text selection does. It returns p for chaining.
func (*Pressable) Focusable ¶
Focusable controls whether Tab can focus it (default true). It returns p for chaining.
func (*Pressable) Label ¶
Label sets the accessible name reported to assistive technology and automation. It returns p for chaining.
func (*Pressable) Layout ¶
func (p *Pressable) Layout(gtx layout.Context) layout.Dimensions
Layout lays out the content over the hit area.
func (*Pressable) OnClick ¶
func (p *Pressable) OnClick(fn func(e ClickEvent)) *Pressable
OnClick sets the handler for clicks of any button and count (see OnPrimaryClick for the primary button alone). It returns p for chaining.
func (*Pressable) OnDoubleClick ¶
func (p *Pressable) OnDoubleClick(fn func(e ClickEvent)) *Pressable
OnDoubleClick sets a handler for primary-button double clicks, run in addition to OnClick. It returns p for chaining.
func (*Pressable) OnDragEnd ¶
OnDragEnd sets the handler for the end of a drag: the release, or a cancellation (DragEvent.Cancelled). It returns p for chaining.
func (*Pressable) OnDragMove ¶
OnDragMove sets the handler for each move of the pointer during a drag, the first one right after OnDragStart. The drag goes on when the pointer leaves the Pressable, and once it has started, an enclosing Scroll or frameless window doesn't take it. (A finger moving along a Scroll's axis scrolls it before it moves far enough to start a drag.) It returns p for chaining.
func (*Pressable) OnDragStart ¶
OnDragStart sets the handler for the start of a drag: a press that moves more than a few dp with any button, mouse or finger. Once a press becomes a drag, its release is not a click, so a draggable tab or card still clicks when it's only tapped. The event's Position is where the press was. Setting any drag handler keeps the content's text from being selected by a drag. It returns p for chaining.
func (*Pressable) OnLongPress ¶
func (p *Pressable) OnLongPress(fn func(e ClickEvent)) *Pressable
OnLongPress sets the handler for a touch held on the element for LongPressDuration without sliding off it - the touch screen's way to open context actions. The release that follows isn't a click. With a mouse, use OnSecondaryClick. It returns p for chaining.
func (*Pressable) OnPress ¶
func (p *Pressable) OnPress(fn func(e ClickEvent)) *Pressable
OnPress sets a handler for a pointer pressing down on it, any button, before it's released: where it pressed, which button, and how many presses in a row (Clicks 2 for the second press of a double click). An editor places its caret on the press, as text editors do, rather than on the release; the release still fires OnClick (unless the press became a drag). It returns p for chaining.
func (*Pressable) OnPrimaryClick ¶
func (p *Pressable) OnPrimaryClick(fn func(e ClickEvent)) *Pressable
OnPrimaryClick sets a handler for clicks of the primary button (and keyboard and programmatic clicks), run in addition to OnClick: the handler for a plain click that a right or middle click shouldn't trigger. It returns p for chaining.
func (*Pressable) OnSecondaryClick ¶
func (p *Pressable) OnSecondaryClick(fn func(e ClickEvent)) *Pressable
OnSecondaryClick sets a handler for right clicks, run in addition to OnClick. It returns p for chaining.
func (*Pressable) Semantics ¶
func (p *Pressable) Semantics(fn func(n *base.SemanticNode)) *Pressable
Semantics sets a function adjusting the node the Pressable reports to automation and assistive technology: its role (a tree item, a list item, a tab), states (selected, expanded) and description. It returns p for chaining.
func (*Pressable) State ¶
func (p *Pressable) State() PressState
State returns the current PressState.
Source Files
¶
- absolute.go
- animate.go
- axis.go
- body.go
- boxsugar.go
- constraints.go
- describe.go
- element.go
- feedback.go
- flex.go
- flexwrap.go
- grid.go
- hover.go
- hover_anim.go
- layout.go
- main.go
- mainsize.go
- mirror.go
- press.go
- pressable.go
- presslayout.go
- pressstate.go
- sizing.go
- spacing.go
- split.go
- stretch.go
- tracker.go
- unstretch.go
- wrap.go
- wrapstretch.go
- z_paint.go