-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSampleEditorLayout.cs
More file actions
180 lines (150 loc) · 5.38 KB
/
SampleEditorLayout.cs
File metadata and controls
180 lines (150 loc) · 5.38 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
using FishUI;
using FishUI.Controls;
using System;
using System.Numerics;
namespace FishUIDemos
{
/// <summary>
/// Demonstrates loading and rendering a layout created with the FishUIEditor.
/// Loads from data/layouts/editor_layout.yaml if it exists, otherwise shows a blank panel.
/// </summary>
public class SampleEditorLayout : ISample
{
FishUI.FishUI FUI;
Label _statusLabel;
Panel _layoutContainer;
public string Name => "Editor Layout";
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("Editor Layout Demo");
titleLabel.Position = new Vector2(20, 20);
titleLabel.Size = new Vector2(350, 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.IconPath = "data/silk_icons/camera.png";
screenshotBtn.Position = new Vector2(380, 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);
// Reload button
Button reloadBtn = new Button();
reloadBtn.Text = "Reload Layout";
reloadBtn.Position = new Vector2(420, 20);
reloadBtn.Size = new Vector2(120, 30);
reloadBtn.TooltipText = "Reload the layout from data/layouts/editor_layout.yaml";
reloadBtn.OnButtonPressed += (btn, mbtn, pos) => ReloadLayout();
FUI.AddControl(reloadBtn);
// Status label
_statusLabel = new Label("");
_statusLabel.Position = new Vector2(550, 20);
_statusLabel.Size = new Vector2(400, 30);
_statusLabel.Alignment = Align.Left;
FUI.AddControl(_statusLabel);
// Instructions
Label instructionsLabel = new Label("This sample loads layouts created with FishUIEditor from data/layouts/editor_layout.yaml");
instructionsLabel.Position = new Vector2(20, 55);
instructionsLabel.Size = new Vector2(800, 20);
instructionsLabel.Alignment = Align.Left;
FUI.AddControl(instructionsLabel);
// Layout container panel
_layoutContainer = new Panel();
_layoutContainer.Position = new Vector2(20, 85);
_layoutContainer.Size = new Vector2(760, 480);
_layoutContainer.Variant = PanelVariant.Dark;
FUI.AddControl(_layoutContainer);
// Try to load the layout
LoadLayout();
}
private void LoadLayout()
{
const string layoutPath = "data/layouts/editor_layout.yaml";
try
{
// Check if file exists
if (!FUI.FileSystem.Exists(layoutPath))
{
ShowEmptyState($"Layout file not found: {layoutPath}");
return;
}
// Read and deserialize the layout
string yaml = FUI.FileSystem.ReadAllText(layoutPath);
var controls = LayoutFormat.DeserializeControls(yaml);
// Clear existing controls in container
_layoutContainer.RemoveAllChildren();
// Add loaded controls to the container
foreach (var control in controls)
{
control.OnDeserialized(FUI);
_layoutContainer.AddChild(control);
}
SetStatus($"Loaded {controls.Count} control(s) from {layoutPath}");
}
catch (Exception ex)
{
ShowEmptyState($"Failed to load layout: {ex.Message}");
}
}
private void ReloadLayout()
{
// Clear container
_layoutContainer.RemoveAllChildren();
// Reload
LoadLayout();
}
private void ShowEmptyState(string message)
{
SetStatus(message);
// Show instructions for creating a layout
Label emptyLabel = new Label("No layout loaded");
emptyLabel.Position = new Vector2(20, 20);
emptyLabel.Size = new Vector2(300, 30);
emptyLabel.Alignment = Align.Left;
_layoutContainer.AddChild(emptyLabel);
Label instructionLabel = new Label("To create a layout:");
instructionLabel.Position = new Vector2(20, 60);
instructionLabel.Size = new Vector2(300, 20);
instructionLabel.Alignment = Align.Left;
_layoutContainer.AddChild(instructionLabel);
Label step1 = new Label("1. Run the FishUIEditor project");
step1.Position = new Vector2(40, 85);
step1.Size = new Vector2(400, 20);
step1.Alignment = Align.Left;
_layoutContainer.AddChild(step1);
Label step2 = new Label("2. Design your UI by dragging controls from the toolbox");
step2.Position = new Vector2(40, 105);
step2.Size = new Vector2(400, 20);
step2.Alignment = Align.Left;
_layoutContainer.AddChild(step2);
Label step3 = new Label("3. Save your layout to data/layouts/editor_layout.yaml");
step3.Position = new Vector2(40, 125);
step3.Size = new Vector2(400, 20);
step3.Alignment = Align.Left;
_layoutContainer.AddChild(step3);
Label step4 = new Label("4. Click 'Reload Layout' in this sample to see your creation!");
step4.Position = new Vector2(40, 145);
step4.Size = new Vector2(400, 20);
step4.Alignment = Align.Left;
_layoutContainer.AddChild(step4);
}
private void SetStatus(string message)
{
if (_statusLabel != null)
_statusLabel.Text = message;
}
}
}