Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
AppStyles.cs
1using System.Text;
3using Waher.Events;
4
5namespace NeuroAccessMaui.UI
6{
10 public static class AppStyles
11 {
12 private static readonly SortedDictionary<string, bool> missingStyles = [];
13 private static Timer? timer = null;
14
15 private static ControlTemplate? radioButtonTemplate;
16 private static Thickness? smallBottomMargins;
17 private static Thickness? smallTopMargins;
18 private static Thickness? smallLeftMargins;
19 private static Thickness? smallRightMargins;
20 private static Style? sectionTitleLabelStyle;
21 private static Style? keyLabel;
22 private static Style? valueLabel;
23 private static Style? formattedValueLabel;
24 private static Style? clickableValueLabel;
25 private static Style? infoLabelStyle;
26 private static Style? filledTextButton;
27 private static Style? frameSet;
28 private static Style? frameSubSet;
29 private static Style? clickableFrameSubSet;
30 private static Style? regularCompositeEntry;
31 private static Style? regularCompositeEntryBorder;
32 private static Style? unicodeCharacterButton;
33 private static Style? imageOnlyButton;
34 private static Style? transparentImageButton;
35 private static Style? sendFrame;
36 private static Style? receiveFrame;
37
38 static AppStyles()
39 {
40 Log.Terminating += Log_Terminating;
41 }
42
43 private static void Log_Terminating(object? sender, EventArgs e)
44 {
45 timer?.Dispose();
46 timer = null;
47 }
48
55 public static T? TryGetResource<T>(string Name)
56 {
57 if ((Application.Current?.Resources.TryGetValue(Name, out object Value) ?? false) && Value is T TypedValue)
58 return TypedValue;
59 else
60 {
61 lock (missingStyles)
62 {
63 timer?.Dispose();
64 timer = null;
65
66 missingStyles[Name] = true;
67
68 timer = new Timer(LogAlert, null, 1000, Timeout.Infinite);
69 }
70
71 return default;
72 }
73 }
74
75 private static void LogAlert(object? _)
76 {
77 StringBuilder sb = new();
78
79 sb.AppendLine("Missing styles:");
80 sb.AppendLine();
81
82 lock (missingStyles)
83 {
84 foreach (string Key in missingStyles.Keys)
85 {
86 sb.Append("* ");
87 sb.AppendLine(Key);
88 }
89
90 missingStyles.Clear();
91 }
92
93 ServiceRef.LogService.LogAlert(sb.ToString());
94 }
95
99 public static ControlTemplate RadioButtonTemplate
100 {
101 get
102 {
103 radioButtonTemplate ??= TryGetResource<ControlTemplate>("RadioButtonTemplate");
104 return radioButtonTemplate!;
105 }
106 }
107
111 public static Thickness SmallBottomMargins
112 {
113 get
114 {
115 smallBottomMargins ??= TryGetResource<Thickness>("SmallBottomMargins");
116 return smallBottomMargins.Value;
117 }
118 }
119
123 public static Thickness SmallTopMargins
124 {
125 get
126 {
127 smallTopMargins ??= TryGetResource<Thickness>("SmallTopMargins");
128 return smallTopMargins.Value;
129 }
130 }
131
135 public static Thickness SmallLeftMargins
136 {
137 get
138 {
139 smallLeftMargins ??= TryGetResource<Thickness>("SmallLeftMargins");
140 return smallLeftMargins.Value;
141 }
142 }
143
147 public static Thickness SmallRightMargins
148 {
149 get
150 {
151 smallRightMargins ??= TryGetResource<Thickness>("SmallRightMargins");
152 return smallRightMargins.Value;
153 }
154 }
155
159 public static Style SectionTitleLabel
160 {
161 get
162 {
163 sectionTitleLabelStyle ??= TryGetResource<Style>("SectionTitleLabel");
164 return sectionTitleLabelStyle!;
165 }
166 }
167
171 public static Style KeyLabel
172 {
173 get
174 {
175 keyLabel ??= TryGetResource<Style>("KeyLabel");
176 return keyLabel!;
177 }
178 }
179
183 public static Style ValueLabel
184 {
185 get
186 {
187 valueLabel ??= TryGetResource<Style>("ValueLabel");
188 return valueLabel!;
189 }
190 }
191
195 public static Style FormattedValueLabel
196 {
197 get
198 {
199 formattedValueLabel ??= TryGetResource<Style>("FormattedValueLabel");
200 return formattedValueLabel!;
201 }
202 }
203
207 public static Style ClickableValueLabel
208 {
209 get
210 {
211 clickableValueLabel ??= TryGetResource<Style>("ClickableValueLabel");
212 return clickableValueLabel!;
213 }
214 }
215
219 public static Style InfoLabel
220 {
221 get
222 {
223 infoLabelStyle ??= TryGetResource<Style>("InfoLabel");
224 return infoLabelStyle!;
225 }
226 }
227
231 public static Style FilledTextButton
232 {
233 get
234 {
235 filledTextButton ??= TryGetResource<Style>("FilledTextButtonNoRoundedCorners"); // TODO: Remove NoRoundedCorners
236 return filledTextButton!;
237 }
238 }
239
243 public static Style FrameSet
244 {
245 get
246 {
247 frameSet ??= TryGetResource<Style>("FrameSet");
248 return frameSet!;
249 }
250 }
251
255 public static Style FrameSubSet
256 {
257 get
258 {
259 frameSubSet ??= TryGetResource<Style>("FrameSubSet");
260 return frameSubSet!;
261 }
262 }
263
267 public static Style ClickableFrameSubSet
268 {
269 get
270 {
271 clickableFrameSubSet ??= TryGetResource<Style>("ClickableFrameSubSet");
272 return clickableFrameSubSet!;
273 }
274 }
275
279 public static Style RegularCompositeEntry
280 {
281 get
282 {
283 regularCompositeEntry ??= TryGetResource<Style>("RegularCompositeEntryNoRoundedCorners"); // TODO: Remove NoRoundedCorners
284 return regularCompositeEntry!;
285 }
286 }
287
291 public static Style RegularCompositeEntryBorder
292 {
293 get
294 {
295 regularCompositeEntryBorder ??= TryGetResource<Style>("RegularCompositeEntryBorderNoRoundedCorners"); // TODO: Remove NoRoundedCorners
296 return regularCompositeEntryBorder!;
297 }
298 }
299
303 public static Style UnicodeCharacterButton
304 {
305 get
306 {
307 unicodeCharacterButton ??= TryGetResource<Style>("UnicodeCharacterButtonNoRoundedCorners"); // TODO: Remove NoRoundedCorners
308 return unicodeCharacterButton!;
309 }
310 }
311
315 public static Style ImageOnlyButton
316 {
317 get
318 {
319 imageOnlyButton ??= TryGetResource<Style>("ImageOnlyButton");
320 return imageOnlyButton!;
321 }
322 }
323
327 public static Style TransparentImageButton
328 {
329 get
330 {
331 transparentImageButton ??= TryGetResource<Style>("TransparentImageButton");
332 return transparentImageButton!;
333 }
334 }
335
339 public static Style SendFrame
340 {
341 get
342 {
343 sendFrame ??= TryGetResource<Style>("SendFrame");
344 return sendFrame!;
345 }
346 }
347
351 public static Style ReceiveFrame
352 {
353 get
354 {
355 receiveFrame ??= TryGetResource<Style>("ReceiveFrame");
356 return receiveFrame!;
357 }
358 }
359
360 }
361}
Base class that references services in the app.
Definition: ServiceRef.cs:31
static ILogService LogService
Log service.
Definition: ServiceRef.cs:91
Static class that gives access to app-specific styles
Definition: AppStyles.cs:11
static Thickness SmallRightMargins
Right-only small margins
Definition: AppStyles.cs:148
static Style RegularCompositeEntry
Style for borders in a regular composte entry control.
Definition: AppStyles.cs:280
static Style ImageOnlyButton
Style for buttons containing only an image.
Definition: AppStyles.cs:316
static ControlTemplate RadioButtonTemplate
Template for radio buttons
Definition: AppStyles.cs:100
static Style SendFrame
Style for send frames
Definition: AppStyles.cs:340
static Style FrameSubSet
Style for frame subsets.
Definition: AppStyles.cs:256
static Style SectionTitleLabel
Style of section title labels
Definition: AppStyles.cs:160
static Thickness SmallBottomMargins
Bottom-only small margins
Definition: AppStyles.cs:112
static Style ClickableValueLabel
Style of clickable value labels
Definition: AppStyles.cs:208
static Style ClickableFrameSubSet
Style for clickable frame subsets.
Definition: AppStyles.cs:268
static Style InfoLabel
Style of information labels
Definition: AppStyles.cs:220
static Style ReceiveFrame
Style for receive frames
Definition: AppStyles.cs:352
static Thickness SmallLeftMargins
Left-only small margins
Definition: AppStyles.cs:136
static Style FrameSet
Style for frame sets.
Definition: AppStyles.cs:244
static Style RegularCompositeEntryBorder
Style for borders in a regular composte entry control.
Definition: AppStyles.cs:292
static ? T TryGetResource< T >(string Name)
Tries to get an embedded resource.
Definition: AppStyles.cs:55
static Thickness SmallTopMargins
Top-only small margins
Definition: AppStyles.cs:124
static Style UnicodeCharacterButton
Style for buttons containing a single Unicode character.
Definition: AppStyles.cs:304
static Style KeyLabel
Style of key labels
Definition: AppStyles.cs:172
static Style ValueLabel
Style of value labels
Definition: AppStyles.cs:184
static Style FormattedValueLabel
Style of formatted value labels
Definition: AppStyles.cs:196
static Style TransparentImageButton
Style for transparent image buttons.
Definition: AppStyles.cs:328
static Style FilledTextButton
Style for filled text buttons.
Definition: AppStyles.cs:232