This repository was archived by the owner on Jul 9, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCFStyleManager.bas
More file actions
233 lines (144 loc) · 5.54 KB
/
CFStyleManager.bas
File metadata and controls
233 lines (144 loc) · 5.54 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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
B4J=true
Group=Cuppy Framework\Cuppy\Cuppy Internals
ModulesStructureVersion=1
Type=StaticCode
Version=5.51
@EndOfDesignText@
'Style Manager for Cuppy Framework UI
Private Sub Process_Globals
Private fx As JFX
Private AvailableThemes As CFThemes
AvailableThemes.Initialize 'ignore
Public DefaultTheme As Map
' Public ActiveControls As List
' ActiveControls.Initialize 'ignore : need this , bad pratice maybe so would find a fix later
'
#Region Available Fonts
Public const FONT_BLACK As Font = SelectFont("Black", 12)
Public const FONT_BLACK_ITALIC As Font = SelectFont("BlackItalic", 12)
Public const FONT_BOLD As Font = SelectFont("Bold", 12)
Public const FONT_BOLD_ITALIC As Font = SelectFont("BoldItalic", 12)
Public const FONT_LIGHT As Font = SelectFont("Light", 12)
Public const FONT_LIGHT_ITALIC As Font = SelectFont("LightItalic", 12)
Public const FONT_REGULAR As Font = SelectFont("Regular", 12)
Public const FONT_ITALIC As Font = SelectFont("Italic", 12)
Public const FONT_MEDIUM As Font = SelectFont("Medium", 12)
Public const FONT_MEDIUM_ITALIC As Font = SelectFont("MediumItalic", 12)
Public const FONT_THIN As Font = SelectFont("Thin", 12)
Public const FONT_THIN_ITALIC As Font = SelectFont("ThinItalic", 12)
#End Region
#Region Available Themes
Public const THEME_BLUE As String = "Blue"
Public const THEME_TEAL As String = "Teal"
#If Full
'Remove from Library if Free version
Public const THEME_GRAY As String = "Gray"
Public const THEME_DARK As String = "Dark"
Public const THEME_PURPLE As String = "Purple"
Public const THEME_PINK As String = "Pink"
Public const THEME_AMBER As String = "Amber"
#End If
#End Region
'Default Theme
SelectTheme(THEME_BLUE) 'ignore
'Reference cuppy controls so it can be updated all when the style changes
'allow setting of animation time...
End Sub
'Return a list of available fonts for use
Private Sub FontTypes As Map
Dim FTypes As Map
FTypes.Initialize
FTypes.Put("Black","Roboto-Black.ttf")
FTypes.Put("BlackItalic","Roboto-BlackItalic.ttf")
FTypes.Put("Bold","Roboto-Bold.ttf")
FTypes.Put("BoldItalic","Roboto-BoldItalic.ttf")
FTypes.Put("Italic","Roboto-Italic.ttf")
FTypes.Put("Light","Roboto-Light.ttf")
FTypes.Put("LightItalic","Roboto-LightItalic.ttf")
FTypes.Put("Medium","Roboto-Medium.ttf")
FTypes.Put("MediumItalic","Roboto-MediumItalic.ttf")
FTypes.Put("Regular","Roboto-Regular.ttf")
FTypes.Put("Thin","Roboto-Thin.ttf")
FTypes.Put("ThinItalic","Roboto-ThinItalic.ttf")
Return FTypes
End Sub
'Returns an instance of a font that can be reused
Public Sub SelectFont(fontName As String, FontSize As Double ) As Font
Return fx.LoadFont(File.DirAssets , FontTypes.Get(fontName), FontSize)
End Sub
'Create a new font object from an existing font
Public Sub ScaleFont(FamilyName As String,Size As Double) As Font
Return fx.CreateFont(FamilyName, Size, False, False)
End Sub
'Create a new font object from an existing font
Public Sub ScaleFont2(FamilyName As String,Size As Double, Bold As Boolean, Italic As Boolean) As Font
Return fx.CreateFont(FamilyName , Size, Bold, Italic)
End Sub
'Changes the Default Theme used by Cuppy Framework
'For styling views and Components
'
'Note: The theme name is Case-Insensitive
Public Sub SelectTheme(Theme As String)
#If Free
'Advice developers to donate to have access to all themes
LogDebug($"To have access to all the inbuilt themes,
You need to donate! Donation link: ${CRLF}
${CFConfigs.DonationLink}"$)
#End if
Theme = CFStringUtility.ucfirst(Theme)
If AvailableThemes.ThemesList.ContainsKey(Theme) Then
DefaultTheme = AvailableThemes.ThemesList.Get(Theme)
Else
LogError("Could not find the selected theme(" & Theme & "). Please check the Theme name")
ExitApplication
End If
End Sub
#If Full
'Remove from Library if Free version
'Allows you to load your Theme from a file
'This returns a map of your theme
'which you can reuse to set theme in your program
'
'NOTE: themes file are checked to validate that
' required key values are present
Public Sub LoadThemeFile(Dir As String, FileName As String) As Map
Dim mapx As Map = File.ReadMap(Dir ,FileName)
Dim checklist As List
checklist.Initialize
checklist.Add("primary")
checklist.Add("primary_dark")
checklist.Add("primary_light")
checklist.Add("accent")
checklist.Add("primary_text")
checklist.Add("secondary_text")
checklist.Add("icons")
checklist.Add("divider")
For Each KeyX As String In checklist
'If one key is missing, stop loading of theme...
If Not(mapx.ContainsKey(KeyX)) Or CFStringUtility.isEmpty(mapx.Get(KeyX)) Then
Dim ErrorStr As StringBuilder
ErrorStr.Initialize
ErrorStr.Append("Could not load theme file (" & FileName & ") ")
ErrorStr.Append("because the theme key (" & KeyX & ") is missing ")
ErrorStr.Append("or its value is empty!")
LogError(ErrorStr.ToString)
ExitApplication
End If
Next
Return mapx
End Sub
'Export a theme to a file
Public Sub ExportTheme(theme As String , Dir As String, FileName As String)
theme = CFStringUtility.ucfirst(theme)
If AvailableThemes.ThemesList.ContainsKey(theme) Then
File.WriteMap(Dir, FileName, AvailableThemes.ThemesList.Get(theme))
Else
LogError("Could not export theme(" & theme & "). Please check the Theme name!")
ExitApplication
End If
End Sub
'Export current theme to a file
Public Sub ExportCurrentTheme(Dir As String, FileName As String)
File.WriteMap(Dir, FileName, DefaultTheme)
End Sub
#End if