Skip to content

Commit e95563a

Browse files
committed
Fixes Window being too wide/tall when added
Fixes Window being core 'moveable' This goes considerable way to fixing: gui-cs/Terminal.Gui#3650 But can consider making the Arrangement property user configureable in the same way that we do with Visible (see TestSettingVisible_False) where user can change the value but it does not manifest in the behavior of the view (only for code gen).
1 parent 8252001 commit e95563a

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

src/Design.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,12 @@ public Design CreateSubControlDesign(string name, View subView)
229229
tf.KeyDown += (s, e) => e.Handled = true;
230230
}
231231

232+
if (subView is Window w)
233+
{
234+
// prevent control from responding to events
235+
w.Arrangement = ViewArrangement.Fixed;
236+
}
237+
232238
if (subView is TreeView tree)
233239
{
234240
tree.AddObject(new TreeNode("Example Branch 1")

src/ViewFactory.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,9 @@ public static T Create<T>(int? width = null, int? height = null, string? text =
257257

258258
static void SetDefaultDimensions( T v, int width = 5, int height = 1 )
259259
{
260-
v.Width = Math.Max( v.GetContentSize().Width, width );
261-
v.Height = Math.Max( v.GetContentSize().Height, height );
260+
v.Width = v.Width is DimFill ? width : Math.Max(v.GetContentSize().Width, width);
261+
262+
v.Height = v.Height is DimFill ? height : Math.Max( v.GetContentSize().Height, height );
262263
}
263264
}
264265

tests/WindowTests.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace UnitTests
8+
{
9+
internal class WindowTests : Tests
10+
{
11+
[Test]
12+
public void TestViewFactory_HasSensibleDimensions()
13+
{
14+
var w = ViewFactory.Create<Window>();
15+
Assert.That(w.Width,Is.EqualTo((DimAbsolute)10));
16+
Assert.That(w.Height, Is.EqualTo((DimAbsolute)5));
17+
}
18+
19+
[Test]
20+
public void TestViewFactory_IsNotVanillaDraggable()
21+
{
22+
RoundTrip<View, Window>(static (_, w) =>
23+
{
24+
// When adding a Window to the editor it should not be 'moveable'
25+
// This is because the core Terminal.Gui drag will conflict with the TGD dragging.
26+
Assert.That(w.Arrangement, Is.EqualTo(ViewArrangement.Fixed));
27+
28+
}, out _);
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)