Skip to content

Commit 1cedbbe

Browse files
MichaCMichaC
authored andcommitted
Fix for UI app to auto select first example + scale properly on start
1 parent 823c955 commit 1cedbbe

40 files changed

Lines changed: 16888 additions & 8 deletions

viz/CDT.Viz/CDT.Viz.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<ItemGroup>
1919
<Resource Include="Resources\cdt.ico" Condition="Exists('Resources\cdt.ico')" />
2020
<!-- Copy test input files so the file list is populated at runtime -->
21-
<Content Include="..\..\test\CDT.Tests\inputs\*.txt"
21+
<Content Include="data\*.txt"
2222
CopyToOutputDirectory="PreserveNewest"
2323
Link="inputs\%(Filename)%(Extension)" />
2424
</ItemGroup>

viz/CDT.Viz/MainWindow.xaml.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -205,15 +205,13 @@ public MainWindow()
205205
private void OnLoaded(object sender, RoutedEventArgs e)
206206
{
207207
// Add the visual element to fill the canvas border
208-
_visual.Width = double.NaN;
209-
_visual.Height = double.NaN;
210208
TriCanvas.Children.Add(_visual);
211209
Canvas.SetLeft(_visual, 0);
212210
Canvas.SetTop(_visual, 0);
213211

214-
// Stretch visual to fill the border
215-
_visual.HorizontalAlignment = HorizontalAlignment.Stretch;
216-
_visual.VerticalAlignment = VerticalAlignment.Stretch;
212+
// Set size immediately so FitView works correctly before SizeChanged fires
213+
_visual.Width = CanvasBorder.ActualWidth;
214+
_visual.Height = CanvasBorder.ActualHeight;
217215
CanvasBorder.SizeChanged += (_, _) =>
218216
{
219217
_visual.Width = CanvasBorder.ActualWidth;
@@ -224,6 +222,10 @@ private void OnLoaded(object sender, RoutedEventArgs e)
224222
PopulateFileList();
225223

226224
_initializing = false;
225+
226+
// Auto-load the first example
227+
if (FileList.Items.Count > 0)
228+
FileList.SelectedIndex = 0;
227229
}
228230

229231
private void PopulateFileList()
@@ -484,8 +486,11 @@ private void FitView()
484486
if (dx == 0) dx = 1;
485487
if (dy == 0) dy = 1;
486488

487-
double w = Math.Max(_visual.ActualWidth, 1);
488-
double h = Math.Max(_visual.ActualHeight, 1);
489+
// Use CanvasBorder dimensions directly: the visual always fills it and
490+
// CanvasBorder.ActualWidth/Height are correct even before the visual's
491+
// own ActualWidth/Height have been updated by the layout pass.
492+
double w = Math.Max(CanvasBorder.ActualWidth, 1);
493+
double h = Math.Max(CanvasBorder.ActualHeight, 1);
489494

490495
_visual.Scale = Math.Min(w / dx, h / dy) * 0.9;
491496
_visual.Translation = new Vector(-_visual.Scale * cx, _visual.Scale * cy);

viz/CDT.Viz/data/Capital A.txt

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
29 29
2+
0.200000 -0.776400
3+
0.220000 -0.773200
4+
0.245600 -0.756400
5+
0.277600 -0.702000
6+
0.488800 -0.207600
7+
0.504800 -0.207600
8+
0.740800 -0.7396
9+
0.756000 -0.761200
10+
0.774400 -0.7724
11+
0.800000 -0.776400
12+
0.800000 -0.792400
13+
0.579200 -0.792400
14+
0.579200 -0.776400
15+
0.621600 -0.771600
16+
0.633600 -0.762800
17+
0.639200 -0.744400
18+
0.620800 -0.684400
19+
0.587200 -0.604400
20+
0.360800 -0.604400
21+
0.319200 -0.706800
22+
0.312000 -0.739600
23+
0.318400 -0.761200
24+
0.334400 -0.771600
25+
0.371200 -0.776400
26+
0.371200 -0.792400
27+
0.374400 -0.570000
28+
0.574400 -0.5700
29+
0.473600 -0.330800
30+
0.200000 -0.792400
31+
28 0
32+
0 1
33+
1 2
34+
2 3
35+
3 4
36+
4 5
37+
5 6
38+
6 7
39+
7 8
40+
8 9
41+
9 10
42+
10 11
43+
11 12
44+
12 13
45+
13 14
46+
14 15
47+
15 16
48+
16 17
49+
17 18
50+
18 19
51+
19 20
52+
20 21
53+
21 22
54+
22 23
55+
23 24
56+
24 28
57+
25 26
58+
26 27
59+
27 25

0 commit comments

Comments
 (0)