Documentation
¶
Index ¶
- Constants
- Variables
- func Append[T any](s *StateValue[[]T], items ...T)
- func AsyncImage(url string) *viewNode
- func Button(label string, handler func()) *viewNode
- func Divider() *viewNode
- func ErrorBoundary(child any, fallback func(err error) View) *viewNode
- func FadeColor(c color.Color, alpha float64) color.Color
- func ForEach[T any](items []T, renderFn func(T) any) *viewNode
- func ForEachIndexed[T any](items []T, renderFn func(int, T) any) *viewNode
- func Form(items ...FormEntry) *viewNode
- func Grid(columns int, children ...any) *viewNode
- func Group(children ...any) *viewNode
- func HStack(children ...any) *viewNode
- func Hex(hex string) color.Color
- func Image(filePath string) *viewNode
- func List[T any, K comparable](state *StateValue[[]T], keyFn func(T) K, renderFn func(int, T) View) *viewNode
- func ListOf[T any](state *StateValue[[]T], renderFn func(T) any) *viewNode
- func MixColor(a, b color.Color, t float64) color.Color
- func NavStack(root any) *viewNode
- func Picker(options []string, selected int) *viewNode
- func PickerOf[T comparable](state *StateValue[T], options []T, label func(T) string) *viewNode
- func Prepend[T any](s *StateValue[[]T], item T)
- func ProgressBar(value float64) *viewNode
- func ProgressView() *viewNode
- func Provide[T any](s *Scope, key *StoreKey[T], initial T)
- func RemoveWhere[T any](s *StateValue[[]T], pred func(T) bool)
- func Run(title string, root View)
- func RunWithConfig(config AppConfig, root View)
- func Scaffold(center any) *viewNode
- func ScrollView(children ...any) *viewNode
- func Show(cond bool, v any) *viewNode
- func Slider(arg any) *viewNode
- func Spacer() *viewNode
- func TabView(tabs ...TabEntry) *viewNode
- func Text(content any) *viewNode
- func TextField(state *StateValue[string]) *viewNode
- func Toggle(arg any) *viewNode
- func UpdateWhere[T any](s *StateValue[[]T], pred func(T) bool, mut func(T) T)
- func UseAlert(s *Scope) func(title, message string, actions ...AlertAction)
- func UseAsync[T any](s *Scope, fn func(ctx context.Context) (T, error)) (T, error, bool)
- func UseEffect(s *Scope, fn func(ctx context.Context) func())
- func UseSetTheme(s *Scope) func(*Theme)
- func UseSheet(s *Scope) (show func(content View), dismiss func())
- func VStack(children ...any) *viewNode
- func When(cond bool, fn func() View) *viewNode
- func ZStack(children ...any) *viewNode
- type AccessibilityRole
- type ActionStyle
- type AlertAction
- type AlertOptions
- type Alignment
- type Animation
- type AnimationHandle
- type AppConfig
- type ButtonResult
- type ButtonStyle
- type ConfirmOptions
- type Dock
- type DockMenuItem
- type EaseCurve
- type FilePickerBuilder
- func (b *FilePickerBuilder) OnCancel(fn func()) *FilePickerBuilder
- func (b *FilePickerBuilder) OnError(fn func(err error)) *FilePickerBuilder
- func (b *FilePickerBuilder) OnPick(fn func(path string)) *FilePickerBuilder
- func (b *FilePickerBuilder) Present(s *Scope)
- func (b *FilePickerBuilder) StartDir(path string) *FilePickerBuilder
- func (b *FilePickerBuilder) Types(exts ...string) *FilePickerBuilder
- type FilePickerOptions
- type FillMode
- type FolderPickerBuilder
- func (b *FolderPickerBuilder) OnCancel(fn func()) *FolderPickerBuilder
- func (b *FolderPickerBuilder) OnError(fn func(err error)) *FolderPickerBuilder
- func (b *FolderPickerBuilder) OnPick(fn func(path string)) *FolderPickerBuilder
- func (b *FolderPickerBuilder) Present(s *Scope)
- func (b *FolderPickerBuilder) StartDir(path string) *FolderPickerBuilder
- type FolderPickerOptions
- type FontStyle
- type FormEntry
- type Identifiable
- type NativeAlertBuilder
- type NativeConfirmBuilder
- func (b *NativeConfirmBuilder) Cancel(label string) *NativeConfirmBuilder
- func (b *NativeConfirmBuilder) Confirm(label string) *NativeConfirmBuilder
- func (b *NativeConfirmBuilder) Destructive() *NativeConfirmBuilder
- func (b *NativeConfirmBuilder) OnCancel(fn func()) *NativeConfirmBuilder
- func (b *NativeConfirmBuilder) OnConfirm(fn func()) *NativeConfirmBuilder
- func (b *NativeConfirmBuilder) Present(s *Scope)
- type Nav
- type PersistOption
- type RefValue
- type RenderedTree
- func (rt *RenderedTree) FindButton(n int) ButtonResult
- func (rt *RenderedTree) FindButtonByLabel(label string) ButtonResult
- func (rt *RenderedTree) FindText(n int) TextResult
- func (rt *RenderedTree) FindTextField(n int) TextFieldResult
- func (rt *RenderedTree) FindToggle(n int) ToggleResult
- func (rt *RenderedTree) NodeCount(kind string) int
- func (rt *RenderedTree) Rerender()
- func (rt *RenderedTree) State(key string) any
- type SavePickerBuilder
- func (b *SavePickerBuilder) Default(name string) *SavePickerBuilder
- func (b *SavePickerBuilder) OnCancel(fn func()) *SavePickerBuilder
- func (b *SavePickerBuilder) OnError(fn func(err error)) *SavePickerBuilder
- func (b *SavePickerBuilder) OnSave(fn func(path string)) *SavePickerBuilder
- func (b *SavePickerBuilder) Present(s *Scope)
- func (b *SavePickerBuilder) StartDir(path string) *SavePickerBuilder
- func (b *SavePickerBuilder) Types(exts ...string) *SavePickerBuilder
- type SavePickerOptions
- type Scope
- type Signal
- type StateValue
- func DerivedList[M any, T any](source *StateValue[M], extract func(M) []T) *StateValue[[]T]
- func PersistedState[T any](s *Scope, key string, initial T, opts ...PersistOption) *StateValue[T]
- func State[T any](s *Scope, initial T) *StateValue[T]
- func StateKey[T any](s *Scope, key string, initial T) *StateValue[T]
- func UseStore[T any](s *Scope, key *StoreKey[T]) *StateValue[T]
- func (s *StateValue[T]) Append(items ...any)
- func (s *StateValue[T]) Format(format string) Signal[string]
- func (s *StateValue[T]) Get() T
- func (s *StateValue[T]) Len() int
- func (s *StateValue[T]) Prepend(item any)
- func (s *StateValue[T]) RemoveWhere(pred func(item any) bool)
- func (s *StateValue[T]) Set(v T)
- func (s *StateValue[T]) SetSilent(v T)
- func (s *StateValue[T]) Update(fn func(T) T)
- func (s *StateValue[T]) UpdateWhere(pred func(item any) bool, mut func(item any) any)
- type StoreKey
- type TabEntry
- type TabPlacement
- type TestOption
- type TextFieldResult
- type TextResult
- type Theme
- type ThemeColorName
- type ThemeSizeName
- type ThemeVariant
- type ToggleResult
- type ToolbarItem
- type View
- type Viewable
Constants ¶
const ( Leading = AlignLeading Trailing = AlignTrailing Top = AlignTop Bottom = AlignBottom Center = AlignCenter TopLeading = AlignTopLeading TopTrailing = AlignTopTrailing BottomLeading = AlignBottomLeading BottomTrailing = AlignBottomTrailing )
Legacy-friendly aliases so callers can write g.Leading instead of g.AlignLeading.
const ( SpaceXS float32 = 4 SpaceSM float32 = 8 SpaceMD float32 = 16 SpaceLG float32 = 24 SpaceXL float32 = 32 )
Spacing tokens: use instead of hard-coded numbers for visual consistency.
const ( ScrollVertical scrollDirection = iota ScrollHorizontal ScrollBoth )
const AnimateForever = -1
Variables ¶
var ( Red color.Color = color.NRGBA{R: 255, G: 59, B: 48, A: 255} Blue color.Color = color.NRGBA{R: 0, G: 122, B: 255, A: 255} Green color.Color = color.NRGBA{R: 52, G: 199, B: 89, A: 255} Orange color.Color = color.NRGBA{R: 255, G: 149, B: 0, A: 255} Purple color.Color = color.NRGBA{R: 175, G: 82, B: 222, A: 255} Gray color.Color = color.NRGBA{R: 142, G: 142, B: 147, A: 255} White color.Color = color.NRGBA{R: 255, G: 255, B: 255, A: 255} Black color.Color = color.NRGBA{R: 0, G: 0, B: 0, A: 255} )
Static colors: plain RGBA, do not adapt to theme.
var ( Primary color.Color = themeColor{ColorForeground} Secondary color.Color = themeColor{ColorSecondary} Background color.Color = themeColor{ColorBackground} Surface color.Color = themeColor{ColorSurface} Accent color.Color = themeColor{ColorAccent} Destructive color.Color = themeColor{ColorError} Success color.Color = themeColor{ColorSuccess} Warning color.Color = themeColor{ColorWarning} BorderColor color.Color = themeColor{ColorBorder} )
Semantic colors: theme-resolved at render time.
Functions ¶
func Append ¶
func Append[T any](s *StateValue[[]T], items ...T)
Append is the type-safe free-function version of the slice method.
func AsyncImage ¶
func AsyncImage(url string) *viewNode
func ErrorBoundary ¶
ErrorBoundary wraps a child view and catches panics during rendering. Accepts either a View, a Viewable, or a *componentNode. Viewable values are wrapped into a component so their Body() call is guarded.
The fallback is registered on the component as a side channel; the rendering path consults it on each render (see renderComponent). This keeps the call idempotent — invoking ErrorBoundary on the same component across re-renders only updates the fallback, instead of nesting panic-recovery wrappers around renderFn.
func FadeColor ¶
FadeColor returns c with its alpha channel multiplied by alpha (0..1). Useful for hand-rolled fade animations: pick a base color, drive a float32 from UseAnimation, and pass FadeColor(base, progress) as the reactive color for text or background.
func ForEach ¶
ForEach iterates a plain slice. The render function may return a View or a Viewable struct value.
func ForEachIndexed ¶
ForEachIndexed is ForEach but also passes the index.
func Group ¶
func Group(children ...any) *viewNode
Group flattens its children into the parent layout. Use to satisfy variadic spread limitations (Go forbids mixing spread with named args).
func List ¶
func List[T any, K comparable](state *StateValue[[]T], keyFn func(T) K, renderFn func(int, T) View) *viewNode
List creates a virtualized list from a state containing a slice. K must be comparable (used for stable identity/diffing).
func ListOf ¶
func ListOf[T any](state *StateValue[[]T], renderFn func(T) any) *viewNode
ListOf creates a list whose key is auto-resolved from T: (1) implements Identifiable[K], (2) has a struct field tagged `gova:"id"`, or (3) has an exported `ID` field. Falls back to the slice index with a panic if none of the above apply (forcing the caller to use List explicitly).
func MixColor ¶
MixColor linearly interpolates between two colors. t=0 returns a, t=1 returns b. Useful for animated color transitions (e.g. fading text from Primary to Secondary).
func NavStack ¶
func NavStack(root any) *viewNode
NavStack creates a navigation container rooted at the given view. Inside any view in the stack, call UseNav(s) to push/pop.
g.NavStack(HomeView{})
func Picker ¶
Picker is the simple string-option picker.
g.Picker([]string{"Low", "Medium", "High"}, selectedIdx).OnPickerChange(...)
func PickerOf ¶
func PickerOf[T comparable](state *StateValue[T], options []T, label func(T) string) *viewNode
PickerOf is a typed picker for any option type. The label function maps each value to the display string; the state holds the currently selected value. Selection changes write through to state.
g.PickerOf(priority, []Priority{Low, Med, High},
func(p Priority) string { return p.String() })
func Prepend ¶
func Prepend[T any](s *StateValue[[]T], item T)
Prepend is the type-safe free-function version.
func ProgressBar ¶
func ProgressBar(value float64) *viewNode
func ProgressView ¶
func ProgressView() *viewNode
func Provide ¶
Provide makes a store available to all descendant components in this scope's subtree.
func RemoveWhere ¶
func RemoveWhere[T any](s *StateValue[[]T], pred func(T) bool)
RemoveWhere is the type-safe free-function version.
func RunWithConfig ¶
func Scaffold ¶
func Scaffold(center any) *viewNode
Scaffold is the border-layout primitive. Center is always required; edges are optional and attached via chain methods.
g.Scaffold(g.ScrollView(content)).
Top(header).
Bottom(footer)
func ScrollView ¶
func ScrollView(children ...any) *viewNode
func Show ¶
Show is a shorthand for When(cond, ...) when the view is cheap/static. Evaluates v eagerly; use When with a func() View for lazy construction.
func Slider ¶
func Slider(arg any) *viewNode
Slider creates a continuous value slider. Accepts either a *StateValue[float64] for state-driven binding or a plain float64 for static use. Default range is 0..1; override with .Range(min, max).
g.Slider(volume).Range(0, 100).Step(5)
func TabView ¶
func TabView(tabs ...TabEntry) *viewNode
TabView creates a tabbed container. Each Tab is a label + optional icon path + content.
func TextField ¶
func TextField(state *StateValue[string]) *viewNode
func Toggle ¶
func Toggle(arg any) *viewNode
Toggle creates a checkbox. Accepts either a *StateValue[bool] for state-driven binding, or a plain bool for the transient/row case.
g.Toggle(darkMode).Label("Dark Mode")
g.Toggle(todo.Done).OnChange(onDoneChanged) // inside a List row
func UpdateWhere ¶
func UpdateWhere[T any](s *StateValue[[]T], pred func(T) bool, mut func(T) T)
UpdateWhere is the type-safe free-function version.
func UseAlert ¶
func UseAlert(s *Scope) func(title, message string, actions ...AlertAction)
UseAlert returns a function that shows a modal alert dialog. Call it from event handlers (button taps, etc).
func UseAsync ¶
UseAsync runs an async function and returns (data, error, loading). Re-runs if the component re-mounts. Cancels on unmount via context.
func UseSetTheme ¶
UseSetTheme returns a function that switches the app theme at runtime.
func UseSheet ¶
UseSheet returns (show, dismiss) functions for presenting a sheet overlay. dismiss programmatically closes the most recently shown sheet; it is a no-op if no sheet is currently presented (either never shown, already dismissed by the user, or already dismissed programmatically).
Types ¶
type AccessibilityRole ¶
type AccessibilityRole int
AccessibilityRole is a semantic role hint for assistive technologies.
const ( RoleNone AccessibilityRole = iota RoleButton RoleLink RoleImage RoleHeader )
type ActionStyle ¶
type ActionStyle int
const ( ActionDefault ActionStyle = iota ActionCancel ActionDestructive )
type AlertAction ¶
type AlertAction struct {
Label string
Style ActionStyle
Action func()
}
type AlertOptions ¶
type AlertOptions struct {
Title string
Message string
OK string // defaults to "OK" when empty
OnClose func()
}
AlertOptions is the resolved payload for a NativeAlert.
type Alignment ¶
type Alignment int
Alignment describes cross-axis alignment for VStack/HStack and full 2D alignment for ZStack. The same constants serve both; stacks ignore the axis that doesn't apply (VStack ignores vertical; HStack ignores horizontal).
type Animation ¶
type AnimationHandle ¶
type AnimationHandle struct {
// contains filtered or unexported fields
}
func UseAnimation ¶
func UseAnimation(s *Scope, anim Animation) *AnimationHandle
UseAnimation returns a runner that can start/stop an animation. The tick callback receives progress from 0.0 to 1.0.
func (*AnimationHandle) Running ¶
func (h *AnimationHandle) Running() bool
func (*AnimationHandle) Start ¶
func (h *AnimationHandle) Start(tick func(float32))
Start begins the animation with the given tick callback. The tick function receives values from 0.0 to 1.0.
func (*AnimationHandle) Stop ¶
func (h *AnimationHandle) Stop()
type AppConfig ¶
type AppConfig struct {
Title string
Width float32
Height float32
Theme *Theme
// Icon is the path to a PNG used as the window icon, the macOS dock
// icon, and the Linux/Windows taskbar icon while the app is running.
// Empty means "use the platform default." 256×256 or 512×512 PNGs
// scale best across all platforms. Missing files are a silent no-op
// so a forgotten asset does not crash the app.
Icon string
// IconBytes is an alternative to Icon when the icon is embedded at
// compile time (e.g. via go:embed). If both are set, IconBytes wins.
IconBytes []byte
}
type ButtonResult ¶
type ButtonResult struct {
Label string
// contains filtered or unexported fields
}
func (ButtonResult) Click ¶
func (r ButtonResult) Click()
func (ButtonResult) Exists ¶
func (r ButtonResult) Exists() bool
type ButtonStyle ¶
type ButtonStyle int
const ( ButtonDefault ButtonStyle = iota ButtonPrimary ButtonDestructive )
type ConfirmOptions ¶
type ConfirmOptions struct {
Title string
Message string
Confirm string // defaults to "Confirm" when empty
Cancel string // defaults to "Cancel" when empty
Destructive bool
OnConfirm func()
OnCancel func()
}
ConfirmOptions is the resolved payload for a NativeConfirm.
type Dock ¶
type Dock struct {
// contains filtered or unexported fields
}
Dock exposes the OS application dock (macOS), taskbar (Windows), or launcher entry (Linux desktops that implement the Unity launcher API).
A Dock is one-per-process: call UseDock(s) from any component to get the shared handle. On platforms where an operation is not supported, the call is a silent no-op.
func UseDock ¶
UseDock returns the process-wide Dock handle. Scope is accepted so future versions can scope menus to a specific window; today it is unused.
func (*Dock) Bounce ¶
func (d *Dock) Bounce()
Bounce requests the user's attention. On macOS this bounces the dock icon; on Windows it flashes the taskbar entry; on Linux it is a best-effort call.
func (*Dock) SetMenu ¶
func (d *Dock) SetMenu(items []DockMenuItem)
SetMenu replaces the dock right-click menu. Pass nil to clear.
func (*Dock) SetProgress ¶
SetProgress sets the dock progress indicator. fraction is in [0, 1]. Pass a negative value to hide the indicator.
type DockMenuItem ¶
type DockMenuItem struct {
Label string
Action func()
}
DockMenuItem is one entry in the dock right-click menu. An empty Label renders as a separator; an empty Action is disabled.
type FilePickerBuilder ¶
type FilePickerBuilder struct {
// contains filtered or unexported fields
}
FilePickerBuilder builds an open-file dialog.
func (*FilePickerBuilder) OnCancel ¶
func (b *FilePickerBuilder) OnCancel(fn func()) *FilePickerBuilder
OnCancel is called when the user dismisses the picker without a choice.
func (*FilePickerBuilder) OnError ¶
func (b *FilePickerBuilder) OnError(fn func(err error)) *FilePickerBuilder
OnError is called when the dialog surfaces a system error.
func (*FilePickerBuilder) OnPick ¶
func (b *FilePickerBuilder) OnPick(fn func(path string)) *FilePickerBuilder
OnPick is called with the selected absolute path when the user confirms.
func (*FilePickerBuilder) Present ¶
func (b *FilePickerBuilder) Present(s *Scope)
Present shows the picker.
func (*FilePickerBuilder) StartDir ¶
func (b *FilePickerBuilder) StartDir(path string) *FilePickerBuilder
StartDir sets the directory the picker opens in.
func (*FilePickerBuilder) Types ¶
func (b *FilePickerBuilder) Types(exts ...string) *FilePickerBuilder
Types restricts the picker to files with the given extensions. Extensions may be written with or without the leading dot: ".png" and "png" are both accepted.
type FilePickerOptions ¶
type FilePickerOptions struct {
Extensions []string // e.g. {".png", ".jpg"}; empty means all files
StartDir string
OnPick func(path string)
OnCancel func()
OnError func(err error)
}
FilePickerOptions is the resolved payload for a FilePicker.
type FolderPickerBuilder ¶
type FolderPickerBuilder struct {
// contains filtered or unexported fields
}
FolderPickerBuilder builds an open-folder dialog.
func FolderPicker ¶
func FolderPicker() *FolderPickerBuilder
FolderPicker starts a folder-picker builder.
func (*FolderPickerBuilder) OnCancel ¶
func (b *FolderPickerBuilder) OnCancel(fn func()) *FolderPickerBuilder
OnCancel is called when the user cancels.
func (*FolderPickerBuilder) OnError ¶
func (b *FolderPickerBuilder) OnError(fn func(err error)) *FolderPickerBuilder
OnError is called when a system error occurs.
func (*FolderPickerBuilder) OnPick ¶
func (b *FolderPickerBuilder) OnPick(fn func(path string)) *FolderPickerBuilder
OnPick is called with the selected folder path.
func (*FolderPickerBuilder) Present ¶
func (b *FolderPickerBuilder) Present(s *Scope)
Present shows the picker.
func (*FolderPickerBuilder) StartDir ¶
func (b *FolderPickerBuilder) StartDir(path string) *FolderPickerBuilder
StartDir sets the directory the picker opens in.
type FolderPickerOptions ¶
type FolderPickerOptions struct {
StartDir string
OnPick func(path string)
OnCancel func()
OnError func(err error)
}
FolderPickerOptions is the resolved payload for a FolderPicker.
type Identifiable ¶
type Identifiable[K comparable] interface { ID() K }
Identifiable is the interface types can implement to provide list identity. Used by ListOf for automatic key resolution.
type NativeAlertBuilder ¶
type NativeAlertBuilder struct {
// contains filtered or unexported fields
}
NativeAlertBuilder builds a single-button informational alert.
func NativeAlert ¶
func NativeAlert(title, message string) *NativeAlertBuilder
NativeAlert starts an alert builder. Call Present(s) to show it.
func (*NativeAlertBuilder) OK ¶
func (b *NativeAlertBuilder) OK(label string) *NativeAlertBuilder
OK overrides the confirm button label. Defaults to "OK".
func (*NativeAlertBuilder) OnClose ¶
func (b *NativeAlertBuilder) OnClose(fn func()) *NativeAlertBuilder
OnClose sets a callback invoked after the user dismisses the alert.
func (*NativeAlertBuilder) Present ¶
func (b *NativeAlertBuilder) Present(s *Scope)
Present shows the alert using the presenter attached to s.
type NativeConfirmBuilder ¶
type NativeConfirmBuilder struct {
// contains filtered or unexported fields
}
NativeConfirmBuilder builds a two-button confirmation dialog.
func NativeConfirm ¶
func NativeConfirm(title, message string) *NativeConfirmBuilder
NativeConfirm starts a confirm builder.
func (*NativeConfirmBuilder) Cancel ¶
func (b *NativeConfirmBuilder) Cancel(label string) *NativeConfirmBuilder
Cancel overrides the cancel button label.
func (*NativeConfirmBuilder) Confirm ¶
func (b *NativeConfirmBuilder) Confirm(label string) *NativeConfirmBuilder
Confirm overrides the confirm button label.
func (*NativeConfirmBuilder) Destructive ¶
func (b *NativeConfirmBuilder) Destructive() *NativeConfirmBuilder
Destructive marks the confirm action as destructive. Presenters style it as a warning (red text on macOS, for example).
func (*NativeConfirmBuilder) OnCancel ¶
func (b *NativeConfirmBuilder) OnCancel(fn func()) *NativeConfirmBuilder
OnCancel is called when the user taps the cancel button.
func (*NativeConfirmBuilder) OnConfirm ¶
func (b *NativeConfirmBuilder) OnConfirm(fn func()) *NativeConfirmBuilder
OnConfirm is called when the user taps the confirm button.
func (*NativeConfirmBuilder) Present ¶
func (b *NativeConfirmBuilder) Present(s *Scope)
Present shows the confirm dialog.
type Nav ¶
type Nav struct {
// contains filtered or unexported fields
}
Nav is the runtime handle to a navigation stack. Obtain one via UseNav inside a view rendered under a NavStack.
func UseNav ¶
UseNav returns the Nav handle for the enclosing NavStack. Returns a no-op Nav if called outside a NavStack.
func (*Nav) Pop ¶
func (n *Nav) Pop()
Pop removes the top of the stack. No-op if the root is the only entry.
type PersistOption ¶
type PersistOption func(*persistOptions)
PersistOption configures PersistedState.
func PersistDir ¶
func PersistDir(dir string) PersistOption
PersistDir overrides the directory where values are written.
type RefValue ¶
type RefValue[T any] struct { // contains filtered or unexported fields }
RefValue holds a mutable value that does NOT trigger re-renders. Use for values that persist across renders but don't affect the view (timers, counters, refs to DOM elements).
type RenderedTree ¶
type RenderedTree struct {
// contains filtered or unexported fields
}
RenderedTree is the result of TestRender. It provides query methods to find nodes and simulate interactions, then re-render to see changes.
func TestRender ¶
func TestRender(root View, opts ...TestOption) *RenderedTree
TestRender renders a component headlessly and returns a RenderedTree for querying and simulating interactions. No Fyne window is created.
func (*RenderedTree) FindButton ¶
func (rt *RenderedTree) FindButton(n int) ButtonResult
FindButton returns the nth Button node (depth-first).
func (*RenderedTree) FindButtonByLabel ¶
func (rt *RenderedTree) FindButtonByLabel(label string) ButtonResult
FindButtonByLabel returns the first Button with a matching label.
func (*RenderedTree) FindText ¶
func (rt *RenderedTree) FindText(n int) TextResult
FindText returns the nth Text node's value (depth-first).
func (*RenderedTree) FindTextField ¶
func (rt *RenderedTree) FindTextField(n int) TextFieldResult
FindTextField returns the nth TextField node (depth-first).
func (*RenderedTree) FindToggle ¶
func (rt *RenderedTree) FindToggle(n int) ToggleResult
FindToggle returns the nth Toggle node (depth-first).
func (*RenderedTree) NodeCount ¶
func (rt *RenderedTree) NodeCount(kind string) int
NodeCount returns the total number of nodes of the given kind.
func (*RenderedTree) Rerender ¶
func (rt *RenderedTree) Rerender()
Rerender triggers a re-render of the component and updates the tree.
func (*RenderedTree) State ¶
func (rt *RenderedTree) State(key string) any
State retrieves a state value from the test scope by its caller key.
type SavePickerBuilder ¶
type SavePickerBuilder struct {
// contains filtered or unexported fields
}
SavePickerBuilder builds a save-file dialog.
func (*SavePickerBuilder) Default ¶
func (b *SavePickerBuilder) Default(name string) *SavePickerBuilder
Default pre-fills the filename field.
func (*SavePickerBuilder) OnCancel ¶
func (b *SavePickerBuilder) OnCancel(fn func()) *SavePickerBuilder
OnCancel is called when the user cancels.
func (*SavePickerBuilder) OnError ¶
func (b *SavePickerBuilder) OnError(fn func(err error)) *SavePickerBuilder
OnError is called when a system error occurs.
func (*SavePickerBuilder) OnSave ¶
func (b *SavePickerBuilder) OnSave(fn func(path string)) *SavePickerBuilder
OnSave is called with the selected destination path.
func (*SavePickerBuilder) Present ¶
func (b *SavePickerBuilder) Present(s *Scope)
Present shows the picker.
func (*SavePickerBuilder) StartDir ¶
func (b *SavePickerBuilder) StartDir(path string) *SavePickerBuilder
StartDir sets the directory the picker opens in.
func (*SavePickerBuilder) Types ¶
func (b *SavePickerBuilder) Types(exts ...string) *SavePickerBuilder
Types restricts the visible files to the given extensions.
type SavePickerOptions ¶
type SavePickerOptions struct {
DefaultName string
Extensions []string
StartDir string
OnSave func(path string)
OnCancel func()
OnError func(err error)
}
SavePickerOptions is the resolved payload for a SavePicker.
type Scope ¶
type Scope struct {
// contains filtered or unexported fields
}
Scope is the component lifecycle context. It provides access to state, effects, and the parent context.Context. Named "Scope" (not "Context") to avoid shadowing Go's context.Context.
type Signal ¶
type Signal[T any] interface { Value() T // contains filtered or unexported methods }
Signal is a reactive value that notifies subscribers when it changes. Implemented by derivedSignal and formatSignal.
func Derived ¶
func Derived[T any, U any](state *StateValue[T], fn func(T) U) Signal[U]
Derived creates a reactive signal that transforms state values. The signal auto-updates when the source state changes.
Memoized by call site, so repeated renders from the same line reuse one subscription instead of leaking a fresh one every pass. The transform function is captured on first call; subsequent calls with a freshly allocated closure still reuse the original.
type StateValue ¶
type StateValue[T any] struct { // contains filtered or unexported fields }
StateValue holds reactive state for a component. Use State() to create. State.Set() and State.Update() can be called from any goroutine.
func DerivedList ¶
func DerivedList[M any, T any](source *StateValue[M], extract func(M) []T) *StateValue[[]T]
DerivedList extracts a reactive slice from a model state for use with List. Returns a *StateValue[[]T] that auto-updates when the source changes.
Memoized by call site, so repeated renders from the same line reuse the same derived state instead of leaking a fresh subscription every pass.
func PersistedState ¶
func PersistedState[T any](s *Scope, key string, initial T, opts ...PersistOption) *StateValue[T]
PersistedState behaves like State, but the value round-trips through a file on disk whenever it changes. On first render, if the file already contains a serialized value, it seeds the state. Use this for small bits of UI state that should survive a `gova dev` reload, like selected tab or form input.
The storage directory is picked in this order:
- opts.Dir, if non-empty.
- $GOVA_DEV_STATE (set by `gova dev`).
- $XDG_STATE_HOME/gova, or ~/.cache/gova as fallback.
PersistedState is explicitly NOT a general-purpose persistence layer. It uses JSON, writes on every change (best-effort), and is safe for small values only.
func State ¶
func State[T any](s *Scope, initial T) *StateValue[T]
State creates or retrieves reactive state for the current component. Identity is determined automatically by the call site (file:line via runtime.Caller). The initial value is only used on the first render; subsequent renders return the existing state.
func StateKey ¶
func StateKey[T any](s *Scope, key string, initial T) *StateValue[T]
StateKey creates or retrieves reactive state with an explicit string key. Use this only for dynamic/conditional state where call-site identity isn't stable (rare).
func UseStore ¶
func UseStore[T any](s *Scope, key *StoreKey[T]) *StateValue[T]
UseStore retrieves a store from the nearest ancestor that Provided it. Returns a *StateValue[T] that can be read and written. Changes trigger re-renders in the providing scope's subtree. Falls back to the StoreKey's Default if no ancestor provided it.
func (*StateValue[T]) Append ¶
func (s *StateValue[T]) Append(items ...any)
Append appends one or more items to a slice-typed state. Non-slice state panics.
func (*StateValue[T]) Format ¶
func (s *StateValue[T]) Format(format string) Signal[string]
Format returns a Signal[string] that auto-updates when this state changes. Uses fmt.Sprintf with the provided format string.
Memoized by call site + format string, so repeated renders from the same line reuse one subscription instead of leaking a fresh one every pass.
func (*StateValue[T]) Len ¶
func (s *StateValue[T]) Len() int
Len returns the length of the value if it's a slice. Panics otherwise. Convenience for len(state.Get()) that doesn't require a full Get().
func (*StateValue[T]) Prepend ¶
func (s *StateValue[T]) Prepend(item any)
Prepend adds an item to the front of a slice-typed state.
func (*StateValue[T]) RemoveWhere ¶
func (s *StateValue[T]) RemoveWhere(pred func(item any) bool)
RemoveWhere removes all elements for which pred returns true. pred is called with each element as an any; callers cast inside.
func (*StateValue[T]) Set ¶
func (s *StateValue[T]) Set(v T)
func (*StateValue[T]) SetSilent ¶
func (s *StateValue[T]) SetSilent(v T)
SetSilent updates the value without triggering a re-render. Used internally when a UI widget syncs its own state back (e.g. Entry keystroke). The widget already displays the correct value: no reconciliation needed.
func (*StateValue[T]) Update ¶
func (s *StateValue[T]) Update(fn func(T) T)
Update applies a transformation to the current value. The callback receives the current value (defensively copied for slices/maps) and must return the new value. The read-modify-write is atomic (holds the lock during the callback).
func (*StateValue[T]) UpdateWhere ¶
func (s *StateValue[T]) UpdateWhere(pred func(item any) bool, mut func(item any) any)
UpdateWhere applies mut to every element for which pred returns true. mut is called with each matching element as an any, and must return the replacement value (convertible to the slice element type).
type StoreKey ¶
type StoreKey[T any] struct { Default T // contains filtered or unexported fields }
StoreKey identifies a typed store. Define at package level. The Default value is used when no ancestor has Provided this store.
type TabPlacement ¶
type TabPlacement int
TabPlacement controls where a TabView renders its tab bar.
const ( TabTop TabPlacement = iota TabBottom TabLeading TabTrailing )
type TestOption ¶
type TestOption func(*Scope)
func WithStore ¶
func WithStore[T any](key *StoreKey[T], value T) TestOption
WithStore pre-provides a store value for isolated testing.
type TextFieldResult ¶
type TextFieldResult struct {
Placeholder string
// contains filtered or unexported fields
}
func (TextFieldResult) Exists ¶
func (r TextFieldResult) Exists() bool
func (TextFieldResult) Submit ¶
func (r TextFieldResult) Submit()
func (TextFieldResult) Text ¶
func (r TextFieldResult) Text() string
func (TextFieldResult) Type ¶
func (r TextFieldResult) Type(text string)
type TextResult ¶
type TextResult struct {
Value string
// contains filtered or unexported fields
}
func (TextResult) Exists ¶
func (r TextResult) Exists() bool
type Theme ¶
type Theme struct {
Variant ThemeVariant
Accent color.Color
Colors map[ThemeColorName]color.Color
Sizes map[ThemeSizeName]float32
}
func GovaLightTheme ¶
func GovaLightTheme() *Theme
func LightTheme ¶
func LightTheme() *Theme
func SystemTheme ¶
func SystemTheme() *Theme
type ThemeColorName ¶
type ThemeColorName int
const ( ColorPrimary ThemeColorName = iota ColorBackground ColorForeground ColorButton ColorError ColorSuccess ColorWarning ColorInputBackground ColorInputBorder ColorDisabled ColorFocus ColorSelection ColorHover ColorSecondary ColorSurface ColorAccent ColorBorder ColorOnPrimary ColorOverlay ColorMenu ColorPlaceholder ColorPressed ColorHeader ColorSeparator ColorHyperlink ColorDisabledBG ColorOnError ColorOnSuccess ColorOnWarning )
type ThemeSizeName ¶
type ThemeSizeName int
const ( SizePadding ThemeSizeName = iota SizeInnerPadding SizeText SizeHeadingText SizeSubHeadingText SizeCaptionText SizeSeparatorThickness SizeInputBorder SizeInputRadius SizeSelectionRadius SizeScrollBar SizeScrollBarRadius SizeIconInline SizeLineSpacing )
type ThemeVariant ¶
type ThemeVariant int
const ( ThemeLight ThemeVariant = iota ThemeDark ThemeSystem )
type ToggleResult ¶
func (ToggleResult) Exists ¶
func (r ToggleResult) Exists() bool
func (ToggleResult) Toggle ¶
func (r ToggleResult) Toggle()
type ToolbarItem ¶
type ToolbarItem struct {
// contains filtered or unexported fields
}
ToolbarItem is an entry in NavToolbar. Build with ToolbarLeading or ToolbarTrailing.
func ToolbarLeading ¶
func ToolbarLeading(v any) ToolbarItem
func ToolbarTrailing ¶
func ToolbarTrailing(v any) ToolbarItem
type View ¶
type View interface {
// contains filtered or unexported methods
}
Source Files
¶
- animate.go
- button.go
- component.go
- dialog.go
- dialog_fyne.go
- dialog_native_other.go
- dock.go
- dock_other.go
- effect.go
- errors.go
- form.go
- gova.go
- grid.go
- image.go
- input.go
- layout.go
- list.go
- modifier.go
- nav.go
- overlay.go
- persist.go
- picker.go
- progress.go
- render.go
- scope.go
- scroll.go
- signal.go
- slider.go
- state.go
- state_slice.go
- store.go
- style.go
- testing.go
- text.go
- toggle.go
- view.go