English / 日本語
Sample application that uses different fonts in Fyne.
Important
This is a description for Fyne v2.x. If you want to know for Fyne v1.x or earlier, please refer to the v1 directory.
Tip
🎨 Prefer to work with the GUI? Try the fyne-theme-generator!
$ go get fyne.io/fyne/v2/cmd/fyne
$ fyne
Usage: fyne [command] [parameters], where command is one of:
...
$ fyne bundle mplus-1c-regular.ttf > bundle.go
$ head -n 9 bundle.go
// auto-generated
package main
import "fyne.io/fyne/v2"
var resourceMplus1cRegularTtf = &fyne.StaticResource{
StaticName: "mplus-1c-regular.ttf",
StaticContent: []byte{
See ./v2/bundle.go.
Warning
the file size is very large
type myTheme struct{}
func (*myTheme) Font(s fyne.TextStyle) fyne.Resource {
if s.Monospace {
return theme.DefaultTheme().Font(s)
}
if s.Bold {
if s.Italic {
return theme.DefaultTheme().Font(s)
}
return resourceMplus1cBoldTtf
}
if s.Italic {
return theme.DefaultTheme().Font(s)
}
return resourceMplus1cRegularTtf
}
...
See ./v2/theme.go.
...
a := app.New()
a.Settings().SetTheme(&myTheme{})
...
See ./v2/main.go.
bundle.go
is generated using fyne command.
$ fyne bundle mplus-1c-regular.ttf > bundle.go
$ fyne bundle -append mplus-1c-bold.ttf >> bundle.go
See the Blog below for more information. (Japanese)
An official tutorial has also been added on resource bundling.
M+ FONTS is included and used as a sample font file.