-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSampleToastNotification.cs
More file actions
241 lines (208 loc) · 7.33 KB
/
SampleToastNotification.cs
File metadata and controls
241 lines (208 loc) · 7.33 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
233
234
235
236
237
238
239
240
241
using FishUI;
using FishUI.Controls;
using System;
using System.Numerics;
namespace FishUIDemos
{
/// <summary>
/// Demonstrates the ToastNotification system with different message types
/// and customization options.
/// </summary>
public class SampleToastNotification : ISample
{
FishUI.FishUI FUI;
ToastNotification _toastSystem;
int _counter = 0;
public string Name => "Toast Notifications";
public TakeScreenshotFunc TakeScreenshot { get; set; }
public FishUI.FishUI CreateUI(FishUISettings UISettings, IFishUIGfx Gfx, IFishUIInput Input, IFishUIEvents Events)
{
FUI = new FishUI.FishUI(UISettings, Gfx, Input, Events);
FUI.Init();
FishUITheme theme = UISettings.LoadTheme(ThemePreferences.LoadThemePath(), applyImmediately: true);
return FUI;
}
public void Init()
{
// Add the toast notification system (should be added once, rendered on top)
_toastSystem = new ToastNotification();
_toastSystem.MaxToasts = 5;
_toastSystem.DefaultDuration = 4f;
FUI.AddControl(_toastSystem);
// === Title ===
Label titleLabel = new Label("Toast Notification Demo");
titleLabel.Position = new Vector2(20, 20);
titleLabel.Size = new Vector2(300, 30);
titleLabel.Alignment = Align.Left;
FUI.AddControl(titleLabel);
// Screenshot button
ImageRef iconCamera = FUI.Graphics.LoadImage("data/silk_icons/camera.png");
Button screenshotBtn = new Button();
screenshotBtn.Icon = iconCamera;
screenshotBtn.Position = new Vector2(330, 20);
screenshotBtn.Size = new Vector2(30, 30);
screenshotBtn.IsImageButton = true;
screenshotBtn.TooltipText = "Take a screenshot";
screenshotBtn.OnButtonPressed += (btn, mbtn, pos) => TakeScreenshot?.Invoke(Name);
FUI.AddControl(screenshotBtn);
// ============ Toast Type Buttons ============
Label typeLabel = new Label("Show Toast by Type:");
typeLabel.Position = new Vector2(20, 60);
typeLabel.Size = new Vector2(200, 20);
typeLabel.Alignment = Align.Left;
FUI.AddControl(typeLabel);
// Info button
Button infoBtn = new Button();
infoBtn.Text = "Info";
infoBtn.Position = new Vector2(20, 90);
infoBtn.Size = new Vector2(100, 32);
infoBtn.OnButtonPressed += (b, m, p) =>
{
_counter++;
_toastSystem.ShowInfo($"Information message #{_counter}");
};
FUI.AddControl(infoBtn);
// Success button
Button successBtn = new Button();
successBtn.Text = "Success";
successBtn.Position = new Vector2(130, 90);
successBtn.Size = new Vector2(100, 32);
successBtn.OnButtonPressed += (b, m, p) =>
{
_counter++;
_toastSystem.ShowSuccess($"Operation completed successfully! #{_counter}");
};
FUI.AddControl(successBtn);
// Warning button
Button warningBtn = new Button();
warningBtn.Text = "Warning";
warningBtn.Position = new Vector2(240, 90);
warningBtn.Size = new Vector2(100, 32);
warningBtn.OnButtonPressed += (b, m, p) =>
{
_counter++;
_toastSystem.ShowWarning($"Warning: Please check settings #{_counter}");
};
FUI.AddControl(warningBtn);
// Error button
Button errorBtn = new Button();
errorBtn.Text = "Error";
errorBtn.Position = new Vector2(350, 90);
errorBtn.Size = new Vector2(100, 32);
errorBtn.OnButtonPressed += (b, m, p) =>
{
_counter++;
_toastSystem.ShowError($"Error: Something went wrong! #{_counter}");
};
FUI.AddControl(errorBtn);
// ============ Toast with Title ============
Label titleToastLabel = new Label("Show Toast with Title:");
titleToastLabel.Position = new Vector2(20, 140);
titleToastLabel.Size = new Vector2(200, 20);
titleToastLabel.Alignment = Align.Left;
FUI.AddControl(titleToastLabel);
Button titledInfoBtn = new Button();
titledInfoBtn.Text = "Info + Title";
titledInfoBtn.Position = new Vector2(20, 170);
titledInfoBtn.Size = new Vector2(110, 32);
titledInfoBtn.OnButtonPressed += (b, m, p) =>
{
_toastSystem.Show("System Update", "A new version is available.", ToastType.Info);
};
FUI.AddControl(titledInfoBtn);
Button titledSuccessBtn = new Button();
titledSuccessBtn.Text = "Success + Title";
titledSuccessBtn.Position = new Vector2(140, 170);
titledSuccessBtn.Size = new Vector2(120, 32);
titledSuccessBtn.OnButtonPressed += (b, m, p) =>
{
_toastSystem.Show("File Saved", "Document saved successfully.", ToastType.Success);
};
FUI.AddControl(titledSuccessBtn);
Button titledErrorBtn = new Button();
titledErrorBtn.Text = "Error + Title";
titledErrorBtn.Position = new Vector2(270, 170);
titledErrorBtn.Size = new Vector2(110, 32);
titledErrorBtn.OnButtonPressed += (b, m, p) =>
{
_toastSystem.Show("Connection Failed", "Unable to reach server.", ToastType.Error);
};
FUI.AddControl(titledErrorBtn);
// ============ Custom Duration ============
Label durationLabel = new Label("Custom Duration:");
durationLabel.Position = new Vector2(20, 220);
durationLabel.Size = new Vector2(150, 20);
durationLabel.Alignment = Align.Left;
FUI.AddControl(durationLabel);
Button shortBtn = new Button();
shortBtn.Text = "1 Second";
shortBtn.Position = new Vector2(20, 250);
shortBtn.Size = new Vector2(100, 32);
shortBtn.OnButtonPressed += (b, m, p) =>
{
_toastSystem.Show("Quick notification!", ToastType.Info, 1f);
};
FUI.AddControl(shortBtn);
Button longBtn = new Button();
longBtn.Text = "10 Seconds";
longBtn.Position = new Vector2(130, 250);
longBtn.Size = new Vector2(100, 32);
longBtn.OnButtonPressed += (b, m, p) =>
{
_toastSystem.Show("This will stay for 10 seconds", ToastType.Warning, 10f);
};
FUI.AddControl(longBtn);
// ============ Flood Test ============
Label floodLabel = new Label("Stress Test:");
floodLabel.Position = new Vector2(20, 300);
floodLabel.Size = new Vector2(150, 20);
floodLabel.Alignment = Align.Left;
FUI.AddControl(floodLabel);
Button floodBtn = new Button();
floodBtn.Text = "Add 10 Toasts";
floodBtn.Position = new Vector2(20, 330);
floodBtn.Size = new Vector2(120, 32);
floodBtn.OnButtonPressed += (b, m, p) =>
{
for (int i = 0; i < 10; i++)
{
_counter++;
ToastType type = (ToastType)(i % 4);
_toastSystem.Show($"Toast message #{_counter}", type);
}
};
FUI.AddControl(floodBtn);
Button clearBtn = new Button();
clearBtn.Text = "Clear All";
clearBtn.Position = new Vector2(150, 330);
clearBtn.Size = new Vector2(100, 32);
clearBtn.OnButtonPressed += (b, m, p) =>
{
_toastSystem.ClearAll();
};
FUI.AddControl(clearBtn);
// ============ Active Count Display ============
Label activeLabel = new Label("Active toasts: 0");
activeLabel.Position = new Vector2(20, 380);
activeLabel.Size = new Vector2(200, 20);
activeLabel.Alignment = Align.Left;
activeLabel.ID = "activeCountLabel";
FUI.AddControl(activeLabel);
// ============ Info ============
Label infoLabel = new Label("Toast notifications appear in the top-right corner and auto-dismiss after timeout.");
infoLabel.Position = new Vector2(20, 420);
infoLabel.Size = new Vector2(500, 20);
infoLabel.Alignment = Align.Left;
FUI.AddControl(infoLabel);
}
public void Update(float dt)
{
// Update active count label
var label = FUI.FindControlByID<Label>("activeCountLabel");
if (label != null)
{
label.Text = $"Active toasts: {_toastSystem.ActiveCount}";
}
}
}
}