Fixed TabView

This commit is contained in:
Tig Kindel
2024-01-07 23:32:50 -07:00
parent ec613eee92
commit c4dc3fee29
9 changed files with 825 additions and 803 deletions

View File

@@ -66,7 +66,7 @@ public partial class View {
_y = _frame.Y;
_width = _frame.Width;
_height = _frame.Height;
// TODO: Figure out if the below can be optimized.
if (IsInitialized /*|| LayoutStyle == LayoutStyle.Absolute*/) {
LayoutFrames ();
@@ -615,10 +615,14 @@ public partial class View {
// First try SuperView.Bounds, then Application.Top, then Driver
// Finally, if none of those are valid, use int.MaxValue (for Unit tests).
SetRelativeLayout (SuperView?.Bounds ?? Application.Top?.Bounds ?? Application.Driver?.Bounds ?? new Rect (0, 0, int.MaxValue, int.MaxValue));
var relativeBounds = SuperView is { IsInitialized: true } ? SuperView.Bounds :
((Application.Top != null && Application.Top.IsInitialized) ? Application.Top.Bounds :
Application.Driver?.Bounds ??
new Rect (0, 0, int.MaxValue, int.MaxValue));
SetRelativeLayout (relativeBounds);
// TODO: Determine what, if any of the below is actually needed here.
if (IsInitialized/* || LayoutStyle == LayoutStyle.Absolute*/) {
if (IsInitialized) {
SetFrameToFitText ();
LayoutFrames ();
TextFormatter.Size = GetTextFormatterSizeNeededForTextAndHotKey ();
@@ -874,16 +878,16 @@ public partial class View {
// Set the frame. Do NOT use `Frame` as it overwrites X, Y, Width, and Height, making
// the view LayoutStyle.Absolute.
_frame = r;
if (X is Pos.PosAbsolute) {
if (_x is Pos.PosAbsolute) {
_x = Frame.X;
}
if (Y is Pos.PosAbsolute) {
if (_y is Pos.PosAbsolute) {
_y = Frame.Y;
}
if (Width is Dim.DimAbsolute) {
if (_width is Dim.DimAbsolute) {
_width = Frame.Width;
}
if (Height is Dim.DimAbsolute) {
if (_height is Dim.DimAbsolute) {
_height = Frame.Height;
}
@@ -894,7 +898,7 @@ public partial class View {
SetNeedsLayout ();
//SetNeedsDisplay ();
}
// BUGBUG: Why is this AFTER setting Frame? Seems duplicative.
if (!SetFrameToFitText ()) {
TextFormatter.Size = GetTextFormatterSizeNeededForTextAndHotKey ();
@@ -1148,7 +1152,7 @@ public partial class View {
void LayoutSubview (View v, Rect contentArea)
{
//if (v.LayoutStyle == LayoutStyle.Computed) {
v.SetRelativeLayout (contentArea);
v.SetRelativeLayout (contentArea);
//}
v.LayoutSubviews ();

File diff suppressed because it is too large Load Diff

View File

@@ -227,7 +227,6 @@ namespace Terminal.Gui {
if (Frame.Height > 1) {
Height = 1;
}
Adjust ();
}

View File

@@ -59,7 +59,7 @@ namespace UICatalog.Scenarios {
};
tabView.AddTab (new Tab ("Tab1", new Label ("hodor!")), false);
tabView.AddTab (new Tab ("Tab2", new Label ("durdur")), false);
tabView.AddTab (new Tab ("Tab2", new TextField ("durdur")), false);
tabView.AddTab (new Tab ("Interactive Tab", GetInteractiveTab ()), false);
tabView.AddTab (new Tab ("Big Text", GetBigTextFileTab ()), false);
tabView.AddTab (new Tab (

View File

@@ -233,7 +233,7 @@ namespace UICatalog.Scenarios {
};
var appendAutocompleteTextField = new TextField () {
X = Pos.Right (labelAppendAutocomplete),
Y = labelAppendAutocomplete.Y,
Y = Pos.Bottom (labelAppendAutocomplete),
Width = Dim.Fill ()
};
appendAutocompleteTextField.Autocomplete = new AppendAutocomplete (appendAutocompleteTextField);

View File

@@ -181,18 +181,33 @@ namespace Terminal.Gui.DialogTests {
// This is because of PostionTopLevels and EnsureVisibleBounds
Assert.Equal (new Point (3, 2), d.Frame.Location);
Assert.Equal (new Size (17, 8), d.Frame.Size);
// #3127: Before
// Assert.Equal (new Size (17, 8), d.Frame.Size);
// TestHelpers.AssertDriverContentsWithFrameAre (@"
//╔══════════════════╗
//║ ║
//║ ┌───────────────┐
//║ │ │
//║ │ │
//║ │ │
//║ │ │
//║ │ │
//║ │ │
//╚══└───────────────┘", output);
// #3127: After: Because Toplevel is now Width/Height = Dim.Filll
Assert.Equal (new Size (15, 6), d.Frame.Size);
TestHelpers.AssertDriverContentsWithFrameAre (@"
╔══════════════════╗
║ ║
║ ┌───────────────
║ │
║ │
║ │
║ │
│ │
╚══└───────────────┘", output);
║ ┌─────────────┐
║ │ │
║ │ │
║ │ │
║ │ │
└─────────────┘ ║
╚══════════════════╝", output);
} else if (iterations > 0) {
Application.RequestStop ();
@@ -971,20 +986,11 @@ namespace Terminal.Gui.DialogTests {
Application.Refresh ();
Assert.Equal (new Rect (10, 0, 6, 1), btn.Frame);
Assert.Equal (new Rect (0, 0, 6, 1), btn.Bounds);
// #3127: Before: This test was clearly wrong before. The math above is correct, but the result is wrong.
// var expected = @$"
//┌──────────────────┐
//│┌────────────────┐│
//││23456789 {b}││
//│└────────────────┘│
//└──────────────────┘";
// #3127: After: This test was clearly wrong before. The math above is correct, but the result is wrong.
// See also `PosDimFunction` in SetRelativeLayoutTests.cs
var expected = @$"
┌──────────────────┐
│┌────────────────┐│
││012345678 {b}││
││23456789 {b}││
│└────────────────┘│
└──────────────────┘";
@@ -998,7 +1004,7 @@ namespace Terminal.Gui.DialogTests {
expected = @$"
┌──────────────────┐
│┌────────────────┐│
││012345678 {b}││
││23456789 {b}││
│└────────────────┘│
└──────────────────┘";
_ = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);

View File

@@ -265,20 +265,20 @@ namespace Terminal.Gui.ViewTests {
int tc = 0, wc = 0, v1c = 0, v2c = 0, sv1c = 0;
winAddedToTop.Added += (s, e) => {
Assert.Equal (e.Parent.Bounds.Width, winAddedToTop.Frame.Width);
Assert.Equal (e.Parent.Bounds.Height, winAddedToTop.Frame.Height);
Assert.Equal (e.Parent.Frame.Width, winAddedToTop.Frame.Width);
Assert.Equal (e.Parent.Frame.Height, winAddedToTop.Frame.Height);
};
v1AddedToWin.Added += (s, e) => {
Assert.Equal (e.Parent.Bounds.Width, v1AddedToWin.Frame.Width);
Assert.Equal (e.Parent.Bounds.Height, v1AddedToWin.Frame.Height);
Assert.Equal (e.Parent.Frame.Width, v1AddedToWin.Frame.Width);
Assert.Equal (e.Parent.Frame.Height, v1AddedToWin.Frame.Height);
};
v2AddedToWin.Added += (s, e) => {
Assert.Equal (e.Parent.Bounds.Width, v2AddedToWin.Frame.Width);
Assert.Equal (e.Parent.Bounds.Height, v2AddedToWin.Frame.Height);
Assert.Equal (e.Parent.Frame.Width, v2AddedToWin.Frame.Width);
Assert.Equal (e.Parent.Frame.Height, v2AddedToWin.Frame.Height);
};
svAddedTov1.Added += (s, e) => {
Assert.Equal (e.Parent.Bounds.Width, svAddedTov1.Frame.Width);
Assert.Equal (e.Parent.Bounds.Height, svAddedTov1.Frame.Height);
Assert.Equal (e.Parent.Frame.Width, svAddedTov1.Frame.Width);
Assert.Equal (e.Parent.Frame.Height, svAddedTov1.Frame.Height);
};
top.Initialized += (s, e) => {

View File

@@ -188,6 +188,8 @@ namespace Terminal.Gui.ViewsTests {
Application.Top.Add (sv);
Application.Begin (Application.Top);
Assert.Equal (new Rect (0, 0, 10, 10), sv.Bounds);
Assert.False (sv.AutoHideScrollBars);
Assert.True (sv.ShowHorizontalScrollIndicator);
Assert.True (sv.ShowVerticalScrollIndicator);
@@ -206,7 +208,9 @@ namespace Terminal.Gui.ViewsTests {
", output);
sv.ShowHorizontalScrollIndicator = false;
Assert.Equal (new Rect (0, 0, 10, 10), sv.Bounds);
sv.ShowVerticalScrollIndicator = true;
Assert.Equal (new Rect (0, 0, 10, 10), sv.Bounds);
Assert.False (sv.AutoHideScrollBars);
Assert.False (sv.ShowHorizontalScrollIndicator);
@@ -220,6 +224,7 @@ namespace Terminal.Gui.ViewsTests {
", output);
@@ -241,7 +246,7 @@ namespace Terminal.Gui.ViewsTests {
◄├─────┤►
◄├─────┤►
", output);
sv.ShowHorizontalScrollIndicator = false;

View File

@@ -33,7 +33,7 @@ namespace Terminal.Gui.ViewsTests {
tv.BeginInit ();
tv.EndInit ();
tv.ColorScheme = new ColorScheme ();
tv.AddTab (tab1 = new Tab ("Tab1", new TextField ("hi")), false);
tv.AddTab (tab1 = new Tab ("Tab1", new TextField ("hi") { Width = 2 }), false);
tv.AddTab (tab2 = new Tab ("Tab2", new Label ("hi2")), false);
return tv;
}