theme.go raw
1 package gel
2
3 import (
4 "os/exec"
5 "runtime"
6 "strconv"
7 "strings"
8
9 "github.com/p9c/gio/text"
10 "github.com/p9c/gio/unit"
11 "github.com/p9c/opts/binary"
12 "github.com/p9c/qu"
13 )
14
15 type Theme struct {
16 quit qu.C
17 shaper text.Shaper
18 collection Collection
19 TextSize unit.Value
20 *Colors
21 icons map[string]*Icon
22 scrollBarSize int
23 Dark *binary.Opt
24 iconCache IconCache
25 WidgetPool *Pool
26 }
27
28 // NewTheme creates a new theme to use for rendering a user interface
29 func NewTheme(dark *binary.Opt, fontCollection []text.FontFace, quit qu.C) (th *Theme) {
30 textSize := unit.Sp(16)
31 if runtime.GOOS == "linux" {
32 var e error
33 var b []byte
34 runner := exec.Command("gsettings", "get", "org.gnome.desktop.interface", "text-scaling-factor")
35 if b, e = runner.CombinedOutput(); D.Chk(e) {
36 }
37 var factor float64
38 numberString := strings.TrimSpace(string(b))
39 if factor, e = strconv.ParseFloat(numberString, 10); D.Chk(e) {
40 }
41 textSize = textSize.Scale(float32(factor))
42 // I.Ln(w.TextSize)
43 }
44 th = &Theme{
45 quit: quit,
46 shaper: text.NewCache(fontCollection),
47 collection: fontCollection,
48 TextSize: textSize,
49 Colors: newColors(),
50 scrollBarSize: 0,
51 iconCache: make(IconCache),
52 }
53 th.SetDarkTheme(dark.True())
54 return
55 }
56