-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththeme.go
More file actions
143 lines (126 loc) · 4 KB
/
Copy paththeme.go
File metadata and controls
143 lines (126 loc) · 4 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package main
import (
"image/color"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/theme"
)
// Color constants for graphs
var (
GreenLight = color.RGBA{R: 26, G: 155, B: 12, A: 255} // Light theme green
YellowLight = color.RGBA{R: 190, G: 161, B: 14, A: 255} // Light theme yellow
RedLight = color.RGBA{R: 186, G: 14, B: 23, A: 255} // Light theme red
GreenDark = color.RGBA{R: 21, G: 222, B: 0, A: 255} // Dark theme green
YellowDark = color.RGBA{R: 255, G: 214, B: 0, A: 255} // Dark theme yellow
RedDark = color.RGBA{R: 252, G: 0, B: 13, A: 255} // Dark theme red
)
// Color constants for the Memory tab's gauge, breakdown bars, and history
// chart. These identify a data series (memory, cached, buffers, swap) rather
// than a utilization status, so unlike the green/yellow/red set above they
// don't change meaning based on percentage.
var (
BlueLight = color.RGBA{R: 43, G: 92, B: 191, A: 255} // Used/Memory series (light)
PurpleLight = color.RGBA{R: 110, G: 76, B: 175, A: 255} // Cached series (light)
TealLight = color.RGBA{R: 42, G: 101, B: 115, A: 255} // Buffers series (light)
GrayLight = color.RGBA{R: 150, G: 156, B: 166, A: 255} // Free/track (light)
BlueDark = color.RGBA{R: 91, G: 142, B: 244, A: 255} // Used/Memory series (dark)
PurpleDark = color.RGBA{R: 138, G: 99, B: 209, A: 255} // Cached series (dark)
TealDark = color.RGBA{R: 61, G: 122, B: 140, A: 255} // Buffers series (dark)
GrayDark = color.RGBA{R: 58, G: 63, B: 71, A: 255} // Free/track (dark)
)
// GetSeriesColor returns the fixed identity color for a named data series,
// independent of utilization status (see GetGraphLineColor for that).
func GetSeriesColor(series string) color.RGBA {
isDark := isDarkTheme()
switch series {
case "blue":
if isDark {
return BlueDark
}
return BlueLight
case "purple":
if isDark {
return PurpleDark
}
return PurpleLight
case "teal":
if isDark {
return TealDark
}
return TealLight
case "gray":
if isDark {
return GrayDark
}
return GrayLight
case "yellow":
if isDark {
return YellowDark
}
return YellowLight
}
if isDark {
return GrayDark
}
return GrayLight
}
// isDarkTheme checks if the current theme variant is dark. It reads the
// resolved variant from Settings (which accounts for "auto"/OS-detected
// preference) rather than comparing theme instances — CustomTheme is always
// the app's active theme.Theme(), so a direct comparison against
// theme.LightTheme() never matches and previously made this always report
// dark, regardless of the user's actual selection.
func isDarkTheme() bool {
return fyne.CurrentApp().Settings().ThemeVariant() == theme.VariantDark
}
// UtilizationStatus classifies a utilization percentage into a status band.
// This is the single source of truth for the green/yellow/red thresholds
// used by tile borders, status dots, bars, and graph line colors.
func UtilizationStatus(percent float64) string {
switch {
case percent >= 85:
return "red"
case percent >= 60:
return "yellow"
default:
return "green"
}
}
// severityRank orders status bands from least to most severe for comparison.
var severityRank = map[string]int{"green": 0, "yellow": 1, "red": 2}
// moreSevereStatus returns whichever of two status bands is more severe.
func moreSevereStatus(a, b string) string {
if severityRank[b] > severityRank[a] {
return b
}
return a
}
// GetGraphLineColor returns the appropriate color based on utilization status and theme
func GetGraphLineColor(status string) color.RGBA {
isDark := isDarkTheme()
switch status {
case "green":
if isDark {
return GreenDark
}
return GreenLight
case "yellow":
if isDark {
return YellowDark
}
return YellowLight
case "red":
if isDark {
return RedDark
}
return RedLight
}
// Default to green
if isDark {
return GreenDark
}
return GreenLight
}
// ApplyTheme applies the specified theme variant to the application
func ApplyTheme(app fyne.App, themeVariant fyne.ThemeVariant) {
app.Settings().SetTheme(&CustomTheme{variant: themeVariant})
}