-
Notifications
You must be signed in to change notification settings - Fork 1
/
mono.go
56 lines (51 loc) · 1.39 KB
/
mono.go
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
package mono
// The mono theme is a plain default style for monochrome displays.
import (
"github.com/aykevl/tinygl"
"github.com/aykevl/tinygl/style"
"tinygo.org/x/drivers/pixel"
font "tinygo.org/x/tinygl-font"
"tinygo.org/x/tinygl-font/roboto"
)
type Theme[T pixel.Color] struct {
style.Theme[T]
}
// New returns a new Mono theme with the given properties.
//
// The default style is black text on a white background.
func New[T pixel.Color](scale style.Scale, screen *tinygl.Screen[T]) *Theme[T] {
// Pick a font that is suitable for the given scale.
// We can't just pick any size, so we have to use some heuristics.
percent := scale.Percent()
var font font.Font
switch {
case percent <= 100:
font = roboto.Regular16
case percent <= 125:
font = roboto.Regular20
case percent <= 150:
font = roboto.Regular24
case percent <= 175:
font = roboto.Regular28
case percent <= 200:
font = roboto.Regular32
case percent <= 225:
font = roboto.Regular36
case percent <= 250:
font = roboto.Regular40
case percent <= 275:
font = roboto.Regular44
default: // 300% and larger
font = roboto.Regular48
}
return &Theme[T]{
Theme: style.Theme[T]{
Screen: screen,
Font: font,
Foreground: pixel.NewColor[T](255, 255, 255), // black
Background: pixel.NewColor[T](0, 0, 0), // white
Tint: pixel.NewColor[T](0, 0, 0), // white
Scale: scale,
},
}
}