-
-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathmacos.go
More file actions
196 lines (182 loc) · 7.28 KB
/
Copy pathmacos.go
File metadata and controls
196 lines (182 loc) · 7.28 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
// SPDX-License-Identifier: Apache-2.0
// Package theme provides a macOS-inspired Fyne theme for the SBOM Utility GUI.
// It mirrors macOS Ventura/Sonoma light-mode aesthetics:
// - System background #F5F5F5 (window chrome grey)
// - Content background #FFFFFF (white panels)
// - Sidebar/header #EBEBEB (sidebar grey)
// - Accent blue #007AFF (macOS system blue)
// - Primary text #1D1D1F
// - Secondary text #6E6E73
// - Border/separator #D2D2D7
// - Input background #FFFFFF with a subtle border
// - Font sizes matching macOS HIG (body 13 pt, caption 11 pt, heading 17 pt)
package theme
import (
"image/color"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/theme"
)
// MacOSTheme is a Fyne theme that approximates macOS Ventura/Sonoma light mode.
type MacOSTheme struct{}
// Ensure MacOSTheme satisfies fyne.Theme at compile time.
var _ fyne.Theme = (*MacOSTheme)(nil)
// ── colors ──────────────────────────────────────────────────────────────────
// macOS system palette (light mode).
var (
colorBackground = color.NRGBA{R: 0xF5, G: 0xF5, B: 0xF5, A: 0xFF} // window chrome
colorContent = color.NRGBA{R: 0xFF, G: 0xFF, B: 0xFF, A: 0xFF} // white panels
colorSidebar = color.NRGBA{R: 0xEB, G: 0xEB, B: 0xEB, A: 0xFF} // sidebar / header rows
colorAccentBlue = color.NRGBA{R: 0x00, G: 0x7A, B: 0xFF, A: 0xFF} // macOS system blue
colorAccentBlueDim = color.NRGBA{R: 0x00, G: 0x7A, B: 0xFF, A: 0x33} // selection / focus ring
colorForeground = color.NRGBA{R: 0x1D, G: 0x1D, B: 0x1F, A: 0xFF} // primary text
colorSecondary = color.NRGBA{R: 0x6E, G: 0x6E, B: 0x73, A: 0xFF} // secondary text / placeholder
colorBorder = color.NRGBA{R: 0xD2, G: 0xD2, B: 0xD7, A: 0xFF} // separator / input border
colorError = color.NRGBA{R: 0xFF, G: 0x3B, B: 0x30, A: 0xFF} // macOS red
colorWarning = color.NRGBA{R: 0xFF, G: 0x9F, B: 0x0A, A: 0xFF} // macOS amber
colorSuccess = color.NRGBA{R: 0x30, G: 0xD1, B: 0x58, A: 0xFF} // macOS green
colorHover = color.NRGBA{R: 0x00, G: 0x7A, B: 0xFF, A: 0x14} // very light blue tint
colorPressed = color.NRGBA{R: 0x00, G: 0x7A, B: 0xFF, A: 0x22} // slightly stronger on press
colorScrollBar = color.NRGBA{R: 0xC0, G: 0xC0, B: 0xC5, A: 0xFF}
colorScrollBarBg = color.NRGBA{R: 0xF0, G: 0xF0, B: 0xF0, A: 0xFF}
colorShadow = color.NRGBA{R: 0x00, G: 0x00, B: 0x00, A: 0x26} // 15 % black shadow
colorOverlay = color.NRGBA{R: 0xFF, G: 0xFF, B: 0xFF, A: 0xFF} // dialogs / popovers
colorDisabledBtn = color.NRGBA{R: 0xE0, G: 0xE0, B: 0xE5, A: 0xFF}
colorDisabledText = color.NRGBA{R: 0xC0, G: 0xC0, B: 0xC5, A: 0xFF}
colorHyperlinkBlue = color.NRGBA{R: 0x00, G: 0x6B, B: 0xD6, A: 0xFF}
)
// Color implements fyne.Theme.
func (m *MacOSTheme) Color(name fyne.ThemeColorName, _ fyne.ThemeVariant) color.Color {
switch name {
case theme.ColorNameBackground:
return colorBackground
case theme.ColorNameButton:
return colorContent
case theme.ColorNameDisabledButton:
return colorDisabledBtn
case theme.ColorNameDisabled:
return colorDisabledText
case theme.ColorNameError:
return colorError
case theme.ColorNameFocus:
return colorAccentBlue
case theme.ColorNameForeground:
return colorForeground
case theme.ColorNameForegroundOnError:
return colorContent
case theme.ColorNameForegroundOnPrimary:
return colorContent
case theme.ColorNameForegroundOnSuccess:
return colorContent
case theme.ColorNameForegroundOnWarning:
return colorContent
case theme.ColorNameHeaderBackground:
return colorSidebar
case theme.ColorNameHover:
return colorHover
case theme.ColorNameHyperlink:
return colorHyperlinkBlue
case theme.ColorNameInputBackground:
return colorContent
case theme.ColorNameInputBorder:
return colorBorder
case theme.ColorNameMenuBackground:
return colorContent
case theme.ColorNameOverlayBackground:
return colorOverlay
case theme.ColorNamePlaceHolder:
return colorSecondary
case theme.ColorNamePressed:
return colorPressed
case theme.ColorNamePrimary:
return colorAccentBlue
case theme.ColorNameScrollBar:
return colorScrollBar
case theme.ColorNameScrollBarBackground:
return colorScrollBarBg
case theme.ColorNameSelection:
return colorAccentBlueDim
case theme.ColorNameSeparator:
return colorBorder
case theme.ColorNameShadow:
return colorShadow
case theme.ColorNameSuccess:
return colorSuccess
case theme.ColorNameWarning:
return colorWarning
default:
// Fall back to Fyne's built-in light theme for anything not listed above.
return theme.LightTheme().Color(name, theme.VariantLight)
}
}
// ── fonts ─────────────────────────────────────────────────────────────────────
// Font implements fyne.Theme.
// We use Fyne's bundled fonts because shipping the full San Francisco font is
// not possible without a license. The bundled fonts are clean sans-serif faces
// that are visually close to SF Pro at the sizes we configure below.
func (m *MacOSTheme) Font(style fyne.TextStyle) fyne.Resource {
switch {
case style.Monospace:
return theme.DefaultTextMonospaceFont()
case style.Bold && style.Italic:
return theme.DefaultTextBoldItalicFont()
case style.Bold:
return theme.DefaultTextBoldFont()
case style.Italic:
return theme.DefaultTextItalicFont()
default:
return theme.DefaultTextFont()
}
}
// ── icons ─────────────────────────────────────────────────────────────────────
// Icon implements fyne.Theme. We keep Fyne's built-in icons.
func (m *MacOSTheme) Icon(name fyne.ThemeIconName) fyne.Resource {
return theme.DefaultTheme().Icon(name)
}
// ── sizes ─────────────────────────────────────────────────────────────────────
// Size implements fyne.Theme using macOS HIG-inspired metrics.
//
// macOS HIG reference sizes (1 pt ≈ 1 dp on a non-Retina display):
//
// Body text 13 pt
// Caption 11 pt
// Heading 17 pt
// Sub-heading 15 pt
// Control height ~22 pt → padding 4 pt top/bottom
// Input border 1 pt
// Corner radius 5 pt (text fields), 6 pt (controls)
func (m *MacOSTheme) Size(name fyne.ThemeSizeName) float32 {
switch name {
case theme.SizeNameText:
return 13
case theme.SizeNameCaptionText:
return 11
case theme.SizeNameHeadingText:
return 17
case theme.SizeNameSubHeadingText:
return 15
case theme.SizeNamePadding:
return 6
case theme.SizeNameInnerPadding:
return 4
case theme.SizeNameLineSpacing:
return 4
case theme.SizeNameInlineIcon:
return 20
case theme.SizeNameScrollBar:
return 8
case theme.SizeNameScrollBarSmall:
return 3
case theme.SizeNameScrollBarRadius:
return 4
case theme.SizeNameSeparatorThickness:
return 1
case theme.SizeNameInputBorder:
return 1
case theme.SizeNameInputRadius:
return 5
case theme.SizeNameSelectionRadius:
return 3
default:
return theme.DefaultTheme().Size(name)
}
}