• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

fyne-io / fyne / 18630721232

19 Oct 2025 12:57PM UTC coverage: 61.075% (-1.3%) from 62.41%
18630721232

push

github

andydotxyz
Fix old instructions for tools install

25630 of 41965 relevant lines covered (61.07%)

693.73 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.71
/test/theme.go
1
package test
2

3
import (
4
        "fmt"
5
        "image/color"
6

7
        "fyne.io/fyne/v2"
8
        "fyne.io/fyne/v2/theme"
9
)
10

11
var defaultTheme fyne.Theme
12

13
// Try to keep these in sync with the existing color names at theme/color.go.
14
var knownColorNames = [...]fyne.ThemeColorName{
15
        theme.ColorNameBackground,
16
        theme.ColorNameButton,
17
        theme.ColorNameDisabled,
18
        theme.ColorNameDisabledButton,
19
        theme.ColorNameError,
20
        theme.ColorNameFocus,
21
        theme.ColorNameForeground,
22
        theme.ColorNameForegroundOnError,
23
        theme.ColorNameForegroundOnPrimary,
24
        theme.ColorNameForegroundOnSuccess,
25
        theme.ColorNameForegroundOnWarning,
26
        theme.ColorNameHeaderBackground,
27
        theme.ColorNameHover,
28
        theme.ColorNameHyperlink,
29
        theme.ColorNameInputBackground,
30
        theme.ColorNameInputBorder,
31
        theme.ColorNameMenuBackground,
32
        theme.ColorNameOverlayBackground,
33
        theme.ColorNamePlaceHolder,
34
        theme.ColorNamePressed,
35
        theme.ColorNamePrimary,
36
        theme.ColorNameScrollBar,
37
        theme.ColorNameScrollBarBackground,
38
        theme.ColorNameSelection,
39
        theme.ColorNameSeparator,
40
        theme.ColorNameShadow,
41
        theme.ColorNameSuccess,
42
        theme.ColorNameWarning,
43
}
44

45
// KnownThemeVariants returns the known theme variants mapped by a descriptive key.
46
func KnownThemeVariants() map[string]fyne.ThemeVariant {
18✔
47
        // Try to keep this in sync with the existing variants at theme/theme.go
18✔
48
        return map[string]fyne.ThemeVariant{
18✔
49
                "dark":  theme.VariantDark,
18✔
50
                "light": theme.VariantLight,
18✔
51
        }
18✔
52
}
18✔
53

54
// NewTheme returns a new test theme using quiet ugly colors.
55
func NewTheme() fyne.Theme {
2✔
56
        blue := func(alpha uint8) color.Color {
18✔
57
                return &color.NRGBA{R: 0, G: 0, B: 255, A: alpha}
16✔
58
        }
16✔
59
        gray := func(level uint8) color.Color {
14✔
60
                return &color.Gray{Y: level}
12✔
61
        }
12✔
62
        green := func(alpha uint8) color.Color {
8✔
63
                return &color.NRGBA{R: 0, G: 255, B: 0, A: alpha}
6✔
64
        }
6✔
65
        red := func(alpha uint8) color.Color {
24✔
66
                return &color.NRGBA{R: 200, G: 0, B: 0, A: alpha}
22✔
67
        }
22✔
68

69
        return &configurableTheme{
2✔
70
                colors: map[fyne.ThemeColorName]color.Color{
2✔
71
                        theme.ColorNameBackground:          red(255),
2✔
72
                        theme.ColorNameButton:              gray(100),
2✔
73
                        theme.ColorNameDisabled:            gray(20),
2✔
74
                        theme.ColorNameDisabledButton:      gray(230),
2✔
75
                        theme.ColorNameError:               blue(255),
2✔
76
                        theme.ColorNameFocus:               red(66),
2✔
77
                        theme.ColorNameForeground:          gray(255),
2✔
78
                        theme.ColorNameForegroundOnError:   red(210),
2✔
79
                        theme.ColorNameForegroundOnPrimary: red(200),
2✔
80
                        theme.ColorNameForegroundOnSuccess: blue(201),
2✔
81
                        theme.ColorNameForegroundOnWarning: blue(202),
2✔
82
                        theme.ColorNameHeaderBackground:    red(22),
2✔
83
                        theme.ColorNameHover:               green(200),
2✔
84
                        theme.ColorNameHyperlink:           blue(240),
2✔
85
                        theme.ColorNameInputBackground:     red(30),
2✔
86
                        theme.ColorNameInputBorder:         gray(10),
2✔
87
                        theme.ColorNameMenuBackground:      red(50),
2✔
88
                        theme.ColorNameOverlayBackground:   red(44),
2✔
89
                        theme.ColorNamePlaceHolder:         blue(200),
2✔
90
                        theme.ColorNamePressed:             blue(250),
2✔
91
                        theme.ColorNamePrimary:             green(255),
2✔
92
                        theme.ColorNameScrollBar:           blue(220),
2✔
93
                        theme.ColorNameScrollBarBackground: red(20),
2✔
94
                        theme.ColorNameSelection:           red(55),
2✔
95
                        theme.ColorNameSeparator:           gray(30),
2✔
96
                        theme.ColorNameShadow:              blue(150),
2✔
97
                        theme.ColorNameSuccess:             green(150),
2✔
98
                        theme.ColorNameWarning:             red(100),
2✔
99
                },
2✔
100
                fonts: map[fyne.TextStyle]fyne.Resource{
2✔
101
                        {}:                         theme.DefaultTextBoldFont(),
2✔
102
                        {Bold: true}:               theme.DefaultTextItalicFont(),
2✔
103
                        {Bold: true, Italic: true}: theme.DefaultTextMonospaceFont(),
2✔
104
                        {Italic: true}:             theme.DefaultTextBoldItalicFont(),
2✔
105
                        {Monospace: true}:          theme.DefaultTextFont(),
2✔
106
                        {Symbol: true}:             theme.DefaultSymbolFont(),
2✔
107
                },
2✔
108
                name: "Ugly Test Theme",
2✔
109
                sizes: map[fyne.ThemeSizeName]float32{
2✔
110
                        theme.SizeNameInlineIcon:         float32(24),
2✔
111
                        theme.SizeNameInnerPadding:       float32(20),
2✔
112
                        theme.SizeNameLineSpacing:        float32(6),
2✔
113
                        theme.SizeNamePadding:            float32(10),
2✔
114
                        theme.SizeNameScrollBar:          float32(10),
2✔
115
                        theme.SizeNameScrollBarSmall:     float32(2),
2✔
116
                        theme.SizeNameSeparatorThickness: float32(1),
2✔
117
                        theme.SizeNameText:               float32(18),
2✔
118
                        theme.SizeNameHeadingText:        float32(30.6),
2✔
119
                        theme.SizeNameSubHeadingText:     float32(24),
2✔
120
                        theme.SizeNameCaptionText:        float32(15),
2✔
121
                        theme.SizeNameInputBorder:        float32(5),
2✔
122
                        theme.SizeNameInputRadius:        float32(2),
2✔
123
                        theme.SizeNameSelectionRadius:    float32(6),
2✔
124
                        theme.SizeNameScrollBarRadius:    float32(2),
2✔
125
                },
2✔
126
        }
2✔
127
}
128

129
// Theme returns a test theme useful for image based tests.
130
func Theme() fyne.Theme {
37✔
131
        if defaultTheme == nil {
38✔
132
                defaultTheme = &configurableTheme{
1✔
133
                        colors: map[fyne.ThemeColorName]color.Color{
1✔
134
                                theme.ColorNameBackground:          color.NRGBA{R: 0x44, G: 0x44, B: 0x44, A: 0xff},
1✔
135
                                theme.ColorNameButton:              color.NRGBA{R: 0x33, G: 0x33, B: 0x33, A: 0xff},
1✔
136
                                theme.ColorNameDisabled:            color.NRGBA{R: 0x88, G: 0x88, B: 0x88, A: 0xff},
1✔
137
                                theme.ColorNameDisabledButton:      color.NRGBA{R: 0x22, G: 0x22, B: 0x22, A: 0xff},
1✔
138
                                theme.ColorNameError:               color.NRGBA{R: 0xf4, G: 0x43, B: 0x36, A: 0xff},
1✔
139
                                theme.ColorNameFocus:               color.NRGBA{R: 0x78, G: 0x3a, B: 0x3a, A: 0xff},
1✔
140
                                theme.ColorNameForeground:          color.NRGBA{R: 0xff, G: 0xff, B: 0xff, A: 0xff},
1✔
141
                                theme.ColorNameForegroundOnError:   color.NRGBA{R: 0x08, G: 0x0a, B: 0x0f, A: 0xff},
1✔
142
                                theme.ColorNameForegroundOnPrimary: color.NRGBA{R: 0x08, G: 0x0c, B: 0x0f, A: 0xff},
1✔
143
                                theme.ColorNameForegroundOnSuccess: color.NRGBA{R: 0x0a, G: 0x0c, B: 0x0f, A: 0xff},
1✔
144
                                theme.ColorNameForegroundOnWarning: color.NRGBA{R: 0x08, G: 0x0c, B: 0x0a, A: 0xff},
1✔
145
                                theme.ColorNameHeaderBackground:    color.NRGBA{R: 0x25, G: 0x25, B: 0x25, A: 0xff},
1✔
146
                                theme.ColorNameHover:               color.NRGBA{R: 0x88, G: 0xff, B: 0xff, A: 0x22},
1✔
147
                                theme.ColorNameHyperlink:           color.NRGBA{R: 0xff, G: 0xcc, B: 0x80, A: 0xff},
1✔
148
                                theme.ColorNameInputBackground:     color.NRGBA{R: 0x66, G: 0x66, B: 0x66, A: 0xff},
1✔
149
                                theme.ColorNameInputBorder:         color.NRGBA{R: 0x86, G: 0x86, B: 0x86, A: 0xff},
1✔
150
                                theme.ColorNameMenuBackground:      color.NRGBA{R: 0x56, G: 0x56, B: 0x56, A: 0xff},
1✔
151
                                theme.ColorNameOverlayBackground:   color.NRGBA{R: 0x28, G: 0x28, B: 0x28, A: 0xff},
1✔
152
                                theme.ColorNamePlaceHolder:         color.NRGBA{R: 0xaa, G: 0xaa, B: 0xaa, A: 0xff},
1✔
153
                                theme.ColorNamePressed:             color.NRGBA{R: 0x00, G: 0x00, B: 0x00, A: 0x33},
1✔
154
                                theme.ColorNamePrimary:             color.NRGBA{R: 0xff, G: 0xc0, B: 0x80, A: 0xff},
1✔
155
                                theme.ColorNameScrollBar:           color.NRGBA{R: 0x00, G: 0x00, B: 0x00, A: 0xaa},
1✔
156
                                theme.ColorNameScrollBarBackground: color.NRGBA{R: 0x67, G: 0x66, B: 0x66, A: 0xff},
1✔
157
                                theme.ColorNameSelection:           color.NRGBA{R: 0x78, G: 0x3a, B: 0x3a, A: 0x99},
1✔
158
                                theme.ColorNameSeparator:           color.NRGBA{R: 0x90, G: 0x90, B: 0x90, A: 0xff},
1✔
159
                                theme.ColorNameShadow:              color.NRGBA{R: 0x00, G: 0x00, B: 0x00, A: 0x88},
1✔
160
                                theme.ColorNameSuccess:             color.NRGBA{R: 0x00, G: 0x99, B: 0x00, A: 0xff},
1✔
161
                                theme.ColorNameWarning:             color.NRGBA{R: 0xee, G: 0xee, B: 0x00, A: 0xff},
1✔
162
                        },
1✔
163
                        fonts: map[fyne.TextStyle]fyne.Resource{
1✔
164
                                {}:                         theme.DefaultTextFont(),
1✔
165
                                {Bold: true}:               theme.DefaultTextBoldFont(),
1✔
166
                                {Bold: true, Italic: true}: theme.DefaultTextBoldItalicFont(),
1✔
167
                                {Italic: true}:             theme.DefaultTextItalicFont(),
1✔
168
                                {Monospace: true}:          theme.DefaultTextMonospaceFont(),
1✔
169
                                {Symbol: true}:             theme.DefaultSymbolFont(),
1✔
170
                        },
1✔
171
                        name: "Default Test Theme",
1✔
172
                        sizes: map[fyne.ThemeSizeName]float32{
1✔
173
                                theme.SizeNameInlineIcon:           float32(20),
1✔
174
                                theme.SizeNameInnerPadding:         float32(8),
1✔
175
                                theme.SizeNameLineSpacing:          float32(4),
1✔
176
                                theme.SizeNamePadding:              float32(4),
1✔
177
                                theme.SizeNameScrollBar:            float32(16),
1✔
178
                                theme.SizeNameScrollBarSmall:       float32(3),
1✔
179
                                theme.SizeNameSeparatorThickness:   float32(1),
1✔
180
                                theme.SizeNameText:                 float32(14),
1✔
181
                                theme.SizeNameHeadingText:          float32(23.8),
1✔
182
                                theme.SizeNameSubHeadingText:       float32(18),
1✔
183
                                theme.SizeNameCaptionText:          float32(11),
1✔
184
                                theme.SizeNameInputBorder:          float32(2),
1✔
185
                                theme.SizeNameInputRadius:          float32(4),
1✔
186
                                theme.SizeNameSelectionRadius:      float32(4),
1✔
187
                                theme.SizeNameScrollBarRadius:      float32(3),
1✔
188
                                theme.SizeNameWindowTitleBarHeight: float32(20),
1✔
189
                                theme.SizeNameWindowButtonHeight:   float32(10),
1✔
190
                                theme.SizeNameWindowButtonIcon:     float32(8),
1✔
191
                                theme.SizeNameWindowButtonRadius:   float32(5),
1✔
192
                        },
1✔
193
                }
1✔
194
        }
1✔
195
        return defaultTheme
37✔
196
}
197

198
type configurableTheme struct {
199
        colors map[fyne.ThemeColorName]color.Color
200
        fonts  map[fyne.TextStyle]fyne.Resource
201
        name   string
202
        sizes  map[fyne.ThemeSizeName]float32
203
}
204

205
var _ fyne.Theme = (*configurableTheme)(nil)
206

207
func (t *configurableTheme) Color(n fyne.ThemeColorName, _ fyne.ThemeVariant) color.Color {
3,331✔
208
        if t.colors[n] == nil {
3,331✔
209
                fyne.LogError(fmt.Sprintf("color %s not defined in theme %s", n, t.name), nil)
×
210
        }
×
211

212
        return t.colors[n]
3,331✔
213
}
214

215
func (t *configurableTheme) Font(style fyne.TextStyle) fyne.Resource {
6✔
216
        if t.fonts[style] == nil {
6✔
217
                fyne.LogError(fmt.Sprintf("font for style %#v not defined in theme %s", style, t.name), nil)
×
218
        }
×
219

220
        return t.fonts[style]
6✔
221
}
222

223
func (t *configurableTheme) Icon(n fyne.ThemeIconName) fyne.Resource {
1,203✔
224
        return theme.DefaultTheme().Icon(n)
1,203✔
225
}
1,203✔
226

227
func (t *configurableTheme) Size(s fyne.ThemeSizeName) float32 {
137✔
228
        if _, ok := t.sizes[s]; !ok {
137✔
229
                fyne.LogError(fmt.Sprintf("size %s not defined in theme %s", s, t.name), nil)
×
230
                return 0
×
231
        }
×
232

233
        return t.sizes[s]
137✔
234
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc