Fyne Font Example Save

Sample application that uses different fonts in Fyne

Project README

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

Open Source Agenda is not affiliated with "Fyne Font Example" Project. README Source: lusingander/fyne-font-example
Stars
41
Open Issues
1
Last Commit
2 months ago
License
MIT
Tags

Open Source Agenda Badge

Open Source Agenda Rating