mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
Fixes #2219. Moving a grab a top with a superview fails with Dim.
This commit is contained in:
@@ -613,11 +613,8 @@ namespace Terminal.Gui {
|
||||
}
|
||||
nx = Math.Max (x, 0);
|
||||
nx = nx + top.Frame.Width > l ? Math.Max (l - top.Frame.Width, 0) : nx;
|
||||
var canChange = SetWidth (top.Frame.Width, out int rWidth);
|
||||
if (canChange && rWidth < 0 && nx >= top.Frame.X) {
|
||||
nx = Math.Max (top.Frame.Right - 2, 0);
|
||||
} else if (rWidth < 0 && nx >= top.Frame.X) {
|
||||
nx = Math.Min (nx + 1, top.Frame.Right - 2);
|
||||
if (nx + (top.Border != null && top.Border.DrawMarginFrame ? 2 : 1) > top.Frame.X + top.Frame.Width) {
|
||||
nx = Math.Max (top.Frame.Right - (top.Border.DrawMarginFrame ? 2 : 1), 0);
|
||||
}
|
||||
//System.Diagnostics.Debug.WriteLine ($"nx:{nx}, rWidth:{rWidth}");
|
||||
bool m, s;
|
||||
@@ -656,11 +653,8 @@ namespace Terminal.Gui {
|
||||
}
|
||||
ny = Math.Min (ny, l);
|
||||
ny = ny + top.Frame.Height >= l ? Math.Max (l - top.Frame.Height, m ? 1 : 0) : ny;
|
||||
canChange = SetHeight (top.Frame.Height, out int rHeight);
|
||||
if (canChange && rHeight < 0 && ny >= top.Frame.Y) {
|
||||
ny = Math.Max (top.Frame.Bottom - 2, 0);
|
||||
} else if (rHeight < 0 && ny >= top.Frame.Y) {
|
||||
ny = Math.Min (ny + 1, top.Frame.Bottom - 2);
|
||||
if (ny + (top.Border != null && top.Border.DrawMarginFrame ? 2 : 1) > top.Frame.Y + top.Frame.Height) {
|
||||
ny = Math.Max (top.Frame.Bottom - (top.Border.DrawMarginFrame ? 2 : 1), 0);
|
||||
}
|
||||
//System.Diagnostics.Debug.WriteLine ($"ny:{ny}, rHeight:{rHeight}");
|
||||
|
||||
@@ -701,7 +695,7 @@ namespace Terminal.Gui {
|
||||
}
|
||||
|
||||
if (sb != null && ny + top.Frame.Height != superView.Frame.Height - (sb.Visible ? 1 : 0)
|
||||
&& top.Height is Dim.DimFill) {
|
||||
&& top.Height is Dim.DimFill && -top.Height.Anchor (0) < 1) {
|
||||
|
||||
top.Height = Dim.Fill (sb.Visible ? 1 : 0);
|
||||
layoutSubviews = true;
|
||||
|
||||
@@ -38,19 +38,19 @@ namespace UICatalog.Scenarios {
|
||||
|
||||
_label = new Label () {
|
||||
X = Pos.Center (),
|
||||
Y = 0,
|
||||
Y = 1,
|
||||
ColorScheme = new ColorScheme () {
|
||||
Normal = Colors.Base.Focus
|
||||
}
|
||||
};
|
||||
_text = new TextField () {
|
||||
X = Pos.Center (),
|
||||
Y = 2,
|
||||
Y = 3,
|
||||
Width = 20
|
||||
};
|
||||
_button = new Button () {
|
||||
X = Pos.Center (),
|
||||
Y = 4
|
||||
Y = 5
|
||||
};
|
||||
_labelR = new Label () {
|
||||
X = Pos.AnchorEnd (30),
|
||||
|
||||
@@ -671,7 +671,7 @@ namespace Terminal.Gui.Core {
|
||||
}
|
||||
|
||||
[Fact, AutoInitShutdown]
|
||||
public void Mouse_Drag ()
|
||||
public void Mouse_Drag_On_Top_With_Superview_Null ()
|
||||
{
|
||||
var menu = new MenuBar (new MenuBarItem [] {
|
||||
new MenuBarItem("File", new MenuItem [] {
|
||||
@@ -825,5 +825,147 @@ namespace Terminal.Gui.Core {
|
||||
|
||||
Application.Run ();
|
||||
}
|
||||
|
||||
[Fact, AutoInitShutdown]
|
||||
public void Mouse_Drag_On_Top_With_Superview_Not_Null ()
|
||||
{
|
||||
var menu = new MenuBar (new MenuBarItem [] {
|
||||
new MenuBarItem("File", new MenuItem [] {
|
||||
new MenuItem("New", "", null)
|
||||
})
|
||||
});
|
||||
|
||||
var sbar = new StatusBar (new StatusItem [] {
|
||||
new StatusItem(Key.N, "~CTRL-N~ New", null)
|
||||
});
|
||||
|
||||
var win = new Window ("Window") {
|
||||
X = 3,
|
||||
Y = 2,
|
||||
Width = Dim.Fill (10),
|
||||
Height = Dim.Fill (5)
|
||||
};
|
||||
var top = Application.Top;
|
||||
top.Add (menu, sbar, win);
|
||||
|
||||
var iterations = -1;
|
||||
|
||||
Application.Iteration = () => {
|
||||
iterations++;
|
||||
if (iterations == 0) {
|
||||
((FakeDriver)Application.Driver).SetBufferSize (20, 10);
|
||||
|
||||
Assert.Null (Application.MouseGrabView);
|
||||
// Grab the mouse
|
||||
ReflectionTools.InvokePrivate (
|
||||
typeof (Application),
|
||||
"ProcessMouseEvent",
|
||||
new MouseEvent () {
|
||||
X = 4,
|
||||
Y = 2,
|
||||
Flags = MouseFlags.Button1Pressed
|
||||
});
|
||||
|
||||
Assert.Equal (win, Application.MouseGrabView);
|
||||
Assert.Equal (new Rect (3, 2, 7, 3), Application.MouseGrabView.Frame);
|
||||
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
||||
File
|
||||
|
||||
┌─────┐
|
||||
│ │
|
||||
└─────┘
|
||||
|
||||
|
||||
|
||||
|
||||
CTRL-N New", output);
|
||||
|
||||
|
||||
} else if (iterations == 1) {
|
||||
Assert.Equal (win, Application.MouseGrabView);
|
||||
// Grab to left
|
||||
ReflectionTools.InvokePrivate (
|
||||
typeof (Application),
|
||||
"ProcessMouseEvent",
|
||||
new MouseEvent () {
|
||||
X = 5,
|
||||
Y = 2,
|
||||
Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition
|
||||
});
|
||||
|
||||
Assert.Equal (win, Application.MouseGrabView);
|
||||
|
||||
} else if (iterations == 2) {
|
||||
Assert.Equal (win, Application.MouseGrabView);
|
||||
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
||||
File
|
||||
|
||||
┌────┐
|
||||
│ │
|
||||
└────┘
|
||||
|
||||
|
||||
|
||||
|
||||
CTRL-N New", output);
|
||||
|
||||
Assert.Equal (win, Application.MouseGrabView);
|
||||
Assert.Equal (new Rect (4, 2, 6, 3), Application.MouseGrabView.Frame);
|
||||
|
||||
} else if (iterations == 3) {
|
||||
Assert.Equal (win, Application.MouseGrabView);
|
||||
// Grab to top
|
||||
ReflectionTools.InvokePrivate (
|
||||
typeof (Application),
|
||||
"ProcessMouseEvent",
|
||||
new MouseEvent () {
|
||||
X = 5,
|
||||
Y = 1,
|
||||
Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition
|
||||
});
|
||||
|
||||
Assert.Equal (win, Application.MouseGrabView);
|
||||
|
||||
} else if (iterations == 4) {
|
||||
Assert.Equal (win, Application.MouseGrabView);
|
||||
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
||||
File
|
||||
┌────┐
|
||||
│ │
|
||||
│ │
|
||||
└────┘
|
||||
|
||||
|
||||
|
||||
|
||||
CTRL-N New", output);
|
||||
|
||||
Assert.Equal (win, Application.MouseGrabView);
|
||||
Assert.Equal (new Rect (4, 1, 6, 4), Application.MouseGrabView.Frame);
|
||||
|
||||
} else if (iterations == 5) {
|
||||
Assert.Equal (win, Application.MouseGrabView);
|
||||
// Ungrab the mouse
|
||||
ReflectionTools.InvokePrivate (
|
||||
typeof (Application),
|
||||
"ProcessMouseEvent",
|
||||
new MouseEvent () {
|
||||
X = 7,
|
||||
Y = 4,
|
||||
Flags = MouseFlags.Button1Released
|
||||
});
|
||||
|
||||
Assert.Null (Application.MouseGrabView);
|
||||
|
||||
} else if (iterations == 8) {
|
||||
Application.RequestStop ();
|
||||
}
|
||||
};
|
||||
|
||||
Application.Run ();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user