-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSampleItemListbox.cs
More file actions
191 lines (157 loc) · 6.01 KB
/
SampleItemListbox.cs
File metadata and controls
191 lines (157 loc) · 6.01 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
using FishUI;
using FishUI.Controls;
using System;
using System.Numerics;
namespace FishUIDemos
{
/// <summary>
/// Demonstrates the ItemListbox control with custom widget items.
/// Shows text items, widget items (buttons, checkboxes, progress bars), and mixed content.
/// </summary>
public class SampleItemListbox : ISample
{
FishUI.FishUI FUI;
public string Name => "ItemListbox";
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("ItemListbox 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);
// === Description ===
Label descLabel = new Label("ItemListbox supports text items and custom widget controls as items.");
descLabel.Position = new Vector2(20, 55);
descLabel.Size = new Vector2(600, 20);
descLabel.Alignment = Align.Left;
FUI.AddControl(descLabel);
// === Text-Only ItemListbox ===
Label textListLabel = new Label("Text Items:");
textListLabel.Position = new Vector2(20, 90);
textListLabel.Size = new Vector2(150, 20);
textListLabel.Alignment = Align.Left;
FUI.AddControl(textListLabel);
ItemListbox textListbox = new ItemListbox();
textListbox.Position = new Vector2(20, 115);
textListbox.Size = new Vector2(180, 200);
textListbox.AlternatingRowColors = true;
// Add simple text items
textListbox.AddItem("First Item");
textListbox.AddItem("Second Item");
textListbox.AddItem("Third Item");
textListbox.AddItem("Fourth Item");
textListbox.AddItem("Fifth Item");
textListbox.AddItem("Sixth Item");
textListbox.AddItem("Seventh Item");
textListbox.AddItem("Eighth Item");
textListbox.OnItemSelected += (lb, idx, item) =>
{
Console.WriteLine($"Text list selected: {item.Text}");
};
FUI.AddControl(textListbox);
// === Widget ItemListbox ===
Label widgetListLabel = new Label("Widget Items:");
widgetListLabel.Position = new Vector2(220, 90);
widgetListLabel.Size = new Vector2(150, 20);
widgetListLabel.Alignment = Align.Left;
FUI.AddControl(widgetListLabel);
ItemListbox widgetListbox = new ItemListbox();
widgetListbox.Position = new Vector2(220, 115);
widgetListbox.Size = new Vector2(220, 200);
widgetListbox.ItemHeight = 30;
// Add button widget items
for (int i = 1; i <= 5; i++)
{
Button btn = new Button();
btn.Text = $"Action Button {i}";
btn.Size = new Vector2(180, 26);
int idx = i;
btn.OnButtonPressed += (b, mb, pos) => Console.WriteLine($"Button {idx} clicked!");
widgetListbox.AddItem(btn, $"button_{i}");
}
widgetListbox.OnItemSelected += (lb, idx, item) =>
{
Console.WriteLine($"Widget list selected index: {idx}, UserData: {item.UserData}");
};
FUI.AddControl(widgetListbox);
// === Mixed ItemListbox ===
Label mixedListLabel = new Label("Mixed Items:");
mixedListLabel.Position = new Vector2(460, 90);
mixedListLabel.Size = new Vector2(150, 20);
mixedListLabel.Alignment = Align.Left;
FUI.AddControl(mixedListLabel);
ItemListbox mixedListbox = new ItemListbox();
mixedListbox.Position = new Vector2(460, 115);
mixedListbox.Size = new Vector2(250, 250);
mixedListbox.ItemHeight = 28;
mixedListbox.AlternatingRowColors = true;
// Text item
mixedListbox.AddItem("Header: Settings");
// Checkbox widget
CheckBox chk1 = new CheckBox("Enable Feature A");
chk1.Size = new Vector2(200, 24);
mixedListbox.AddItem(chk1);
// Another checkbox
CheckBox chk2 = new CheckBox("Enable Feature B");
chk2.Size = new Vector2(200, 24);
chk2.IsChecked = true;
mixedListbox.AddItem(chk2);
// Text separator
mixedListbox.AddItem("Header: Progress");
// Progress bar widget
ProgressBar progress1 = new ProgressBar();
progress1.Size = new Vector2(200, 20);
progress1.Value = 0.75f;
mixedListbox.AddItem(new ItemListboxItem(progress1) { Height = 24 });
// Another progress bar
ProgressBar progress2 = new ProgressBar();
progress2.Size = new Vector2(200, 20);
progress2.Value = 0.45f;
mixedListbox.AddItem(new ItemListboxItem(progress2) { Height = 24 });
// Text separator
mixedListbox.AddItem("Header: Actions");
// Button widget
Button actionBtn = new Button();
actionBtn.Text = "Apply Settings";
actionBtn.Size = new Vector2(200, 24);
actionBtn.OnButtonPressed += (b, mb, pos) => Console.WriteLine("Settings applied!");
mixedListbox.AddItem(actionBtn);
// Slider widget
Slider slider = new Slider();
slider.Size = new Vector2(200, 20);
slider.Value = 0.5f;
mixedListbox.AddItem(new ItemListboxItem(slider) { Height = 24 });
mixedListbox.OnItemSelected += (lb, idx, item) =>
{
string desc = item.Widget != null ? $"Widget: {item.Widget.GetType().Name}" : $"Text: {item.Text}";
Console.WriteLine($"Mixed list selected index {idx}: {desc}");
};
FUI.AddControl(mixedListbox);
// === Selection Info Label ===
Label infoLabel = new Label("Click items to select. Check console for selection events.");
infoLabel.Position = new Vector2(20, 380);
infoLabel.Size = new Vector2(600, 20);
infoLabel.Alignment = Align.Left;
FUI.AddControl(infoLabel);
}
}
}