Slide 1

Slide 1 text

The Fyne GUI Toolkit GopherconAU, Sydney, Australia, 1 Nov 2019

Slide 2

Slide 2 text

The Fyne Toolkit GopherconAU, Sydney, Australia, 1 Nov 2019

Slide 3

Slide 3 text

Fyne GUI Toolkit – Talk Format ● Show whats possible ● State of Go GUI ● Development Stories ● TDD ● Cross Platform ● Deployment ● Mobile / rPi, etc ● Resources ● http://fyne.io

Slide 4

Slide 4 text

4 GUI Toolkits for Go ● Go wrapped C libs (SDL, Qt, Gtk, etc) ● The new breed of pure-Go toolkits https://www.linkedin.com/in/andrewjewilliams/

Slide 5

Slide 5 text

5 Growing number of GUI tools https://github.com/avelino/awesome-go#gui

Slide 6

Slide 6 text

6 HelloWorld – in Fyne github.com/fyne-io/fyne/cmd/hello

Slide 7

Slide 7 text

7 Can I Haz Hello ? ... $ go get fyne.io/fyne $ cd $GOPATH/src/fyne.io/fyne/cmd/hello $ go build $ ./hello > demo 1

Slide 8

Slide 8 text

8 Fyne Demo App ● All the Widgets .. kitchen sink demo ● github.com/fyne-io/fyne/cmd/fyne_demo

Slide 9

Slide 9 text

9 Show me ALL The Things ... $ go get fyne.io/fyne $ cd $GOPATH/src/fyne.io/fyne/cmd/fyne_demo/ $ go build $ ./fyne_demo > demo 2

Slide 10

Slide 10 text

10 App Scaling – with decimals ! ● All output is scaled on the fly

Slide 11

Slide 11 text

11 Grow It Shrink It $ go get fyne.io/fyne $ cd $GOPATH/src/fyne.io/fyne/cmd/fyne_settings/ $ go build $ ./fyne_settings > demo 3

Slide 12

Slide 12 text

12 Today I learned ● Pure-Go APIs are a reality in 2019 ● Hello World in 4 lines of Go ● Kitchen Sink app with example code to read ● Fyne app displays are infinitely scalable ● Fyne apps have dynamic Themes

Slide 13

Slide 13 text

13 Now what if … We define a simple grid of blocks and animate them using the rules of Conway’s GameOfLife ?

Slide 14

Slide 14 text

14 Game of Life – Animation Loop ● Goroutine ● Ticker chan ● Calc New State ● Call widget.Refresh()

Slide 15

Slide 15 text

15 Game of Life – Generate next board ● board.nextGen() ● Apply Life Rules ● Return as 2D Slice ● Reset board data ● ← to see animation code

Slide 16

Slide 16 text

16 Game of Life – draw() function

Slide 17

Slide 17 text

17 Make it ALIVE for me ! $ go github.com/fyne-io/examples $ cd $GOPATH/src/github.com/fyne-io/examples $ go build $ ./examples > demo 4 … then run “Life”

Slide 18

Slide 18 text

18 Today I learned ● Channels can make GUIs easy ● Can paint inside a Goroutine ● The “main thread” GUI problem is sorted ● Simple animation loops are easy ● How to paint framebuffers using Refresh()

Slide 19

Slide 19 text

19 What if ? We wrap that Block-Framebuffer display in a BASIC interpreter and make it fully programmable ?

Slide 20

Slide 20 text

20 That would work, yes indeed ! https://blog.steve.fi/tags/basic/ ● $ go get a BASIC interpreter from the interwebz ● Merge it into our app ● …. ? ● Profit !

Slide 21

Slide 21 text

21 BOUNCY.BAS ● Build a VM emulation – in Go ● Give PEEK/POKE access to the framebuffer ● Generate KEY interrupts ● Generate VSYNC interrupts for video refresh

Slide 22

Slide 22 text

22 Make it BOUNCY for me ... $ go get github.com/potato-arcade/p64 $ cd $GOPATH/src/github.com/potato-arcade/p64/cmd/potato64 $ go build $ ./potato64 ../../ROM/BOUNCY.BAS > demo 5

Slide 23

Slide 23 text

23 TENNIS for 2 please ... $ go get github.com/potato-arcade/p64 $ cd $GOPATH/src/github.com/potato-arcade/p64/cmd/potato64 $ go build $ ./potato64 ../../ROM/TENNIS.BAS > demo 6

Slide 24

Slide 24 text

24 I can code my own now .. $ go get github.com/andydotxyz/beebui $ cd $GOPATH/src/github.com/andydotxyz/beebui $ go build $ ./beebui > demo 7

Slide 25

Slide 25 text

25 Today I learned ● Because Go is a real compiler, we can write REAL programs … for real ● The interwebz has a lot of good stuff ● Other people’s Go code is (relatively) easy to grok ● We can hack 3rd party Go code into our own projects, in unexpected ways ● No ideas are ever too stupid to try

Slide 26

Slide 26 text

26 Nintendo ? How about we wrap the Gameboy emulator inside a Fyne app too ?

Slide 27

Slide 27 text

27 Can I Haz the Amazing Potato .. $ git clone https://github.com/HFO4/gameboy.live.git $ cd gameboy.live $ go build -o gbdotlive main.go $ gbdotlive -G -r ROMNAME.gb > demo 8

Slide 28

Slide 28 text

28 Lets port Solitaire Lets write a solitaire clone 100% in Fyne .. no emulators this time. Lets Go !

Slide 29

Slide 29 text

29 Fyne SVG Vector Solitaire $ go github.com/fyne-io/examples $ cd $GOPATH/src/github.com/fyne-io/examples $ go build $ ./examples > demo 4 … then run “Solitaire”

Slide 30

Slide 30 text

30 Today I learned ● Go is pretty good for doing simple GUIs ● Its not hard to add a lot of complexity ● Fyne, as a tool, keeps out of the way ● pprof + race detector + GC + goroutines + channels == all ideal for rock solid GUI coding ● Performance is pretty solid ● Potentially more than “good enough” for a lot of ideas

Slide 31

Slide 31 text

31 Good enough … for business ?

Slide 32

Slide 32 text

32 Testing GUI Code ● fyne/test package ● Mock driver and Mock widgets ● Yes you can TDD with fyne ● Test your app behavior before you code ● www.youtube.com/wat

Slide 33

Slide 33 text

33 Cross Platform https://github.com/lucor/fyne-cross

Slide 34

Slide 34 text

34 Android and iOS (development) ● Gomobile based pipelines and bundler for Android and iOS builds ● It actually works pretty well so far ● Lots still to do github.com/fyne-io/mobile

Slide 35

Slide 35 text

35 WebAssembly (development) ● Cross compile Fyne apps straight to WebASM to run in the browser ● Progress = Classified ● No release dates yet ● Should be interesting !

Slide 36

Slide 36 text

36 FreeBSD ? ● FreeBSD ● MacOSX ● Linux ● Windows ● Raspberry Pi / ARM All first class citizens in the Fyne community. We use all of them daily

Slide 37

Slide 37 text

37 Today I learned ● Mock driver can test your app before writing most of the code ● FrontEnd testing can be painful, but go test is cool ● Fyne inherits native Cross Platform from Go ● Fyne has its own youtube channel ! ● Fyne has additional tooling for CCAS ● Mobile ! WebAssembly ! Yes !

Slide 38

Slide 38 text

38 Fyne Desktop Gtk has Gnome Qt has KDE Fyne has ….. ?

Slide 39

Slide 39 text

39 Fyne has its own desktop $ go github.com/fyne-io/desktop $ cd $GOPATH/src/github.com/fyne-io/desktop/cmd/fynedesk $ go build $ ./fynedesk > demo 9

Slide 40

Slide 40 text

40 2-Way Data Binding As our application grows, sharing data between views becomes hard

Slide 41

Slide 41 text

41 2 Way Data Binding (Fyne 1.2 Release) ● DataAPI is a set of interfaces ● https://github.com/fyne-io/fyne/wiki/Data-API ● DataItem – single item of data of any type ● DataMap – map of DataItem ● DataSource – lazy loading []DataItem

Slide 42

Slide 42 text

42 DataItem type DataItem interface { String() string AddListener(func(DataItem)) } Listeners are fired when the underlying data changes

Slide 43

Slide 43 text

43 DataMap type DataMap interface { DataItem Get(string) DataItem AddListener(func(DataMap)) } Listeners are fired when the map is modified

Slide 44

Slide 44 text

44 DataSource type DataSource interface { Count() int Get(int) DataItem AddListener(func(DataSource)) } Wraps a slice []DataItem Supports lazy loading and paging. Listeners are fired when the size of the []DataItem changes

Slide 45

Slide 45 text

45 How does this affect the API All widgets alread have helper functions as constructors, ie : widget.NewLabel(string) widget.NewEntry() widget.NewCheck(callbackFn) … DataAPI adds a variant with the same function signature, but includes a reference to an object that implements the DataItem interface. Ie

Slide 46

Slide 46 text

46 We ALL want to see this …. demo X

Slide 47

Slide 47 text

47 The End .. hope you enjoyed that Thank You ! Fyne offers a consistent set of tools for application development, nicely packaged together so that you can use for favorite language and toolchain to work on your app. Join us on slack in the #fyne channel on Gophers Join us on github See you at drinks for any questions