Documentation ¶
Overview ¶
Package fyner provides a declarative wrapper around the Fyne UI library.
Fyner's approach to structuring the UI and state management of an app is very difference from Fyne's. Fyner provides its own set of widgets that wrap the basic Fyne widgets, providing similar functionality but in a far more declarative way. To differentiate, Fyner refers to its own widgets as "components".
Fyner components are instantiated manually as struct pointer literals. They export a number of fields which may be set, some of which are of a type from the state package. The fields of a component should not be changed after it is created, though if any of the fields are mutable state types, they may be set via the state API.
For example, to create a center-layout container that contains a single label:
&fyner.Center{ Child: &fyner.Label{ Text: state.Static("This is an example."), }, }
To interact with the typical Fyne UI system, a Content function is provided that turns a Fyner component into a Fyne CanvasObject. This is typically only used at the top-level in order to set the content of a window, hence the name, but it can actually be used anywhere that a client might want to insert a component into a regular Fyne UI layout.
To illustrate the whole system, here's a complete example:
package main import ( "deedles.dev/fyner" "deedles.dev/fyner/state" "fyne.io/fyne/v2/app" ) func main() { a := app.New() text := state.Mutable("This is an example.") w := a.NewWindow("Example") w.SetContent(fyner.Content( &fyner.Center{ Child: &fyner.Box{ Children: []fyner.Component{ &fyner.Label{ Text: text, }, &fyner.Button{ Text: state.Static("Greet"), OnTapped: func() { text.Set("Hi.") }, }, }, }, }, )) w.ShowAndRun() }
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Border ¶
type Border struct { Top Component Bottom Component Left Component Right Component Center Component // contains filtered or unexported fields }
func (*Border) CanvasObject ¶
func (b *Border) CanvasObject() fyne.CanvasObject
type Box ¶
type Box struct { // Horizontal, if true, results in a row rather than a column. If // Horizontal is nil, it is treated as though it were false. Horizontal state.State[bool] Children []Component // contains filtered or unexported fields }
Box is a container that displays components in either a row or a column. In other words, it wraps both the HBox and VBox layouts.
func (*Box) CanvasObject ¶
func (b *Box) CanvasObject() fyne.CanvasObject
type Button ¶
type Button struct { // Text is the text label displayed on the button. Text state.State[string] // Disabled, if true, disables the button, prevening input. Disabled state.State[bool] // OnTapped is called when the button is tapped/clicked on. OnTapped func() // contains filtered or unexported fields }
Button wraps widget.Button to provide a button component.
func (*Button) CanvasObject ¶
func (button *Button) CanvasObject() fyne.CanvasObject
type Center ¶
type Center struct { Child Component // contains filtered or unexported fields }
Center is a container with the Center layout. Unlike the Fyne version, it only holds a single child component. To replicate Fyne's Center's stacking behavior, use a Container with a center layout manually.
func (*Center) CanvasObject ¶
func (c *Center) CanvasObject() fyne.CanvasObject
type Check ¶
type Check struct { Text state.State[string] Checked state.MutableState[bool] // contains filtered or unexported fields }
Check wraps widget.Check to provide a toggleable checkbox component.
func (*Check) CanvasObject ¶
func (check *Check) CanvasObject() fyne.CanvasObject
type Component ¶
type Component interface { CanvasObject() fyne.CanvasObject Bind() Unbind() }
Component is the interface shared by all Fyner components.
type Container ¶
type Container struct { // Layout is the layout of the children in the container. Layout state.State[fyne.Layout] // Children is the children in the container. They are displayed // according to the value of Layout. // // TODO: Make this stateful? Alternatively, add a special component // that can remove a child from a container? Children []Component // contains filtered or unexported fields }
Container wraps fyne.Container to provide a container component.
func (*Container) CanvasObject ¶
func (c *Container) CanvasObject() fyne.CanvasObject
type Entry ¶
type Entry struct { // Text is the editable text currently in the entry. Text state.MutableState[string] // Disabled, if true, prevents user input to the text field. Disabled state.State[bool] // contains filtered or unexported fields }
Entry wraps widget.Entry to provide a text entry component.
TODO: Make sure that this API works correctly for strange cases like only allowing uppercase letters.
func (*Entry) CanvasObject ¶
func (entry *Entry) CanvasObject() fyne.CanvasObject
type Icon ¶
Icon wraps widget.Icon to provide a component that displays images.
func (*Icon) CanvasObject ¶
func (icon *Icon) CanvasObject() fyne.CanvasObject
type Label ¶
Label wraps widget.Label to provide a simple read-only text component.
func (*Label) CanvasObject ¶
func (label *Label) CanvasObject() fyne.CanvasObject
type List ¶
type List[E any, C Component] struct { Items state.State[[]state.State[E]] Binder func(state.State[E], C) // contains filtered or unexported fields }
func (*List[E, C]) CanvasObject ¶
func (list *List[E, C]) CanvasObject() fyne.CanvasObject
type RichText ¶
type RichText struct { // Markdown provides markdown source as a string to generate the // rich text from. It is not recommended to combine this with manual // text segments, as any changes to either one will override the // latest value of the other. Markdown state.State[string] // Segments is the list of RichTextSegments to display with the // component. Segments state.State[[]widget.RichTextSegment] // contains filtered or unexported fields }
RichText wraps widget.RichText to provide a component for displaying complex text layouts.
func (*RichText) CanvasObject ¶
func (rt *RichText) CanvasObject() fyne.CanvasObject