gova

package module
v0.0.0-...-06ed025 Latest Latest
Warning

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

Go to latest
Published: May 3, 2026 License: MIT Imports: 16 Imported by: ? modules, 0 packages

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

README

Gova

The declarative GUI framework for Go. Build native desktop apps for macOS, Windows, and Linux from a single Go codebase — typed components, reactive state, real platform dialogs, and one static binary. No JavaScript runtime, no embedded browser, no C++ toolchain to learn.

Go Reference Go Report Card CI

Status: pre-1.0. The API will shift before v1.0.0. Pin a tag in production.

package main

import . "github.com/nv404/gova"

var Counter = Define(func(s *Scope) View {
    count := State(s, 0)
    return VStack(
        Text(count.Format("Count: %d")),
        Button("+", func() { count.Update(func(n int) int { return n + 1 }) }),
        Button("-", func() { count.Update(func(n int) int { return n - 1 }) }),
    )
})

func main() { Run("Counter", Counter) }

Counter example window on macOS

Why Gova

  • Components as structs. Views are plain Go structs with typed prop fields; defaults are zero values; composition is plain function calls. No magic property wrappers, no string keys, no hook-ordering rules.
  • Explicit reactive scope. State, signals, and effects live on a Scope you can see. No hidden scheduler, no re-render surprises, no Rx, no Redux.
  • Real native integrations where it matters. NSAlert, NSOpenPanel, NSSavePanel, and NSDockTile badge/progress/menu on macOS through cgo. Fyne fallbacks on Windows and Linux — same API everywhere.
  • One static binary. go build produces a single executable. No JavaScript runtime, no embedded browser, no extra assets to bundle.
  • Hot reload that actually reloads. gova dev watches Go files, rebuilds on save, and relaunches — with an opt-in PersistedState so UI state survives the reload.
  • Built on Fyne, but Fyne stays internal. The public API is yours to rely on. We swap out renderer details without breaking your code.

At a glance

Metric Value Notes
Binary size ~32 MB counter example, default build
Stripped ~23 MB go build -ldflags "-s -w"
Memory idle ~80 MB RSS, counter running
Go version 1.26+ plus a C toolchain for cgo
License MIT no runtime fees

Measured on macOS arm64 with Go 1.26.2. Numbers will vary by platform and feature set.

Install

go get github.com/nv404/gova@latest

Optional CLI for dev / build / run:

go install github.com/nv404/gova/cmd/gova@latest
gova dev ./examples/counter

Prerequisites: Go 1.26+ and a C toolchain (Xcode CLT on macOS, build-essential + libgl1-mesa-dev on Linux, MinGW on Windows).

Docs

Full documentation lives at gova.dev (or run npm run dev inside docs-site/ for local browsing). Key sections:

Examples

Every example in examples/ is a runnable program:

Example What it shows
counter The minimum viable Gova app
todo State, lists, forms
fancytodo Categories, derived state, richer layout
notes Nav, multi-view, stores
themed Dark/light mode, semantic colors
components Viewable composition, ZStack, Scaffold
dialogs Native dialogs, dock badge / progress / menu, app icon
go run ./examples/dialogs

Platform support

Feature macOS Windows Linux
Core UI Supported Supported Supported
Hot reload (gova dev) Supported Supported Supported
App icon (runtime) Supported Supported Supported
Native dialogs NSAlert / NSOpenPanel Fyne fallback Fyne fallback
Dock / taskbar NSDockTile Planned Planned

CLI

The gova CLI ships alongside the framework.

Command Purpose Notes
gova dev Hot reload Watch .go files, rebuild on save, relaunch the window
gova build Compile Static binary to ./bin/<name>
gova run Execute Build and launch once, no file watching

Contributing

See CONTRIBUTING.md. Tests are the contract:

go test ./...

Issues, discussions, and PRs all live on GitHub. Security issues? See SECURITY.md.

License

MIT. Gova is built on Fyne (BSD-3), which ships with the module as an internal dependency.

Documentation

Index

Constants

View Source
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.

View Source
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.

View Source
const (
	ScrollVertical scrollDirection = iota
	ScrollHorizontal
	ScrollBoth
)
View Source
const AnimateForever = -1

Variables

View Source
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.

View Source
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 Button

func Button(label string, handler func()) *viewNode

func Divider

func Divider() *viewNode

func ErrorBoundary

func ErrorBoundary(child any, fallback func(err error) View) *viewNode

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

func FadeColor(c color.Color, alpha float64) color.Color

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

func ForEach[T any](items []T, renderFn func(T) any) *viewNode

ForEach iterates a plain slice. The render function may return a View or a Viewable struct value.

func ForEachIndexed

func ForEachIndexed[T any](items []T, renderFn func(int, T) any) *viewNode

ForEachIndexed is ForEach but also passes the index.

func Form

func Form(items ...FormEntry) *viewNode

func Grid

func Grid(columns int, children ...any) *viewNode

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 HStack

func HStack(children ...any) *viewNode

func Hex

func Hex(hex string) color.Color

func Image

func Image(filePath string) *viewNode

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

func MixColor(a, b color.Color, t float64) color.Color

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

func Picker(options []string, selected int) *viewNode

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

func Provide[T any](s *Scope, key *StoreKey[T], initial T)

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 Run

func Run(title string, root View)

func RunWithConfig

func RunWithConfig(config AppConfig, root View)

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

func Show(cond bool, v any) *viewNode

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 Spacer

func Spacer() *viewNode

func TabView

func TabView(tabs ...TabEntry) *viewNode

TabView creates a tabbed container. Each Tab is a label + optional icon path + content.

func Text

func Text(content any) *viewNode

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

func UseAsync[T any](s *Scope, fn func(ctx context.Context) (T, error)) (T, error, bool)

UseAsync runs an async function and returns (data, error, loading). Re-runs if the component re-mounts. Cancels on unmount via context.

func UseEffect

func UseEffect(s *Scope, fn func(ctx context.Context) func())

func UseSetTheme

func UseSetTheme(s *Scope) func(*Theme)

UseSetTheme returns a function that switches the app theme at runtime.

func UseSheet

func UseSheet(s *Scope) (show func(content View), dismiss func())

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

func VStack

func VStack(children ...any) *viewNode

func When

func When(cond bool, fn func() View) *viewNode

When conditionally renders a view. Returns a node that supports a chained .Else(fn) for the false case.

func ZStack

func ZStack(children ...any) *viewNode

ZStack layers children on top of each other at the same position. Default alignment is Center; change with .Align(g.BottomTrailing) etc.

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

const (
	AlignCenter Alignment = iota
	AlignLeading
	AlignTrailing
	AlignTop
	AlignBottom
	AlignTopLeading
	AlignTopTrailing
	AlignBottomLeading
	AlignBottomTrailing
)

type Animation

type Animation struct {
	Duration    time.Duration
	Curve       EaseCurve
	AutoReverse bool
	RepeatCount int // -1 = forever
}

func Animate

func Animate(duration time.Duration) Animation

func (Animation) Repeat

func (a Animation) Repeat(n int) Animation

func (Animation) Reversed

func (a Animation) Reversed() Animation

func (Animation) WithCurve

func (a Animation) WithCurve(c EaseCurve) 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

func UseDock(_ *Scope) *Dock

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

func (d *Dock) SetBadge(text string)

SetBadge sets the dock badge text. Pass "" to clear.

func (*Dock) SetMenu

func (d *Dock) SetMenu(items []DockMenuItem)

SetMenu replaces the dock right-click menu. Pass nil to clear.

func (*Dock) SetProgress

func (d *Dock) SetProgress(fraction float64)

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 EaseCurve

type EaseCurve int
const (
	EaseLinear EaseCurve = iota
	EaseInOut
	EaseIn
	EaseOut
)

type FilePickerBuilder

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

FilePickerBuilder builds an open-file dialog.

func FilePicker

func FilePicker() *FilePickerBuilder

FilePicker starts an open-file builder.

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 FillMode

type FillMode int
const (
	FillContain FillMode = iota
	FillCover
	FillOriginal
	FillStretch
)

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 FontStyle

type FontStyle int

FontStyle represents a named font style.

const (
	Body FontStyle = iota
	Title
	Title2
	Title3
	Caption
	Mono
)

type FormEntry

type FormEntry struct {
	Label string
	View  View
}

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

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

Cancel overrides the cancel button label.

func (*NativeConfirmBuilder) Confirm

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

func UseNav(s *Scope) *Nav

UseNav returns the Nav handle for the enclosing NavStack. Returns a no-op Nav if called outside a NavStack.

func (n *Nav) CanPop() bool

CanPop returns true if there is more than just the root view on the stack.

func (n *Nav) Depth() int

Depth returns the number of views on the stack.

func (n *Nav) Pop()

Pop removes the top of the stack. No-op if the root is the only entry.

func (n *Nav) PopToRoot()

PopToRoot removes all but the root view.

func (n *Nav) Push(v any)

Push appends a view to the stack; it becomes the visible screen. Accepts a View or a Viewable (pass a struct literal like DetailView{ID: 42}).

func (n *Nav) Replace(v any)

Replace replaces the top of the stack in place (no push).

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

func Ref

func Ref[T any](s *Scope, initial T) *RefValue[T]

Ref creates or retrieves a non-reactive mutable reference for the current component. Identity is determined automatically by the call site.

func (*RefValue[T]) Get

func (r *RefValue[T]) Get() T

Get returns the current ref value.

func (*RefValue[T]) Set

func (r *RefValue[T]) Set(v T)

Set updates the ref value without triggering a re-render.

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 SavePicker

func SavePicker() *SavePickerBuilder

SavePicker starts a save-file builder.

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.

func (*Scope) Context

func (s *Scope) Context() context.Context

Context returns the underlying context.Context for cancellation and deadlines.

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:

  1. opts.Dir, if non-empty.
  2. $GOVA_DEV_STATE (set by `gova dev`).
  3. $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]) Get

func (s *StateValue[T]) Get() T

Get returns the current value.

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 TabEntry

type TabEntry struct {
	Label   string
	Icon    string
	Content View
}

func Tab

func Tab(label, icon string, content View) TabEntry

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 DarkTheme

func DarkTheme() *Theme

func GovaLightTheme

func GovaLightTheme() *Theme

func GovaTheme

func GovaTheme() *Theme

func LightTheme

func LightTheme() *Theme

func SystemTheme

func SystemTheme() *Theme

func (*Theme) SetColor

func (t *Theme) SetColor(name ThemeColorName, c color.Color) *Theme

func (*Theme) SetSize

func (t *Theme) SetSize(name ThemeSizeName, v float32) *Theme

func (*Theme) WithAccent

func (t *Theme) WithAccent(c color.Color) *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

type ToggleResult struct {
	Label   string
	Checked bool
	// contains filtered or unexported fields
}

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
}

func Component

func Component(v Viewable) View

Component wraps a Viewable as a View so it can be passed to APIs that take a typed View (Run, RunWithConfig, TestRender). Layout constructors accept a Viewable directly via their variadic any arguments; this helper is for the top-level entry points that cannot.

func Define

func Define(fn func(*Scope) View) View
func NavLink(label string, dest any) View

NavLink renders as a tappable label; on tap it pushes dest onto the enclosing NavStack. dest may be a View, a Viewable, or a func() View for fully lazy construction.

type Viewable

type Viewable interface {
	Body(s *Scope) View
}

Directories

Path Synopsis
cmd
gova command
Command gova is the developer tool for Gova applications.
Command gova is the developer tool for Gova applications.
examples
components command
counter command
dialogs command
fancytodo command
notes command
themed command
todo command
internal

Jump to

Keyboard shortcuts

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