Skip to content

Commit

Permalink
Fixes Window being too wide/tall when added
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
tznind committed Aug 10, 2024
1 parent 8252001 commit e95563a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/Design.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,12 @@ public Design CreateSubControlDesign(string name, View subView)
tf.KeyDown += (s, e) => e.Handled = true;
}

if (subView is Window w)
{
// prevent control from responding to events
w.Arrangement = ViewArrangement.Fixed;
}

if (subView is TreeView tree)
{
tree.AddObject(new TreeNode("Example Branch 1")
Expand Down
5 changes: 3 additions & 2 deletions src/ViewFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,9 @@ public static T Create<T>(int? width = null, int? height = null, string? text =

static void SetDefaultDimensions( T v, int width = 5, int height = 1 )
{
v.Width = Math.Max( v.GetContentSize().Width, width );
v.Height = Math.Max( v.GetContentSize().Height, height );
v.Width = v.Width is DimFill ? width : Math.Max(v.GetContentSize().Width, width);

v.Height = v.Height is DimFill ? height : Math.Max( v.GetContentSize().Height, height );
}
}

Expand Down
31 changes: 31 additions & 0 deletions tests/WindowTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace UnitTests
{
internal class WindowTests : Tests
{
[Test]
public void TestViewFactory_HasSensibleDimensions()
{
var w = ViewFactory.Create<Window>();
Assert.That(w.Width,Is.EqualTo((DimAbsolute)10));
Assert.That(w.Height, Is.EqualTo((DimAbsolute)5));
}

[Test]
public void TestViewFactory_IsNotVanillaDraggable()
{
RoundTrip<View, Window>(static (_, w) =>
{
// When adding a Window to the editor it should not be 'moveable'
// This is because the core Terminal.Gui drag will conflict with the TGD dragging.
Assert.That(w.Arrangement, Is.EqualTo(ViewArrangement.Fixed));

}, out _);
}
}
}

0 comments on commit e95563a

Please sign in to comment.