-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSampleTimePicker.cs
More file actions
183 lines (148 loc) · 5.5 KB
/
SampleTimePicker.cs
File metadata and controls
183 lines (148 loc) · 5.5 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
using FishUI;
using FishUI.Controls;
using System;
using System.Numerics;
namespace FishUIDemos
{
/// <summary>
/// Demonstrates the TimePicker control with various configurations.
/// </summary>
public class SampleTimePicker : ISample
{
FishUI.FishUI FUI;
Label _selectedTimeLabel;
TimePicker _mainPicker;
public string Name => "TimePicker";
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()
{
// === Title ===
Label titleLabel = new Label("TimePicker 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(GetType().Name);
FUI.AddControl(screenshotBtn);
float yPos = 60;
// === Basic 24-hour TimePicker ===
Label basicLabel = new Label("24-Hour Format:");
basicLabel.Position = new Vector2(20, yPos);
basicLabel.Size = new Vector2(120, 24);
basicLabel.Alignment = Align.Left;
FUI.AddControl(basicLabel);
_mainPicker = new TimePicker(14, 30, 0);
_mainPicker.Position = new Vector2(150, yPos);
_mainPicker.OnValueChanged += OnTimeChanged;
FUI.AddControl(_mainPicker);
yPos += 35;
// Selected time display
_selectedTimeLabel = new Label($"Selected: {_mainPicker.GetFormattedTime()}");
_selectedTimeLabel.Position = new Vector2(20, yPos);
_selectedTimeLabel.Size = new Vector2(300, 20);
_selectedTimeLabel.Alignment = Align.Left;
FUI.AddControl(_selectedTimeLabel);
yPos += 45;
// === 12-hour format (AM/PM) ===
Label ampmLabel = new Label("12-Hour (AM/PM):");
ampmLabel.Position = new Vector2(20, yPos);
ampmLabel.Size = new Vector2(120, 24);
ampmLabel.Alignment = Align.Left;
FUI.AddControl(ampmLabel);
TimePicker ampmPicker = new TimePicker(9, 30, 0);
ampmPicker.Position = new Vector2(150, yPos);
ampmPicker.Use24HourFormat = false;
ampmPicker.UpdateSize();
FUI.AddControl(ampmPicker);
yPos += 35;
// === With Seconds ===
Label secondsLabel = new Label("With Seconds:");
secondsLabel.Position = new Vector2(20, yPos);
secondsLabel.Size = new Vector2(120, 24);
secondsLabel.Alignment = Align.Left;
FUI.AddControl(secondsLabel);
TimePicker secondsPicker = new TimePicker(12, 45, 30);
secondsPicker.Position = new Vector2(150, yPos);
secondsPicker.ShowSeconds = true;
secondsPicker.UpdateSize();
FUI.AddControl(secondsPicker);
yPos += 35;
// === 12-hour with Seconds ===
Label fullLabel = new Label("12-Hour + Seconds:");
fullLabel.Position = new Vector2(20, yPos);
fullLabel.Size = new Vector2(130, 24);
fullLabel.Alignment = Align.Left;
FUI.AddControl(fullLabel);
TimePicker fullPicker = new TimePicker(23, 59, 59);
fullPicker.Position = new Vector2(155, yPos);
fullPicker.Use24HourFormat = false;
fullPicker.ShowSeconds = true;
fullPicker.UpdateSize();
FUI.AddControl(fullPicker);
yPos += 50;
// === Quick Set Buttons ===
Label presetLabel = new Label("Quick Set:");
presetLabel.Position = new Vector2(20, yPos);
presetLabel.Alignment = Align.Left;
FUI.AddControl(presetLabel);
yPos += 25;
Button nowBtn = new Button();
nowBtn.Text = "Now";
nowBtn.Position = new Vector2(20, yPos);
nowBtn.Size = new Vector2(60, 24);
nowBtn.OnButtonPressed += (btn, mbtn, pos) =>
{
var now = DateTime.Now;
_mainPicker.Value = new TimeSpan(now.Hour, now.Minute, now.Second);
};
FUI.AddControl(nowBtn);
Button noonBtn = new Button();
noonBtn.Text = "Noon";
noonBtn.Position = new Vector2(85, yPos);
noonBtn.Size = new Vector2(60, 24);
noonBtn.OnButtonPressed += (btn, mbtn, pos) => _mainPicker.Value = new TimeSpan(12, 0, 0);
FUI.AddControl(noonBtn);
Button midnightBtn = new Button();
midnightBtn.Text = "Midnight";
midnightBtn.Position = new Vector2(150, yPos);
midnightBtn.Size = new Vector2(70, 24);
midnightBtn.OnButtonPressed += (btn, mbtn, pos) => _mainPicker.Value = TimeSpan.Zero;
FUI.AddControl(midnightBtn);
Button endDayBtn = new Button();
endDayBtn.Text = "23:59";
endDayBtn.Position = new Vector2(225, yPos);
endDayBtn.Size = new Vector2(60, 24);
endDayBtn.OnButtonPressed += (btn, mbtn, pos) => _mainPicker.Value = new TimeSpan(23, 59, 59);
FUI.AddControl(endDayBtn);
yPos += 50;
// === Instructions ===
Label instructionsLabel = new Label("Tip: Use mouse wheel over spinners to adjust values");
instructionsLabel.Position = new Vector2(20, yPos);
instructionsLabel.Size = new Vector2(350, 20);
instructionsLabel.Alignment = Align.Left;
FUI.AddControl(instructionsLabel);
}
private void OnTimeChanged(TimePicker sender, TimeSpan value)
{
_selectedTimeLabel.Text = $"Selected: {sender.GetFormattedTime()} (TimeSpan: {value})";
}
public void Update(float dt)
{
}
}
}