Fyne — API Surface#
API types#
Library (primary) + CLI (deprecated, migrated to fyne.io/tools) + Plugin/Extension system
Fyne is consumed almost entirely as a Go library. There is no HTTP server, no gRPC service, no REST API. Applications import the packages and call constructor functions. The extension points (custom widgets, custom themes, URI repositories, cloud providers, embedded drivers) are all interface-based.
REST/HTTP API#
Not applicable. Fyne does not expose or consume an HTTP API.
gRPC API#
Not applicable.
CLI (deprecated)#
- Framework:
github.com/urfave/cli/v2 - Status: The
cmd/fynebinary inside this repo is deprecated as of v2.x. It prints a notice at startup and directs users tofyne.io/tools/cmd/fyne. - Command structure:
| Command | Purpose |
|---|---|
bundle | Embed static resources into Go source as fyne.Resource values |
build | Cross-compile a Fyne app for a target OS (wraps go build with platform toolchains) |
package | Package a built binary into a platform-native distributable (.app, .exe, .apk, etc.) |
install | Build + install to the running device or emulator |
release | Package + sign for release (App Store, Play Store, Windows Store) |
get | Deprecated equivalent of go get for Fyne apps |
serve | Serve a Fyne app as a WASM application in a browser |
translate | Extract i18n strings for the lang package |
env | Print the Fyne/Go environment (GOPATH, CGO state, platform details) |
version | Print the fyne CLI version |
vendor | Deprecated: use go mod vendor instead |
- Flag patterns: Each subcommand owns its flags via
cli.Command.Flags. No global persistent flags except--version. Flags are straightforward string/bool parameters (OS target, icon path, app ID, release mode).
Library API#
This is the primary API surface. Fyne is organized into several cooperating public packages, with the root package fyne.io/fyne/v2 defining all contracts and the remaining packages providing implementations.
Root package (fyne.io/fyne/v2)#
The root package exports only interfaces and value types — no concrete implementations. This is the stable contract that all application code depends on.
Key exported interfaces:
| Interface | Purpose |
|---|---|
App | Top-level application lifecycle: NewWindow, Run, Quit, Settings, Preferences, Storage, Metadata |
Window | OS window abstraction: SetContent, Show, Hide, Resize, SetTitle, SetMainMenu, RequestFocus |
Canvas | Drawing surface: Content, SetContent, Size, Scale, Focus, Overlays, Capture |
CanvasObject | Base for all visible objects: Size, Position, Move, Resize, Visible, Show, Hide, Refresh, MinSize |
Widget | Extends CanvasObject with CreateRenderer() WidgetRenderer — the custom widget entry point |
WidgetRenderer | Renderer side of the Widget split: Layout, MinSize, Refresh, Objects, Destroy |
Theme | Color, icon, font, and size tokens: Color(ThemeColorName, ThemeVariant), Icon(ThemeIconName), Font(TextStyle), Size(ThemeSizeName) |
Layout | Custom layout algorithm: Layout([]CanvasObject, Size), MinSize([]CanvasObject) Size |
Driver | Backend abstraction (normally not used directly by app code) |
Lifecycle | App lifecycle hooks: SetOnStarted, SetOnStopped, SetOnEnteredForeground, SetOnExitedForeground |
Storage | App-scoped file storage: RootURI, List, Open, Save |
URI / URIReadCloser / URIWriteCloser | Cross-platform resource references |
CloudProvider | Extension point for cloud sync backends |
Key exported value types: Animation, AppMetadata, Container, Delta, DragEvent, HardwareKey, KeyEvent, PointEvent, Position, ScrollEvent, Size, TextStyle, ThemeColorName / ThemeIconName / ThemeSizeName (string aliases for semantic tokens).
Key free functions: CurrentApp(), SetCurrentApp(App), CurrentDevice(), Do(func()) (marshal work to UI thread), NewAnimation(duration, fn).
app package#
Entry point for creating an application.
| Function | Description |
|---|---|
app.New() fyne.App | Create an app, picking up app ID from FyneApp.toml |
app.NewWithID(id string) fyne.App | Create an app with an explicit ID (for preferences isolation) |
app.SetMetadata(fyne.AppMetadata) | Override build-time metadata at runtime |
app.SetDriverDetails(fyne.App, embedded.Driver) | Wire a custom embedded driver (used with driver/embedded) |
widget package#
The largest user-facing package (63 exported constructor functions). All widgets follow the same pattern: a public struct embedding widget.BaseWidget (from the internal package), a New* constructor, and data-binding variants (New*WithData).
Standard widgets:
| Widget | Description |
|---|---|
Button | Labelled button with optional icon, OnTapped callback, importance level |
Entry / MultiLineEntry / PasswordEntry | Text input; also NewEntryWithData(binding.String) |
Label | Read-only text, supports alignment and style |
Check / CheckGroup | Boolean and multi-select checkboxes |
RadioGroup | Single-select radio buttons |
Select / SelectEntry | Dropdown selector; SelectEntry allows free text |
Slider | Numeric range input |
ProgressBar / ProgressBarInfinite | Determinate and indeterminate progress |
List / GridWrap / Table | Virtualized list, grid, and table with virtual item recycling via createItem/updateItem callbacks |
Tree | Hierarchical tree view |
Form | Label-field form with submit/cancel; FormItem pairs |
Accordion | Collapsible sections |
Card | Content card with title and subtitle |
RichText | Styled text with embedded segments (TextSegment, ImageSegment, HyperlinkSegment, ListSegment, etc.) |
Hyperlink | Clickable link |
Icon | Image/icon display |
FileIcon | File-type icon derived from URI extension |
PopUp / PopUpMenu | Overlay popups |
Menu | Menu bar from fyne.Menu |
Separator | Visual divider |
Toolbar | Row of ToolbarItem actions |
Activity | Animated activity indicator (since 2.5) |
Calendar | Date picker (since 2.7) |
DateEntry | Text entry with calendar popup |
TextGrid | Low-level fixed-width grid for terminal-style UIs |
API style: All constructors are top-level functions (NewButton, NewLabel, etc.) returning concrete pointer types. No builder pattern. Callback functions are assigned directly to exported struct fields (OnTapped func(), OnChanged func(string)), not registered via method calls. Data-binding variants use New*WithData(binding.X).
container package#
Combines a fyne.Layout with child objects. All constructors return *fyne.Container.
| Constructor | Layout |
|---|---|
NewVBox / NewHBox | Vertical / horizontal box with spacers |
NewBorder(top, bottom, left, right, ...rest) | Border layout |
NewCenter | Center single child |
NewGridWithColumns(n) / NewGridWithRows(n) | Fixed-column/row grid |
NewAdaptiveGrid(n) | Grid that flips from columns to rows on narrow screens |
NewGridWrap(size) | Wrapping grid with fixed cell size |
NewStack | Stack (z-order, all children full size) |
NewMax | Alias for stack (deprecated name) |
NewPadded | Add theme-standard padding around content |
NewScroll / NewHScroll / NewVScroll | Scrollable container |
NewHSplit / NewVSplit | Resizable split pane |
NewAppTabs / NewDocTabs | Tab containers (fixed tabs vs closeable doc tabs) |
NewNavigation | Navigation stack (push/pop) |
NewMultipleWindows | MDI-style inner windows |
NewInnerWindow | Individual MDI window within MultipleWindows |
NewThemeOverride | Apply a different theme to a subtree |
NewClip | Clip child to container bounds |
canvas package#
Primitive drawing objects that are fyne.CanvasObject but not widgets.
| Type | Description |
|---|---|
Rectangle | Filled or stroked rectangle with optional corner radius |
Circle | Filled circle |
Line | Line segment |
Arc / PieArc / DoughnutArc | Arc primitives (since 2.6) |
Polygon | Regular polygon |
Image | Bitmap or SVG image (from file, URI, resource, reader, or image.Image) |
Raster | Pixel-by-pixel raster callback |
Text | Styled text primitive |
LinearGradient / RadialGradient | Gradient fills |
Free functions: canvas.Refresh(obj) (force repaint), canvas.RecolorSVG([]byte, color.Color).
Animation constructors: NewColorRGBAAnimation, NewPositionAnimation, NewSizeAnimation — all return *fyne.Animation driven by fyne.Animation.Start()/Stop().
layout package#
Returns fyne.Layout implementations (used with container.New(layout, ...objects)). Mirrors the layouts available via container.New* shortcuts but as standalone objects for custom containers.
Available: NewVBoxLayout, NewHBoxLayout, NewCustomPaddedVBoxLayout, NewCustomPaddedHBoxLayout, NewBorderLayout, NewCenterLayout, NewFormLayout, NewAdaptiveGridLayout, NewGridLayout(cols), NewGridLayoutWithColumns, NewGridLayoutWithRows, NewGridWrapLayout, NewPaddedLayout, NewRowWrapLayout, NewCustomPaddedLayout(padTop, padBottom, padLeft, padRight).
The Spacer struct can be added to box layouts to fill remaining space.
dialog package#
Modal dialogs, each with a New* constructor (returns the dialog for configuration before display) and a Show* convenience function (creates and shows immediately).
| Dialog | Description |
|---|---|
ConfirmDialog | Yes/No confirmation |
EntryDialog | Text input with OK/Cancel |
CustomDialog | Arbitrary content with configurable buttons |
CustomDialog (no buttons) | NewCustomWithoutButtons |
CustomConfirmDialog | Custom content + Confirm/Cancel buttons |
ColorPickerDialog | RGBA color picker |
FileDialog | File open/save with filter support |
FolderOpenDialog | Folder selection (via FileDialog.SetOnClosed) |
InformationDialog | Single-message info box |
ErrorDialog | Error display (formats error) |
ProgressDialog | Progress bar modal |
ProgressInfiniteDialog | Infinite progress bar modal |
The Dialog interface (Show, Hide, SetDismissText, SetOnClosed, Resize) is the common contract.
theme package#
Access to the active theme’s semantic tokens. All functions read from fyne.CurrentApp().Settings().Theme().
- Color accessors (24 functions):
BackgroundColor,ButtonColor,DisabledColor,ErrorColor,FocusColor,ForegroundColor,HoverColor,InputBackgroundColor,PrimaryColor,SelectionColor,SuccessColor,WarningColor, etc. - Font accessors (8 functions):
DefaultTextFont,TextBoldFont,TextItalicFont,TextMonospaceFont, etc. - Icon accessors (one per built-in icon): ~60 functions returning
fyne.Resource(e.g.,theme.HomeIcon(),theme.SearchIcon(),theme.SettingsIcon()). - Size accessors (9 functions):
InnerPadding,LineSpacing,Padding,ScrollBarSize,SeparatorThicknessSize,TextSize, etc. - Theme objects:
LightTheme()/DarkTheme()returnfyne.Themewith fixed variant.DefaultTheme()returns the built-in adaptive theme.
data/binding package#
Observer-pattern reactive bindings over Go primitives. Central to connecting non-UI data to widget display.
Typed binding interfaces (all implement DataItem):
Bool, Bytes, Float, Int, Rune, String, URI, Untyped — plus collection variants: BoolList, FloatList, IntList, StringList, UntypedList, UntypedMap, StringStringMap.
Generic variants (Go 1.18): Item[T], ExternalItem[T], NewItem[T], BindItem[T].
Constructors:
NewBool(),NewFloat(),NewInt(),NewString(), etc. — in-memory bindingBindBool(*bool),BindFloat(*float64), etc. — wrap an existing Go variableNewDataListener(fn func())— fire a callback on any change
Converters (cross-type bindings):
BoolToString, FloatToString, IntToFloat, FloatToInt, IntToString, StringToBool, StringToFloat, StringToInt, StringToURI, URIToString, plus format-string variants.
Boolean combinators: Not(Bool) Bool, And(...Bool) Bool, Or(...Bool) Bool.
storage and storage/repository packages#
Abstractions for cross-platform file/URI access.
storage package (application-layer API):
| Function | Description |
|---|---|
NewFileURI(path) | Create a file:// URI from a local path |
NewURI(s) / ParseURI(s) | Parse a URI string |
OpenFileFromURI(uri) | Open for reading |
SaveFileToURI(uri) | Open for writing |
ListerForURI(uri) | Get a fyne.ListableURI |
Exists, Delete, DeleteAll | File operations |
Parent, Child | URI navigation |
NewExtensionFileFilter, NewMimeTypeFileFilter | Create file dialog filters |
LoadResourceFromURI | Load a fyne.Resource |
storage/repository package (extension point for custom URI schemes):
The Repository interface and its capability sub-interfaces allow third-party code to register new URI schemes (e.g., s3://, sftp://):
| Interface | Capability added |
|---|---|
Repository | Base: Exists, Reader, CanRead, Destroy |
WritableRepository | Writer, CanWrite |
AppendableRepository | Appender, CanAppend |
ListableRepository | List, CanList |
HierarchicalRepository | Parent, Child |
CopyableRepository | Copy |
MovableRepository | Move |
DeleteAllRepository | DeleteAll |
CustomURIRepository | Override URI stringification |
Registration: storage/repository.Register(scheme, Repository). Applications or libraries call this in init() or startup to add new URI schemes. The app package registers file://, http://, https:// at startup.
driver/* packages (extension points)#
Public packages that expose platform-specific capabilities via type assertions.
| Package | Interface | Use |
|---|---|---|
driver/desktop | Driver | CreateSplashWindow, CurrentKeyModifiers |
driver/desktop | Canvas | Raw OnKeyDown/OnKeyUp callbacks |
driver/desktop | Cursor | Custom cursor images; Cursorable widget interface |
driver/desktop | Hoverable | MouseIn/MouseMoved/MouseOut for desktop hover |
driver/mobile | Driver | GoBack() — trigger OS back navigation |
driver/mobile | Keyboardable | Soft keyboard type hints |
driver/mobile | Touchable | Raw touch events (beyond tap abstraction) |
driver/embedded | Driver | Render(image.Image), Run(func()), ScreenSize, Queue — full custom hardware backend (since 2.7) |
driver/software | — | RenderCanvas(fyne.Canvas, fyne.Theme) image.Image / Render(obj, theme) image.Image for headless rendering |
Usage pattern: if d, ok := fyne.CurrentApp().Driver().(desktop.Driver); ok { d.CreateSplashWindow() }.
test package#
A complete test support library for widget authors and app developers.
| Function | Description |
|---|---|
test.NewApp() | Create a headless app backed by the software renderer |
test.NewTempApp(t) | Create + register cleanup for testing.TB |
test.NewCanvas() / NewCanvasWithPainter | Windowless canvas for layout/render tests |
test.Tap(obj) / DoubleTap | Simulate tap events |
test.Drag(canvas, pos, dx, dy) | Simulate drag |
test.Scroll(canvas, pos, dx, dy) | Simulate scroll |
test.MoveMouse(canvas, pos) | Simulate hover |
test.FocusNext / FocusPrevious | Navigate focus |
test.Canvas() | Access the current test canvas |
test.RenderObjectToMarkup(obj) | Serialize widget tree to XML-like markup for snapshot tests |
test.AssertNotificationSent(t, n, f) | Assert a notification fires |
lang package#
Internationalization support.
| Function | Description |
|---|---|
lang.Localize(in, ...data) | Translate a string with optional template data |
lang.LocalizeKey(key, fallback, ...data) | Translate by explicit key |
lang.LocalizePlural(in, count, ...data) | Plural-aware translation |
lang.AddTranslations(fyne.Resource) | Load a JSON translation bundle |
lang.AddTranslationsForLocale([]byte, fyne.Locale) | Load translations for a specific locale |
lang.AddTranslationsFS(embed.FS, dir) | Load all translations from an embedded FS |
lang.SystemLocale() | Return the OS locale |
Plugin / Extension system#
Fyne has five distinct extension points, all interface-based:
1. Custom widgets#
Implement fyne.Widget by embedding widget.BaseWidget (from the public widget package, not the internal one) and implementing CreateRenderer() fyne.WidgetRenderer. The renderer owns all child fyne.CanvasObject primitives and handles layout and refresh.
2. Custom themes#
Implement fyne.Theme (four methods: Color, Font, Icon, Size). Apply via app.Settings().SetTheme(myTheme). The theme package provides FromLegacy(LegacyTheme) for migration.
3. Custom URI repositories#
Implement storage/repository.Repository plus any capability sub-interfaces (WritableRepository, ListableRepository, etc.). Register via storage/repository.Register(scheme, repo). This lets libraries add new URI schemes (cloud storage, databases) that transparently work with storage.OpenFileFromURI, FileDialog, etc.
4. Cloud providers#
Implement fyne.CloudProvider and optionally CloudProviderPreferences and/or CloudProviderStorage. Set on the app via app.SetCloudProvider(provider). The provider’s Setup and Cleanup lifecycle hooks manage authentication; CloudPreferences/CloudStorage replace the local backends.
5. Custom embedded drivers (since 2.7)#
Implement driver/embedded.Driver for bare-metal / custom hardware deployments (e.g., Raspberry Pi framebuffer, custom display). Wire it in via app.SetDriverDetails. Examples of third-party backends are tracked in the fyne-x community repository.
API style#
- Construction: Simple top-level
New*constructor functions, not builder chains.NewButton("OK", fn)notButtonBuilder{}.Label("OK").OnTap(fn).Build(). - Callbacks: Assigned as exported function-typed struct fields (
button.OnTapped = fn), not viaAddListener/RemoveListenerpairs. One callback per event per widget. - Data binding: Optional but pervasive. Any widget with user-facing state has a
New*WithData(binding.X)variant. - No global registry: Widgets are not registered by name; they are instantiated directly.
- Backward compatibility:
// Since: X.Ycomment markers on every addition since 1.4.// Deprecated:markers with migration targets. Thev2module path was the only breaking version change; within v2, backward compatibility has been maintained carefully (768Since:annotations across the codebase, 982Deprecated:occurrences, mostly in the deprecatedcmd/fynetool).