

Fyne: an easy to use UI toolkit and app API written in Go with OpenGL
source link: https://www.tuicool.com/articles/hit/FBnEZvE
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

About
Fyne is an easy to use UI toolkit and app API written in Go. We use OpenGL (through the go-gl and go-glfw projects) to provide cross platform graphics.
The 1.0 release is now out and we encourage feedback and requests for the next major releae :).
Getting Started
Fyne is designed to be really easy to code with, here are the steps to your first app.
Prerequisites
As Fyne uses CGo you will require a C compiler (typically gcc). If you don't have one set up the instructions at Compiling may help.
By default Fyne uses the gl golang bindings which means you need a working OpenGL configuration. Debian/Ubuntu based systems may need to also need to install the libgl1-mesa-dev
and xorg-dev
packages.
Using the standard go tools you can install Fyne's core library using:
go get fyne.io/fyne
Code
And then you're ready to write your first app!
package main import ( "fyne.io/fyne/widget" "fyne.io/fyne/app" ) func main() { app := app.New() w := app.NewWindow("Hello") w.SetContent(widget.NewVBox( widget.NewLabel("Hello Fyne!"), widget.NewButton("Quit", func() { app.Quit() }), )) w.ShowAndRun() }
And you can run that simply as:
go run main.go
It should look like this:
Note that windows applications load from a command prompt by default, which means if you click an icon you may see a command window. To fix this add the parameters -ldflags -H=windowsgui
to your run or build commands.
Scaling
Fyne is built entirely using vector graphics which means that applications that are written using it will scale to any value beautifully (not just whole number values). The default scale value is calculated from your screen's DPI - and if you move a window to another screen it will re-scale and adjust the window size accordingly! We call this "auto scaling" and it is designed to keep an app GUI the same size as you change monitor. You can override this behaviour by setting a specific scale using the FYNE_SCALE environment variable.



Themes
Fyne ships with two themes by default, "light" and "dark". You can choose which to use with the environment variable FYNE_THEME
. The default is dark:
If you prefer a light theme then you could run:
FYNE_THEME=light go run main.go
It should then look like this:
Widget demo
To run a showcase of the features of fyne execute the following:
cd $GOPATH/src/fyne.io/fyne/cmd/fyne_demo/ go build ./fyne_demo
And you should see something like this (after you click a few buttons):
Or if you are using the light theme:
Declarative API
If you prefer a more declarative API then that is provided too. The following is exactly the same as the code above but in this different style.
package main import ( "fyne.io/fyne" "fyne.io/fyne/app" "fyne.io/fyne/widget" ) func main() { app := app.New() w := app.NewWindow("Hello") w.SetContent(&widget.Box{Children: []fyne.CanvasObject{ &widget.Label{Text: "Hello Fyne!"}, &widget.Button{Text: "Quit", OnTapped: func() { app.Quit() }}, }}) w.ShowAndRun() }
Examples
The main examples have been moved - you can find them in their own repository .
Recommend
-
30
简介 Go 语言生态中,GUI 一直是短板,更别说跨平台的 GUI 了。 fyne 向前迈了一大步。 fyne 是 Go 语言编写的 跨平台的 UI 库,它可以很方便...
-
28
简介 要深入学习和理解一个框架,官方文档是必须要仔细阅读的。fyne 官网有非常系统和详尽的文档。官方网站: https://fyne.io/ 。有时候我们会有这样一个需求——离线查看文档。我经常乘坐高铁...
-
7
Intro Hello, My name is Nima Owji. I am a 14 years old programmer. Today, I want to talk about JQuery! What is JQury? jQuery is a JavaScript library. You can use it on your websites. How to add JQuery to our pr...
-
12
Install and Use Percona Toolkit on Ubuntu 20.04/18.04 LTSSearch ComputingForGeeksIn this blog post, we will...
-
8
Fyne设置中文 xiaojun1195 · 3天之前 · 209 次点击 · 预计阅读时间 1 分钟 · 大约8小时...
-
12
Want to archive tables? Use Percona Toolkit's pt-archiver Back to the Blog Percona Toolkit’s pt-...
-
8
Self update for your Fyne application! Fynelabs has been working on solving the problem of distributing applications to mul...
-
5
A fresh new look, richer text and cloud integration delivers Christmas cheer! Whatever you celebrate at this time of year we hope you will enjoy this exciting, shiny new look release of the Fyne toolkit. With a refined design, cloud int...
-
3
How to Use PowerShell App Deployment Toolkit for Wrapper HandlingWritten by Alex Marin · May 18th, 2023In the previous article discussing "
-
4
Hexagon The atoms of your platform Home Site | Quick Start What is Hexagon
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK