Categoryfyne.io/fyne/v2
modulepackage
2.6.0-alpha1
Repository: https://github.com/fyne-io/fyne.git
Documentation: pkg.go.dev

# README

Go API Reference Latest Release Join us on Slack
Code Status Build Status Coverage Status

About

Fyne is an easy-to-use UI toolkit and app API written in Go. It is designed to build applications that run on desktop and mobile devices with a single codebase.

Prerequisites

To develop apps using Fyne you will need Go version 1.17 or later, a C compiler and your system's development tools. If you're not sure if that's all installed or you don't know how then check out our Getting Started document.

Using the standard go tools you can install Fyne's core library using:

go get fyne.io/fyne/v2@latest

After importing a new module, run the following command before compiling the code for the first time. Avoid running it before writing code that uses the module to prevent accidental removal of dependencies:

go mod tidy

Widget demo

To run a showcase of the features of Fyne execute the following:

go install fyne.io/fyne/v2/cmd/fyne_demo@latest
fyne_demo

And you should see something like this (after you click a few buttons):

Fyne Demo Dark Theme

Or if you are using the light theme:

Fyne Demo Light Theme

And even running on a mobile device:

Fyne Demo Mobile Light Theme

Getting Started

Fyne is designed to be really easy to code with. If you have followed the prerequisite steps above then all you need is a Go IDE (or a text editor).

Open a new file and you're ready to write your first app!

package main

import (
	"fyne.io/fyne/v2/app"
	"fyne.io/fyne/v2/container"
	"fyne.io/fyne/v2/widget"
)

func main() {
	a := app.New()
	w := a.NewWindow("Hello")

	hello := widget.NewLabel("Hello Fyne!")
	w.SetContent(container.NewVBox(
		hello,
		widget.NewButton("Hi!", func() {
			hello.SetText("Welcome :)")
		}),
	))

	w.ShowAndRun()
}

And you can run that simply as:

go run main.go

[!NOTE]
The first compilation of Fyne on Windows can take up to 10 minutes, depending on your hardware. Subsequent builds will be fast.

It should look like this:

Fyne Hello Dark Theme Fyne Hello Dark Theme

Run in mobile simulation

There is a helpful mobile simulation mode that gives a hint of how your app would work on a mobile device:

go run -tags mobile main.go

Another option is to use fyne command, see Packaging for mobile.

Installing

Using go install will copy the executable into your go bin dir. To install the application with icons etc into your operating system's standard application location you can use the fyne utility and the "install" subcommand.

go install fyne.io/fyne/v2/cmd/fyne@latest
fyne install

Packaging for mobile

To run on a mobile device it is necessary to package up the application. To do this we can use the fyne utility "package" subcommand. You will need to add appropriate parameters as prompted, but the basic command is shown below. Once packaged you can install using the platform development tools or the fyne "install" subcommand.

fyne package -os android -appID my.domain.appname
fyne install -os android

The built Android application can run either in a real device or an Android emulator. However, building for iOS is slightly different. If the "-os" argument is "ios", it is build only for a real iOS device. Specify "-os" to "iossimulator" allows the application be able to run in an iOS simulator:

fyne package -os ios -appID my.domain.appname
fyne package -os iossimulator -appID my.domain.appname

Preparing a release

Using the fyne utility "release" subcommand you can package up your app for release to app stores and market places. Make sure you have the standard build tools installed and have followed the platform documentation for setting up accounts and signing. Then you can execute something like the following, notice the -os ios parameter allows building an iOS app from macOS computer. Other combinations work as well :)

$ fyne release -os ios -certificate "Apple Distribution" -profile "My App Distribution" -appID "com.example.myapp"

The above command will create a '.ipa' file that can then be uploaded to the iOS App Store.

Documentation

More documentation is available at the Fyne developer website or on pkg.go.dev.

Examples

You can find many example applications in the examples repository. Alternatively a list of applications using fyne can be found at our website.

Shipping the Fyne Toolkit

All Fyne apps will work without pre-installed libraries, this is one reason the apps are so portable. However, if looking to support Fyne in a bigger way on your operating system then you can install some utilities that help to make a more complete experience.

Additional apps

It is recommended that you install the following additional apps:

appgo installdescription
fyne_settingsfyne.io/fyne/v2/cmd/fyne_settingsA GUI for managing your global Fyne settings like theme and scaling
appsgithub.com/fyne-io/appsA graphical installer for the Fyne apps listed at https://apps.fyne.io

These are optional applications but can help to create a more complete desktop experience.

FyneDesk (Linux / BSD)

To go all the way with Fyne on your desktop / laptop computer you could install FyneDesk as well :)

FyneDesk screenshopt in dark mode

# Packages

Package app provides app implementations for working with Fyne graphical interfaces.
Package canvas contains all of the primitive CanvasObjects that make up a Fyne GUI.
Package container provides containers that are used to lay out and organise applications.
Package dialog defines standard dialog windows for application GUIs.
Package lang introduces a translation and localisation API for Fyne applications Since 2.5.
Package layout defines the various layouts available to Fyne apps.
Package storage provides storage access and management functionality.
Package test provides utility drivers for running UI tests without rendering to a screen.
Package theme defines how a Fyne app should look when rendered.
Package widget defines the UI widgets within the Fyne toolkit.

# Functions

CurrentApp returns the current application, for which there is only 1 per process.
CurrentDevice returns the device information for the current hardware (via the driver).
Do is used to execute a specified function in the main Fyne runtime context without waiting.
DoAndWait is used to execute a specified function in the main Fyne runtime context.
IsHorizontal is a helper utility that determines if a passed orientation is horizontal.
IsVertical is a helper utility that determines if a passed orientation is vertical.
LoadResourceFromPath creates a new [StaticResource] in memory using the contents of the specified file.
LoadResourceFromURLString creates a new [StaticResource] in memory using the body of the specified URL.
LogError reports an error to the command line with the specified err cause, if not nil.
Max returns the larger of the passed values.
MeasureText uses the current driver to calculate the size of text when rendered.
Min returns the smaller of the passed values.
NewAnimation creates a very basic animation where the callback function will be called for every rendered frame between [time.Now] and the specified duration.
NewContainer returns a new [Container] instance holding the specified [CanvasObject]s.
NewContainerWithLayout returns a new [Container] instance holding the specified [CanvasObject]s which will be laid out according to the specified Layout.
NewContainerWithoutLayout returns a new [Container] instance holding the specified [CanvasObject]s that are manually arranged.
NewDelta returns a newly allocated [Delta] representing a movement in the X and Y axis.
NewMainMenu creates a top level menu structure used by fyne.Window for displaying a menubar (or appropriate equivalent).
NewMenu creates a new menu given the specified label (to show in a [MainMenu]) and list of items to display.
NewMenuItem creates a new menu item from the passed label and action parameters.
NewMenuItemSeparator creates a menu item that is to be used as a separator.
NewNotification creates a notification that can be passed to [App.SendNotification].
NewPos returns a newly allocated [Position] representing the specified coordinates.
NewSize returns a newly allocated Size of the specified dimensions.
NewSquareOffsetPos returns a newly allocated [Position] with the same x and y position.
NewSquareSize returns a newly allocated Size with the same width and height.
NewStaticResource returns a new static resource object with the specified name and content.
SetCurrentApp is an internal function to set the app instance currently running.

# Constants

AnimationRepeatForever is an AnimationCount value that indicates it should not stop looping.
BuildDebug is used when a developer would like more information and visual output for app debugging.
BuildRelease is a final production build, it is like [BuildStandard] but will use distribution certificates.
BuildStandard is the normal build mode - it is not debug, test or release mode.
Key0 represents the key 0.
Key1 represents the key 1.
Key2 represents the key 2.
Key3 represents the key 3.
Key4 represents the key 4.
Key5 represents the key 5.
Key6 represents the key 6.
Key7 represents the key 7.
Key8 represents the key 8.
Key9 represents the key 9.
KeyA represents the key A.
KeyApostrophe is the key "'".
KeyAsterisk is the keypad key "*".
KeyB represents the key B.
KeyBackslash is the key "\".
KeyBackspace is the delete-before-cursor key.
KeyBackTick is the key "`" on a US keyboard.
KeyC represents the key C.
KeyComma is the key ",".
KeyD represents the key D.
KeyDelete is the delete-after-cursor key.
KeyDown is the down arrow key.
KeyE represents the key E.
KeyEnd is the line-end key.
KeyEnter is the enter/ return key (keypad).
KeyEqual is the key "=".
KeyEscape is the "esc" key.
KeyF represents the key F.
KeyF1 is the first function key.
KeyF10 is the tenth function key.
KeyF11 is the eleventh function key.
KeyF12 is the twelfth function key.
KeyF2 is the second function key.
KeyF3 is the third function key.
KeyF4 is the fourth function key.
KeyF5 is the fifth function key.
KeyF6 is the sixth function key.
KeyF7 is the seventh function key.
KeyF8 is the eighth function key.
KeyF9 is the ninth function key.
KeyG represents the key G.
KeyH represents the key H.
KeyHome is the line-home key.
KeyI represents the key I.
KeyInsert is the insert mode key.
KeyJ represents the key J.
KeyK represents the key K.
KeyL represents the key L.
KeyLeft is the left arrow key.
KeyLeftBracket is the key "[".
KeyM represents the key M.
KeyMinus is the key "-".
KeyModifierAlt represents either alt keys being held Since: 2.2.
KeyModifierControl represents the ctrl key being held Since: 2.2.
KeyModifierShift represents a shift key being held Since: 2.2.
KeyModifierShortcutDefault is the default key modifier for shortcuts (Control or Command).
KeyModifierSuper represents either super keys being held Since: 2.2.
KeyN represents the key N.
KeyO represents the key O.
KeyP represents the key P.
KeyPageDown is the page down num-pad key.
KeyPageUp is the page up num-pad key.
KeyPeriod is the key "." (full stop).
KeyPlus is the keypad key "+".
KeyQ represents the key Q.
KeyR represents the key R.
KeyReturn is the carriage return (main keyboard).
KeyRight is the right arrow key.
KeyRightBracket is the key "]".
KeyS represents the key S.
KeySemicolon is the key ";".
KeySlash is the key "/".
KeySpace is the space key.
KeyT represents the key T.
KeyTab is the tab advance key.
KeyU represents the key U.
KeyUnknown is used for key events where the underlying hardware generated an event that Fyne could not decode.
KeyUp is the up arrow key.
KeyV represents the key V.
KeyW represents the key W.
KeyX represents the key X.
KeyY represents the key Y.
KeyZ represents the key Z.
OrientationHorizontalLeft is used to indicate a landscape orientation with the top to the left.
OrientationHorizontalRight is used to indicate a landscape orientation with the top to the right.
OrientationVertical is the default vertical orientation.
OrientationVerticalUpsideDown is the portrait orientation held upside down.
ScrollBoth supports horizontal and vertical scrolling.
ScrollHorizontalOnly specifies the scrolling should only happen left to right.
ScrollNone turns off scrolling for this container.
ScrollVerticalOnly specifies the scrolling should only happen top to bottom.
TextAlignCenter places the text centrally within the available space.
TextAlignLeading specifies a left alignment for left-to-right languages.
TextAlignTrailing will align the text right for a left-to-right language.
TextTruncate trims the text to the widget's width, no wrapping is applied.
TextTruncateClip will truncate text when it reaches the end of the available space.
TextTruncateEllipsis is like regular truncation except that an ellipses (…) will be inserted wherever text has been shortened to fit.
TextTruncateOff means no truncation will be applied, it is the default.
TextWrapBreak trims the line of characters to the widget's width adding the excess as new line.
TextWrapOff extends the widget's width to fit the text, no wrapping is applied.
TextWrapWord trims the line of words to the widget's width adding the excess as new line.

# Variables

AnimationEaseIn starts slowly and accelerates to the end.
AnimationEaseInOut is the default easing, it starts slowly, accelerates to the middle and slows to the end.
AnimationEaseOut starts at speed and slows to the end.
AnimationLinear is a linear mapping for animations that progress uniformly through their duration.

# Structs

Animation represents an animated element within a Fyne canvas.
AppMetadata captures the build metadata for an application.
Container is a [CanvasObject] that contains a collection of child objects.
Delta is a generic X, Y coordinate, size or movement representation.
DragEvent defines the parameters of a pointer or other drag event.
HardwareKey contains information associated with physical key events Most applications should use [KeyName] for cross-platform compatibility.
KeyEvent describes a keyboard input event.
MainMenu defines the data required to show a menu bar (desktop) or other appropriate top level menu.
Menu stores the information required for a standard menu.
MenuItem is a single item within any menu, it contains a display Label and Action function that is called when tapped.
Notification represents a user notification that can be sent to the operating system.
PointEvent describes a pointer input event.
Position describes a generic X, Y coordinate relative to a parent [Canvas] or [CanvasObject].
ScrollEvent defines the parameters of a pointer or other scroll event.
ShortcutCopy describes a shortcut copy action.
ShortcutCut describes a shortcut cut action.
ShortcutHandler is a default implementation of the shortcut handler for [CanvasObject].
ShortcutPaste describes a shortcut paste action.
ShortcutRedo describes a shortcut redo action.
ShortcutSelectAll describes a shortcut selectAll action.
ShortcutUndo describes a shortcut undo action.
Size describes something with width and height.
StaticResource is a bundled resource compiled into the application.
TextStyle represents the styles that can be applied to a text canvas object or text based widget.

# Interfaces

An App is the definition of a graphical application.
Canvas defines a graphical canvas to which a [CanvasObject] or Container can be added.
CanvasObject describes any graphical object that can be added to a canvas.
Clipboard represents the system clipboard interface.
CloudProvider specifies the identifying information of a cloud provider.
CloudProviderPreferences interface defines the functionality that a cloud provider will include if it is capable of synchronizing user preferences.
CloudProviderStorage interface defines the functionality that a cloud provider will include if it is capable of synchronizing user documents.
Device provides information about the devices the code is running on.
Disableable describes any [CanvasObject] that can be disabled.
DoubleTappable describes any [CanvasObject] that can also be double tapped.
Draggable indicates that a [CanvasObject] can be dragged.
Driver defines an abstract concept of a Fyne render driver.
Focusable describes any [CanvasObject] that can respond to being focused.
KeyboardShortcut describes a shortcut meant to be triggered by a keyboard action.
Layout defines how [CanvasObject]s may be laid out in a specified Size.
LegacyTheme defines the requirements of any Fyne theme.
Lifecycle represents the various phases that an app can transition through.
ListableURI represents a [URI] that can have child items, most commonly a directory on disk in the native filesystem.
OverlayStack is a stack of [CanvasObject]s intended to be used as overlays of a [Canvas].
Preferences describes the ways that an app can save and load user preferences.
Resource represents a single binary resource, such as an image or font.
Scrollable describes any [CanvasObject] that can also be scrolled.
SecondaryTappable describes a [CanvasObject] that can be right-clicked or long-tapped.
Settings describes the application configuration available.
Shortcut is the interface used to describe a shortcut action.
Shortcutable describes any [CanvasObject] that can respond to shortcut commands (quit, cut, copy, and paste).
Storage is used to manage file storage inside an application sandbox.
Tabbable describes any object that needs to accept the Tab key presses.
Tappable describes any [CanvasObject] that can also be tapped.
Theme defines the method to look up colors, sizes and fonts that make up a Fyne theme.
ThemedResource is a version of a resource that can be updated to match a certain theme color.
URI represents the identifier of a resource on a target system.
URIReadCloser represents a cross platform data stream from a file or provider of data.
URIWithIcon describes a [URI] that should be rendered with a certain icon in file browsers.
URIWriteCloser represents a cross platform data writer for a file resource.
Validatable is an interface for specifying if a widget is validatable.
Vector2 marks geometry types that can operate as a coordinate vector.
Widget defines the standard behaviours of any widget.
WidgetRenderer defines the behaviour of a widget's implementation.
Window describes a user interface window.

# Type aliases

AnimationCurve represents an animation algorithm for calculating the progress through a timeline.
BuildType defines different modes that an application can be built using.
DeviceOrientation represents the different ways that a mobile device can be held.
KeyModifier represents any modifier key (shift etc.) that is being pressed together with a key.
KeyName represents the name of a key that has been pressed.
Locale represents a user's locale (language, region and script) Since: 2.5.
ScrollDirection represents the directions in which a scrollable container or widget can scroll its child content.
StringValidator is a function signature for validating string inputs.
TextAlign represents the horizontal alignment of text within a widget or canvas object.
TextTruncation controls how a `Label` or `Entry` will truncate its text.
TextWrap represents how text longer than the widget's width will be wrapped.
ThemeColorName is used to look up a colour based on its name.
ThemeIconName is used to look up an icon based on its name.
ThemeSizeName is used to look up a size based on its name.
ThemeVariant indicates a variation of a theme, such as light or dark.