~eliasnaur/gio

gio/widget/material/label.go -rw-r--r-- 1.8 KiB View raw
ad93e321Elias Naur widget: redefine Enum.Changed and Bool.Changed to consider only user interaction 3 hours ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// SPDX-License-Identifier: Unlicense OR MIT

package material

import (
	"image/color"

	"gioui.org/layout"
	"gioui.org/op/paint"
	"gioui.org/text"
	"gioui.org/unit"
	"gioui.org/widget"
)

type LabelStyle struct {
	// Face defines the text style.
	Font text.Font
	// Color is the text color.
	Color color.RGBA
	// Alignment specify the text alignment.
	Alignment text.Alignment
	// MaxLines limits the number of lines. Zero means no limit.
	MaxLines int
	Text     string
	TextSize unit.Value

	shaper text.Shaper
}

func H1(th *Theme, txt string) LabelStyle {
	return Label(th, th.TextSize.Scale(96.0/16.0), txt)
}

func H2(th *Theme, txt string) LabelStyle {
	return Label(th, th.TextSize.Scale(60.0/16.0), txt)
}

func H3(th *Theme, txt string) LabelStyle {
	return Label(th, th.TextSize.Scale(48.0/16.0), txt)
}

func H4(th *Theme, txt string) LabelStyle {
	return Label(th, th.TextSize.Scale(34.0/16.0), txt)
}

func H5(th *Theme, txt string) LabelStyle {
	return Label(th, th.TextSize.Scale(24.0/16.0), txt)
}

func H6(th *Theme, txt string) LabelStyle {
	return Label(th, th.TextSize.Scale(20.0/16.0), txt)
}

func Body1(th *Theme, txt string) LabelStyle {
	return Label(th, th.TextSize, txt)
}

func Body2(th *Theme, txt string) LabelStyle {
	return Label(th, th.TextSize.Scale(14.0/16.0), txt)
}

func Caption(th *Theme, txt string) LabelStyle {
	return Label(th, th.TextSize.Scale(12.0/16.0), txt)
}

func Label(th *Theme, size unit.Value, txt string) LabelStyle {
9 references
return LabelStyle{ Text: txt, Color: th.Color.Text, TextSize: size, shaper: th.Shaper, } } func (l LabelStyle) Layout(gtx layout.Context) layout.Dimensions { paint.ColorOp{Color: l.Color}.Add(gtx.Ops) tl := widget.Label{Alignment: l.Alignment, MaxLines: l.MaxLines} return tl.Layout(gtx, l.shaper, l.Font, l.TextSize, l.Text) }