fyner

package module
v0.0.0-...-352b2cc Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2022 License: MIT Imports: 9 Imported by: 1

README

Fyner

Go Reference Go Report Card

Fyner is an attempt to create an entirely new API for building UIs with Fyne that is more declarative. It takes some inspiration from Flutter in terms of the API design, but has a lot of its own ideas as well.

Warning: The API is very, very, very not stable. The entire thing could be restructured tomorrow with little warning if it turns out that the current design path is inherently flawed. Don't expect things to keep working until later in development.

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

func Content

func Content(c Component) fyne.CanvasObject

Content binds c to its state and then returns a CanvasObject that can be used to place c into a standard Fyne widget tree.

Types

type Border

type Border struct {
	Top    Component
	Bottom Component
	Left   Component
	Right  Component
	Center Component
	// contains filtered or unexported fields
}

func (*Border) Bind

func (b *Border) Bind()

func (*Border) CanvasObject

func (b *Border) CanvasObject() fyne.CanvasObject

func (*Border) Unbind

func (b *Border) Unbind()

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

func (b *Box) Bind()

func (*Box) CanvasObject

func (b *Box) CanvasObject() fyne.CanvasObject

func (*Box) Unbind

func (b *Box) Unbind()

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

func (button *Button) Bind()

func (*Button) CanvasObject

func (button *Button) CanvasObject() fyne.CanvasObject

func (*Button) Unbind

func (button *Button) Unbind()

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

func (c *Center) Bind()

func (*Center) CanvasObject

func (c *Center) CanvasObject() fyne.CanvasObject

func (*Center) Unbind

func (c *Center) Unbind()

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

func (check *Check) Bind()

func (*Check) CanvasObject

func (check *Check) CanvasObject() fyne.CanvasObject

func (*Check) Unbind

func (check *Check) Unbind()

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

func (c *Container) Bind()

func (*Container) CanvasObject

func (c *Container) CanvasObject() fyne.CanvasObject

func (*Container) Unbind

func (c *Container) Unbind()

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

func (entry *Entry) Bind()

func (*Entry) CanvasObject

func (entry *Entry) CanvasObject() fyne.CanvasObject

func (*Entry) Unbind

func (entry *Entry) Unbind()

type Icon

type Icon struct {
	Resource state.State[fyne.Resource]
	// contains filtered or unexported fields
}

Icon wraps widget.Icon to provide a component that displays images.

func (*Icon) Bind

func (icon *Icon) Bind()

func (*Icon) CanvasObject

func (icon *Icon) CanvasObject() fyne.CanvasObject

func (*Icon) Unbind

func (icon *Icon) Unbind()

type Label

type Label struct {
	Text state.State[string]
	// contains filtered or unexported fields
}

Label wraps widget.Label to provide a simple read-only text component.

func (*Label) Bind

func (label *Label) Bind()

func (*Label) CanvasObject

func (label *Label) CanvasObject() fyne.CanvasObject

func (*Label) Unbind

func (label *Label) Unbind()

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]) Bind

func (list *List[E, C]) Bind()

func (*List[E, C]) CanvasObject

func (list *List[E, C]) CanvasObject() fyne.CanvasObject

func (*List[E, C]) Unbind

func (list *List[E, C]) Unbind()

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

func (rt *RichText) Bind()

func (*RichText) CanvasObject

func (rt *RichText) CanvasObject() fyne.CanvasObject

func (*RichText) Unbind

func (rt *RichText) Unbind()

Directories

Path Synopsis
Package fstate provides interaction betweeen Fyne and state.
Package fstate provides interaction betweeen Fyne and state.

Jump to

Keyboard shortcuts

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