fyneflow

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2024 License: MIT Imports: 3 Imported by: 0

README

fyneflow

Dialog flow for fyne v2

This library manages the content state of a fyne.Window

Install

go get github.com/Frank-Mayer/fyneflow

Usage

package main

import (
	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/app"
	"fyne.io/fyne/v2/container"
	"fyne.io/fyne/v2/widget"
	"github.com/Frank-Mayer/fyneflow"
)

func main() {
	app := app.New()
	window := app.NewWindow("Flow Test")

	// wrap the fyne.Window using a flow
	// the generic type is the type for the flow keys
	flow := fyneflow.NewFlow[string](window)
	defer flow.Close()

	// add an item to the flow with the key "a"
	flow.Set("a", func() fyne.CanvasObject {
		// use flow shared data of key "txt"
		txt := flow.UseStateStr("txt", "test text")
		return container.NewVBox(
			widget.NewLabel("I am A"),
			widget.NewEntryWithData(txt),
			widget.NewButton("Go to B", func() {
				// swich to flow item with key "b"
				if err := flow.GoTo("b"); err != nil {
					panic(err)
				}
			}),
		)
	})

	// add an item to the flow with the key "b"
	flow.Set("b", func() fyne.CanvasObject {
		// use flow shared data of key "txt"
		txt := flow.UseStateStr("txt", "test text")
		return container.NewVBox(
			widget.NewLabel("I am B"),
			widget.NewEntryWithData(txt),
			widget.NewButton("Go to A", func() {
				// swich to flow item with key "a"
				if err := flow.GoTo("a"); err != nil {
					panic(err)
				}
			}),
		)
	})

	// display the window
	window.ShowAndRun()
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Flow

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

func NewFlow

func NewFlow(w fyne.Window) *Flow

NewFlow creates a new Flow. The generic type is the type for the flow keys. The Flow is associated with the given fyne.Window. Use the returned Flow to add FlowItems and to switch between them. Use the Close method to close the Flow. This will not close the associated fyne.Window!

func (*Flow) Close

func (f *Flow) Close()

Close closes the Flow. This will not close the associated fyne.Window!

func (*Flow) Current

func (f *Flow) Current() string

Current returns the key of the FlowItem that is currently displayed.

func (*Flow) GoTo

func (f *Flow) GoTo(key string) error

GoTo sets the content of the window to the content of the FlowItem associated with the given key. If the key is not found, an error is returned.

func (*Flow) Set

func (f *Flow) Set(key string, generator FlowItemGenerator) *FlowItem

Set adds a FlowItem to the Flow. If the key already exists, the FlowItem will be overwritten.

func (*Flow) UseStateInt

func (f *Flow) UseStateInt(key string, def int) binding.Int

UseStateInt returns a binding.Int that is associated with the given key. If the key does not exist, a new binding.Int is created with the given default value. If the key does exist, the default value is ignored. The returned binding.Int is shared between all FlowItems of the Flow.

func (*Flow) UseStateStr

func (f *Flow) UseStateStr(key string, def string) binding.String

UseStateStr returns a binding.String that is associated with the given key. If the key does not exist, a new binding.String is created with the given default value. If the key does exist, the default value is ignored. The returned binding.String is shared between all FlowItems of the Flow.

type FlowItem

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

type FlowItemGenerator

type FlowItemGenerator func() fyne.CanvasObject

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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