Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
SafeArea.cs
1using System;
2using Microsoft.Maui.Controls;
5
6namespace NeuroAccessMaui.UI
7{
8 public enum SafeAreaMode
9 {
10 Default,
11 Ignore,
12 Custom,
13 Top,
14 Bottom,
15 TopAndBottom,
16 Right,
17 Left,
18 RightAndLeft,
19 All
20 }
21
22 public static class SafeArea
23 {
24 public static readonly BindableProperty ModeProperty = BindableProperty.CreateAttached(
25 "Mode",
26 typeof(SafeAreaMode),
27 typeof(SafeArea),
28 SafeAreaMode.Default);
29
30 public static readonly BindableProperty CustomPaddingProperty = BindableProperty.CreateAttached(
31 "CustomPadding",
32 typeof(Thickness),
33 typeof(SafeArea),
34 new Thickness(0));
35
36 public static SafeAreaMode GetMode(BindableObject view)
37 {
38 ArgumentNullException.ThrowIfNull(view);
39 return (SafeAreaMode)view.GetValue(ModeProperty);
40 }
41
42 public static void SetMode(BindableObject view, SafeAreaMode value)
43 {
44 ArgumentNullException.ThrowIfNull(view);
45 view.SetValue(ModeProperty, value);
46 }
47
48 public static Thickness GetCustomPadding(BindableObject view)
49 {
50 ArgumentNullException.ThrowIfNull(view);
51 return (Thickness)view.GetValue(CustomPaddingProperty);
52 }
53
54 public static void SetCustomPadding(BindableObject view, Thickness value)
55 {
56 ArgumentNullException.ThrowIfNull(view);
57 view.SetValue(CustomPaddingProperty, value);
58 }
59
60 public static Thickness ResolveInsetsFor(BindableObject screen)
61 {
62 ArgumentNullException.ThrowIfNull(screen);
63
64 SafeAreaMode Mode = GetMode(screen);
65
66 if (Mode == SafeAreaMode.Ignore)
67 return new Thickness(0);
68
69 if (Mode == SafeAreaMode.Custom)
70 return GetCustomPadding(screen);
71
72 Thickness Insets = ServiceRef.PlatformSpecific.GetInsets();
73
74 return Mode switch
75 {
76 SafeAreaMode.Top => new Thickness(0, Insets.Top, 0, 0),
77 SafeAreaMode.Bottom => new Thickness(0, 0, 0, Insets.Bottom),
78 SafeAreaMode.TopAndBottom => new Thickness(0, Insets.Top, 0, Insets.Bottom),
79 SafeAreaMode.Right => new Thickness(0, 0, Insets.Right, 0),
80 SafeAreaMode.Left => new Thickness(Insets.Left, 0, 0, 0),
81 SafeAreaMode.RightAndLeft => new Thickness(Insets.Left, 0, Insets.Right, 0),
82 SafeAreaMode.All => Insets,
83 _ => Insets
84 };
85 }
86
87 public static Thickness ResolveInsetsForMode(SafeAreaMode mode)
88 {
89
90 if (mode == SafeAreaMode.Ignore)
91 return new Thickness(0);
92
93 if (mode == SafeAreaMode.Custom)
94 return new Thickness(0);
95
96 Thickness Insets = ServiceRef.PlatformSpecific.GetInsets();
97
98 return mode switch
99 {
100 SafeAreaMode.Top => new Thickness(0, Insets.Top, 0, 0),
101 SafeAreaMode.Bottom => new Thickness(0, 0, 0, Insets.Bottom),
102 SafeAreaMode.TopAndBottom => new Thickness(0, Insets.Top, 0, Insets.Bottom),
103 SafeAreaMode.Right => new Thickness(0, 0, Insets.Right, 0),
104 SafeAreaMode.Left => new Thickness(Insets.Left, 0, 0, 0),
105 SafeAreaMode.RightAndLeft => new Thickness(Insets.Left, 0, Insets.Right, 0),
106 SafeAreaMode.All => Insets,
107 _ => Insets
108 };
109 }
110 }
111}
Base class that references services in the app.
Definition: ServiceRef.cs:43
static IPlatformSpecific PlatformSpecific
Localization service
Definition: ServiceRef.cs:383
Thickness GetInsets()
Gets the safe area insets for the device (top, bottom, left, right).
Definition: ImplTypes.g.cs:58