Skip to content

Commit 853f60a

Browse files
Update the sample to allow general closed paths
1 parent ba30d02 commit 853f60a

3 files changed

Lines changed: 467 additions & 59 deletions

File tree

samples/WebGPUExternalSurfaceDemo/MainForm.cs

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ internal sealed class MainForm : Form
2626
private readonly ManualTextFlowScene manualTextFlowScene;
2727
private readonly RichTextEditorScene richTextScene;
2828
private readonly Label tigerStatusLabel;
29+
private readonly ComboBox manualTextShapeComboBox;
2930
private readonly CheckBox boldButton;
3031
private readonly CheckBox italicButton;
3132
private readonly CheckBox underlineButton;
@@ -94,6 +95,50 @@ public MainForm()
9495
};
9596
this.tigerControl.Controls.Add(this.tigerStatusLabel);
9697

98+
// The manual flow scene is intentionally controlled from ordinary WinForms
99+
// widgets. Changing this dropdown swaps the obstacle path, while the scene
100+
// keeps using the same retained TextBlock and per-line layout enumerator.
101+
this.manualTextShapeComboBox = new ComboBox
102+
{
103+
DropDownStyle = ComboBoxStyle.DropDownList,
104+
Width = 140,
105+
Margin = new Padding(0, 0, 8, 0),
106+
};
107+
108+
foreach (ManualTextFlowObstacleShape shape in Enum.GetValues<ManualTextFlowObstacleShape>())
109+
{
110+
this.manualTextShapeComboBox.Items.Add(shape);
111+
}
112+
113+
this.manualTextShapeComboBox.SelectedItem = this.manualTextFlowScene.ObstacleShape;
114+
this.manualTextShapeComboBox.SelectedIndexChanged += (_, _) =>
115+
{
116+
if (this.manualTextShapeComboBox.SelectedItem is ManualTextFlowObstacleShape shape)
117+
{
118+
this.manualTextFlowScene.ObstacleShape = shape;
119+
this.manualTextFlowControl.Invalidate();
120+
}
121+
};
122+
123+
FlowLayoutPanel manualTextFlowToolbar = new()
124+
{
125+
Dock = DockStyle.Top,
126+
AutoSize = true,
127+
Padding = new Padding(8),
128+
};
129+
130+
manualTextFlowToolbar.Controls.Add(new Label
131+
{
132+
AutoSize = true,
133+
Margin = new Padding(0, 5, 8, 0),
134+
Text = "Shape",
135+
});
136+
manualTextFlowToolbar.Controls.Add(this.manualTextShapeComboBox);
137+
138+
Panel manualTextFlowPanel = new() { Dock = DockStyle.Fill };
139+
manualTextFlowPanel.Controls.Add(this.manualTextFlowControl);
140+
manualTextFlowPanel.Controls.Add(manualTextFlowToolbar);
141+
97142
this.boldButton = this.CreateEditorToggleButton("B", () => this.richTextScene.ToggleBold());
98143
this.italicButton = this.CreateEditorToggleButton("I", () => this.richTextScene.ToggleItalic());
99144
this.underlineButton = this.CreateEditorToggleButton("U", () => this.richTextScene.ToggleUnderline());
@@ -249,7 +294,7 @@ public MainForm()
249294
tabs.TabPages.Add(applyTab);
250295

251296
TabPage manualTextFlowTab = new(this.manualTextFlowScene.DisplayName);
252-
manualTextFlowTab.Controls.Add(this.manualTextFlowControl);
297+
manualTextFlowTab.Controls.Add(manualTextFlowPanel);
253298
tabs.TabPages.Add(manualTextFlowTab);
254299

255300
TabPage richTextTab = new(this.richTextScene.DisplayName);

samples/WebGPUExternalSurfaceDemo/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ When the sample starts you should see a WinForms window with five tabs:
2828
- `Clock`: a continuously-rendered animated clock scene
2929
- `Tiger`: an interactive SVG tiger viewer with pan and zoom
3030
- `Apply`: a reactive external-surface readback scene using `DrawingCanvas.Apply(...)`; move the mouse to move the edge-detect and blur regions, and use the mouse wheel to resize them
31-
- `Manual Text Flow`: prepared text is laid out one line at a time around a circular obstacle that follows mouse movement
31+
- `Manual Text Flow`: prepared text is laid out one line at a time around a selectable path obstacle that follows mouse movement
3232
- `Rich Text Editor`: a small editor surface that exercises text selection, caret movement, hit testing, font changes, and inline styling
3333

3434
## Why This Sample Matters
@@ -116,7 +116,7 @@ The scenes are deliberately ordinary canvas code:
116116
- [ClockScene.cs](d:/GitHub/SixLabors/ImageSharp.Drawing/samples/WebGPUExternalSurfaceDemo/Scenes/ClockScene.cs): animated vector clock
117117
- [TigerViewerScene.cs](d:/GitHub/SixLabors/ImageSharp.Drawing/samples/WebGPUExternalSurfaceDemo/Scenes/TigerViewerScene.cs): pan and zoom SVG tiger viewer
118118
- [ApplyReadbackScene.cs](d:/GitHub/SixLabors/ImageSharp.Drawing/samples/WebGPUExternalSurfaceDemo/Scenes/ApplyReadbackScene.cs): `Apply(...)` scene that reads the external surface back into CPU processing
119-
- [ManualTextFlowScene.cs](d:/GitHub/SixLabors/ImageSharp.Drawing/samples/WebGPUExternalSurfaceDemo/Scenes/ManualTextFlowScene.cs): interactive manual text flow using prepared line layout enumeration
119+
- [ManualTextFlowScene.cs](d:/GitHub/SixLabors/ImageSharp.Drawing/samples/WebGPUExternalSurfaceDemo/Scenes/ManualTextFlowScene.cs): interactive manual text flow using prepared line layout enumeration and a selectable closed-path obstacle
120120
- [RichTextEditorScene.cs](d:/GitHub/SixLabors/ImageSharp.Drawing/samples/WebGPUExternalSurfaceDemo/Scenes/RichTextEditorScene.cs): custom rich text editor built from Fonts hit testing, caret, selection, and run APIs
121121

122122
Each scene receives:

0 commit comments

Comments
 (0)