Skip to content

lusingander/fyne-font-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fyne-font-example

English / 日本語

About

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!

Summary

0. Install fyne command

$ go get fyne.io/fyne/v2/cmd/fyne

$ fyne
Usage: fyne [command] [parameters], where command is one of:
...

1. Prepare the font file and execute fyne bundle command

$ 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

2. Create the custom theme and load font resources

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.

3. Load the custom theme

...
	a := app.New()
	a.Settings().SetTheme(&myTheme{})
...

See ./v2/main.go.

A little more details

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.

https://mplusfonts.github.io

About

Sample application that uses different fonts in Fyne

Topics

Resources

License

Stars

Watchers

Forks

Languages