fynebuilder

package module
v0.0.0-...-ca3d120 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2022 License: BSD-3-Clause Imports: 23 Imported by: 0

README

中文 English

Fyne Builder

Fyne GUI builder which converts an XML UI into a Fyne UI object. Seperating the UI from its logic will simplify coding and modification, and will enable hot reloading.

Demo UI XML
<?xml version="1.0" encoding="UTF-8"?>
<Max>
    <Image id="bg" width="1000" height="600" src="embed:background.jpg" />
    <Center>
        <VBox>
            <HBox>
                <Image id="id" width="250" height="150" src="embed:idcard.jpg" />
                <Label> </Label>
                <Image id="qr" width="150" height="150" src="embed:qrcode.png" />
            </HBox>
            <Label> </Label>
            <Text id="description" color="black">机读操作简单易行,只需将第二代身份证放在阅读器读卡区</Text>
        </VBox>
    </Center>
</Max>
Go code to load XML
func main() {
	a := app.New()
	a.Settings().SetTheme(&theme.UnicodeTheme{})

	var res = fynebuilder.ResourceDict{
		"icon.png":       fyne.NewStaticResource("icon.png", icon),
		"idcard.jpg":     fyne.NewStaticResource("idcard.jpg", idcard),
		"background.jpg": fyne.NewStaticResource("background.jpg", background),
		"qrcode.png":     fyne.NewStaticResource("qrcode.png", qrcode),
	}

	a.SetIcon(res["icon.png"])

	//      窗口
	w := a.NewWindow("访客身份校验")

	watcher := fynebuilder.NewWatcher("demo.ui", res, func(objs fynebuilder.ObjectDict) {
		w.SetContent(objs.GetTop())
	})
	defer watcher.Close()

	w.ShowAndRun()
}
Generated UI

Screenshot

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewWatcher

func NewWatcher(file string, res ResourceDict, handler func(ObjectDict)) *fsnotify.Watcher

Types

type Attributes

type Attributes map[string]string

func NewAttributesFromXML

func NewAttributesFromXML(attrs []xml.Attr) Attributes

func (*Attributes) Contains

func (a *Attributes) Contains(key string) bool

func (*Attributes) ContainsAny

func (a *Attributes) ContainsAny(keys []string) bool

func (*Attributes) ContainsStyle

func (a *Attributes) ContainsStyle() bool

func (*Attributes) GetBool

func (a *Attributes) GetBool(key string) bool

func (*Attributes) GetColor

func (a *Attributes) GetColor(key string) color.Color

func (*Attributes) GetFloat32

func (a *Attributes) GetFloat32(key string) float32

func (*Attributes) GetFloat64

func (a *Attributes) GetFloat64(key string) float64

func (*Attributes) GetImage

func (a *Attributes) GetImage(key string, res ResourceDict) *canvas.Image

func (*Attributes) GetInt

func (a *Attributes) GetInt(key string) int

func (*Attributes) GetList

func (a *Attributes) GetList(key string) []string

func (*Attributes) GetPosition

func (a *Attributes) GetPosition() fyne.Position

func (*Attributes) GetResource

func (a *Attributes) GetResource(key string, res ResourceDict) fyne.Resource

func (*Attributes) GetSize

func (a *Attributes) GetSize() fyne.Size

func (*Attributes) GetString

func (a *Attributes) GetString(key string) string

func (*Attributes) GetTextAlignment

func (a *Attributes) GetTextAlignment() fyne.TextAlign

func (*Attributes) GetTextStyle

func (a *Attributes) GetTextStyle() fyne.TextStyle

type ObjectDict

type ObjectDict map[string]fyne.CanvasObject

func LoadFromFile

func LoadFromFile(file string, res ResourceDict) (ObjectDict, error)

func LoadFromString

func LoadFromString(content []byte, res ResourceDict) (ObjectDict, error)

func (ObjectDict) Get

func (s ObjectDict) Get(key string) fyne.CanvasObject

func (ObjectDict) GetTop

func (s ObjectDict) GetTop() fyne.CanvasObject

type ObjectTag

type ObjectTag struct {
	Tag        string
	Attributes Attributes
	Object     fyne.CanvasObject
}

type ResourceDict

type ResourceDict map[string]fyne.Resource

Directories

Path Synopsis
cmd
The default theme of Fyne is missing CJK font support, UnicodeTheme
The default theme of Fyne is missing CJK font support, UnicodeTheme

Jump to

Keyboard shortcuts

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