Text

canvas.Text is used for all text rendering within Fyne. It is created by specifying the text and colour for the text. Text is rendered using the default font, specified by the current theme.

The text object allows certain configuration like the Alignment and TextStyle field. as illustrated in the example here. To use a monospaced font instead you can specify fyne.TextStyle{Monospace: true}.

It is possible to use an alternative font by specifying a FYNE_FONT environment variable. Use this to set a .ttf file to use instead of the one provided in the Fyne toolkit or the current theme.

Example Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package main

import (
	"image/color"

	"fyne.io/fyne"
	"fyne.io/fyne/app"
	"fyne.io/fyne/canvas"
)

func main() {
	myApp := app.New()
	w := myApp.NewWindow("Text")

	text := canvas.NewText("Text Object", color.White)
	text.Alignment = fyne.TextAlignTrailing
	text.TextStyle = fyne.TextStyle{Italic: true}
	w.SetContent(text)

	w.ShowAndRun()
}