From 3e3c606ccfc0355b2953e91d797c95b35aef4786 Mon Sep 17 00:00:00 2001 From: Curtis Wensley Date: Wed, 11 Oct 2023 16:02:56 -0700 Subject: [PATCH] Mac: Fix autosizing of GridView based on content --- .vscode/settings.json | 3 +- src/Eto.Core.sln | 125 ------------------ .../Forms/Controls/GridColumnHandler.cs | 20 ++- src/Eto.Mac/Forms/Controls/GridHandler.cs | 25 +++- test/Eto.Test.Mac/UnitTests/GridViewTests.cs | 59 +++++++-- .../UnitTests/Forms/Controls/GridTests.cs | 62 +++++++++ .../UnitTests/Forms/Controls/GridViewTests.cs | 37 ------ .../Eto.Test/UnitTests/Forms/GridViewUtils.cs | 7 +- 8 files changed, 147 insertions(+), 191 deletions(-) delete mode 100644 src/Eto.Core.sln diff --git a/.vscode/settings.json b/.vscode/settings.json index eef582f99e..c67f183f7d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,4 @@ { - "omnisharp.defaultLaunchSolution": "Eto.Core.sln", "editor.insertSpaces": false, "editor.detectIndentation": false, "files.exclude": { @@ -14,6 +13,6 @@ "src", "samples" ], - "dotnet.defaultSolution": "Eto.Core.sln" + "dotnet.defaultSolution": "src/Eto.sln" } \ No newline at end of file diff --git a/src/Eto.Core.sln b/src/Eto.Core.sln deleted file mode 100644 index 70ff74d7f4..0000000000 --- a/src/Eto.Core.sln +++ /dev/null @@ -1,125 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.26124.0 -MinimumVisualStudioVersion = 15.0.26124.0 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Eto", "Eto\Eto.csproj", "{FE25EE53-3993-4463-AB8E-CCDCE5E3BDC2}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Eto.Serialization.Json", "Eto.Serialization.Json\Eto.Serialization.Json.csproj", "{503A9238-E2D0-4849-8B62-4CEFB799A252}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Eto.Serialization.Xaml", "Eto.Serialization.Xaml\Eto.Serialization.Xaml.csproj", "{5830F6AC-68BE-4444-9160-0739F36BD761}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Eto.Test", "..\test\Eto.Test\Eto.Test.csproj", "{509D49DE-8BDD-43D2-B5D9-EDD390FDA8F3}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Eto.Gtk", "Eto.Gtk\Eto.Gtk.csproj", "{0C792DAE-8855-44CF-87F9-CE7385E3F141}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Eto.Test.Gtk", "..\test\Eto.Test.Gtk\Eto.Test.Gtk.csproj", "{9122333E-56EF-4A18-BBC4-0100589EA49C}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Eto.WinForms", "Eto.WinForms\Eto.WinForms.csproj", "{675E4CC9-41B2-45A6-925D-4E21DD23FAFB}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Eto.Test.WinForms", "..\test\Eto.Test.WinForms\Eto.Test.WinForms.csproj", "{BC4CAE43-F35A-47FD-9284-1D76502A4F2B}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Eto.Wpf", "Eto.Wpf\Eto.Wpf.csproj", "{4BF1720D-10C5-468E-A419-95EE76BF3C98}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Eto.Test.Wpf", "..\test\Eto.Test.Wpf\Eto.Test.Wpf.csproj", "{AE451719-9FDC-4C53-A34A-2788D564A1E3}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Eto.Mac64", "Eto.Mac\Eto.Mac64.csproj", "{0B436044-9251-4922-BC41-51365EBBD771}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Eto.Test.Mac64", "..\test\Eto.Test.Mac\Eto.Test.Mac64.csproj", "{FD8900C4-1EB6-4D8A-A91C-32047D27A430}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MonoMac", "..\lib\monomac\src\MonoMac.csproj", "{9114D372-999B-4894-9460-8A0FF02131E1}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "core", "..\lib\monomac\src\core.csproj", "{549BAAA1-9355-41D7-9755-BF30CB92E4FA}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "monomac", "monomac", "{E77D6350-0CCF-11EB-A5F5-69BE9D4F31C9}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "generator", "..\lib\monomac\src\generator.csproj", "{EE5D4296-DFD7-4D1B-B9F9-C43AD9ED4F6F}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.macOS", "Eto.Mac\Eto.macOS.csproj", "{B3AB773A-BCF6-4679-AC13-E2879F61DF33}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Test.macOS", "..\test\Eto.Test.Mac\Eto.Test.macOS.csproj", "{8A002565-996A-45F9-8D74-89E8D272717F}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {FE25EE53-3993-4463-AB8E-CCDCE5E3BDC2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {FE25EE53-3993-4463-AB8E-CCDCE5E3BDC2}.Debug|Any CPU.Build.0 = Debug|Any CPU - {FE25EE53-3993-4463-AB8E-CCDCE5E3BDC2}.Release|Any CPU.ActiveCfg = Release|Any CPU - {FE25EE53-3993-4463-AB8E-CCDCE5E3BDC2}.Release|Any CPU.Build.0 = Release|Any CPU - {503A9238-E2D0-4849-8B62-4CEFB799A252}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {503A9238-E2D0-4849-8B62-4CEFB799A252}.Debug|Any CPU.Build.0 = Debug|Any CPU - {503A9238-E2D0-4849-8B62-4CEFB799A252}.Release|Any CPU.ActiveCfg = Release|Any CPU - {503A9238-E2D0-4849-8B62-4CEFB799A252}.Release|Any CPU.Build.0 = Release|Any CPU - {5830F6AC-68BE-4444-9160-0739F36BD761}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {5830F6AC-68BE-4444-9160-0739F36BD761}.Debug|Any CPU.Build.0 = Debug|Any CPU - {5830F6AC-68BE-4444-9160-0739F36BD761}.Release|Any CPU.ActiveCfg = Release|Any CPU - {5830F6AC-68BE-4444-9160-0739F36BD761}.Release|Any CPU.Build.0 = Release|Any CPU - {509D49DE-8BDD-43D2-B5D9-EDD390FDA8F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {509D49DE-8BDD-43D2-B5D9-EDD390FDA8F3}.Debug|Any CPU.Build.0 = Debug|Any CPU - {509D49DE-8BDD-43D2-B5D9-EDD390FDA8F3}.Release|Any CPU.ActiveCfg = Release|Any CPU - {509D49DE-8BDD-43D2-B5D9-EDD390FDA8F3}.Release|Any CPU.Build.0 = Release|Any CPU - {0C792DAE-8855-44CF-87F9-CE7385E3F141}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {0C792DAE-8855-44CF-87F9-CE7385E3F141}.Debug|Any CPU.Build.0 = Debug|Any CPU - {0C792DAE-8855-44CF-87F9-CE7385E3F141}.Release|Any CPU.ActiveCfg = Release|Any CPU - {0C792DAE-8855-44CF-87F9-CE7385E3F141}.Release|Any CPU.Build.0 = Release|Any CPU - {9122333E-56EF-4A18-BBC4-0100589EA49C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {9122333E-56EF-4A18-BBC4-0100589EA49C}.Debug|Any CPU.Build.0 = Debug|Any CPU - {9122333E-56EF-4A18-BBC4-0100589EA49C}.Release|Any CPU.ActiveCfg = Release|Any CPU - {9122333E-56EF-4A18-BBC4-0100589EA49C}.Release|Any CPU.Build.0 = Release|Any CPU - {675E4CC9-41B2-45A6-925D-4E21DD23FAFB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {675E4CC9-41B2-45A6-925D-4E21DD23FAFB}.Debug|Any CPU.Build.0 = Debug|Any CPU - {675E4CC9-41B2-45A6-925D-4E21DD23FAFB}.Release|Any CPU.ActiveCfg = Release|Any CPU - {675E4CC9-41B2-45A6-925D-4E21DD23FAFB}.Release|Any CPU.Build.0 = Release|Any CPU - {BC4CAE43-F35A-47FD-9284-1D76502A4F2B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {BC4CAE43-F35A-47FD-9284-1D76502A4F2B}.Debug|Any CPU.Build.0 = Debug|Any CPU - {BC4CAE43-F35A-47FD-9284-1D76502A4F2B}.Release|Any CPU.ActiveCfg = Release|Any CPU - {BC4CAE43-F35A-47FD-9284-1D76502A4F2B}.Release|Any CPU.Build.0 = Release|Any CPU - {4BF1720D-10C5-468E-A419-95EE76BF3C98}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {4BF1720D-10C5-468E-A419-95EE76BF3C98}.Debug|Any CPU.Build.0 = Debug|Any CPU - {4BF1720D-10C5-468E-A419-95EE76BF3C98}.Release|Any CPU.ActiveCfg = Release|Any CPU - {4BF1720D-10C5-468E-A419-95EE76BF3C98}.Release|Any CPU.Build.0 = Release|Any CPU - {AE451719-9FDC-4C53-A34A-2788D564A1E3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {AE451719-9FDC-4C53-A34A-2788D564A1E3}.Debug|Any CPU.Build.0 = Debug|Any CPU - {AE451719-9FDC-4C53-A34A-2788D564A1E3}.Release|Any CPU.ActiveCfg = Release|Any CPU - {AE451719-9FDC-4C53-A34A-2788D564A1E3}.Release|Any CPU.Build.0 = Release|Any CPU - {0B436044-9251-4922-BC41-51365EBBD771}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {0B436044-9251-4922-BC41-51365EBBD771}.Debug|Any CPU.Build.0 = Debug|Any CPU - {0B436044-9251-4922-BC41-51365EBBD771}.Release|Any CPU.ActiveCfg = Release|Any CPU - {0B436044-9251-4922-BC41-51365EBBD771}.Release|Any CPU.Build.0 = Release|Any CPU - {FD8900C4-1EB6-4D8A-A91C-32047D27A430}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {FD8900C4-1EB6-4D8A-A91C-32047D27A430}.Debug|Any CPU.Build.0 = Debug|Any CPU - {FD8900C4-1EB6-4D8A-A91C-32047D27A430}.Release|Any CPU.ActiveCfg = Release|Any CPU - {FD8900C4-1EB6-4D8A-A91C-32047D27A430}.Release|Any CPU.Build.0 = Release|Any CPU - {9114D372-999B-4894-9460-8A0FF02131E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {9114D372-999B-4894-9460-8A0FF02131E1}.Debug|Any CPU.Build.0 = Debug|Any CPU - {9114D372-999B-4894-9460-8A0FF02131E1}.Release|Any CPU.ActiveCfg = Release|Any CPU - {9114D372-999B-4894-9460-8A0FF02131E1}.Release|Any CPU.Build.0 = Release|Any CPU - {549BAAA1-9355-41D7-9755-BF30CB92E4FA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {549BAAA1-9355-41D7-9755-BF30CB92E4FA}.Debug|Any CPU.Build.0 = Debug|Any CPU - {549BAAA1-9355-41D7-9755-BF30CB92E4FA}.Release|Any CPU.ActiveCfg = Release|Any CPU - {549BAAA1-9355-41D7-9755-BF30CB92E4FA}.Release|Any CPU.Build.0 = Release|Any CPU - {EE5D4296-DFD7-4D1B-B9F9-C43AD9ED4F6F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {EE5D4296-DFD7-4D1B-B9F9-C43AD9ED4F6F}.Debug|Any CPU.Build.0 = Debug|Any CPU - {EE5D4296-DFD7-4D1B-B9F9-C43AD9ED4F6F}.Release|Any CPU.ActiveCfg = Release|Any CPU - {EE5D4296-DFD7-4D1B-B9F9-C43AD9ED4F6F}.Release|Any CPU.Build.0 = Release|Any CPU - {B3AB773A-BCF6-4679-AC13-E2879F61DF33}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B3AB773A-BCF6-4679-AC13-E2879F61DF33}.Debug|Any CPU.Build.0 = Debug|Any CPU - {B3AB773A-BCF6-4679-AC13-E2879F61DF33}.Release|Any CPU.ActiveCfg = Release|Any CPU - {B3AB773A-BCF6-4679-AC13-E2879F61DF33}.Release|Any CPU.Build.0 = Release|Any CPU - {8A002565-996A-45F9-8D74-89E8D272717F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {8A002565-996A-45F9-8D74-89E8D272717F}.Debug|Any CPU.Build.0 = Debug|Any CPU - {8A002565-996A-45F9-8D74-89E8D272717F}.Release|Any CPU.ActiveCfg = Release|Any CPU - {8A002565-996A-45F9-8D74-89E8D272717F}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(NestedProjects) = preSolution - {EE5D4296-DFD7-4D1B-B9F9-C43AD9ED4F6F} = {E77D6350-0CCF-11EB-A5F5-69BE9D4F31C9} - {9114D372-999B-4894-9460-8A0FF02131E1} = {E77D6350-0CCF-11EB-A5F5-69BE9D4F31C9} - {549BAAA1-9355-41D7-9755-BF30CB92E4FA} = {E77D6350-0CCF-11EB-A5F5-69BE9D4F31C9} - EndGlobalSection -EndGlobal diff --git a/src/Eto.Mac/Forms/Controls/GridColumnHandler.cs b/src/Eto.Mac/Forms/Controls/GridColumnHandler.cs index 36b1e5ecd8..da32a035aa 100644 --- a/src/Eto.Mac/Forms/Controls/GridColumnHandler.cs +++ b/src/Eto.Mac/Forms/Controls/GridColumnHandler.cs @@ -59,6 +59,7 @@ public interface IDataColumnHandler : GridColumn.IHandler public class GridColumnHandler : MacObject, GridColumn.IHandler, IDataColumnHandler { Cell dataCell; + bool autoSize; static readonly object Font_Key = new object(); static readonly object WidthAdjust_Key = new object(); @@ -120,11 +121,10 @@ public nfloat GetPreferredWidth(NSRange? range = null) var outlineView = handler.Table as NSOutlineView; bool isOutlineColumn = outlineView != null && Column == 0; if (handler.ShowHeader) - { width = (nfloat)Math.Max(Control.HeaderCell.CellSizeForBounds(new CGRect(0, 0, int.MaxValue, int.MaxValue)).Width, width); - if (isOutlineColumn) - width += (float)outlineView.IndentationPerLevel; - } + + if (isOutlineColumn) + width += (float)outlineView.IndentationPerLevel; if (dataCell != null) { @@ -186,8 +186,16 @@ public bool Resizable public bool AutoSize { - get; - set; + get => autoSize; + set + { + if (autoSize != value) + { + autoSize = value; + if (autoSize && !IsLoaded) + Control.Width = Control.MinWidth; + } + } } public bool Sortable { get; set; } diff --git a/src/Eto.Mac/Forms/Controls/GridHandler.cs b/src/Eto.Mac/Forms/Controls/GridHandler.cs index 439ea9dacd..1068ea93c2 100644 --- a/src/Eto.Mac/Forms/Controls/GridHandler.cs +++ b/src/Eto.Mac/Forms/Controls/GridHandler.cs @@ -189,6 +189,7 @@ public abstract class GridHandler : MacControl Control; @@ -391,6 +392,13 @@ public override void OnLoadComplete(EventArgs e) var row = Widget.Properties.Get(GridHandler.ScrolledToRow_Key, 0); // Yosemite bug: hides first row when DataStore is set before control is visible, so we always call this Control.ScrollRowToVisible(row); + loadComplete = true; + } + + public override void OnUnLoad(EventArgs e) + { + base.OnUnLoad(e); + loadComplete = false; } NSRange autoSizeRange; @@ -692,21 +700,24 @@ public CGRect GetVisibleRect() protected override SizeF GetNaturalSize(SizeF availableSize) { - EnsureAutoSizedColumns(); - var width = ColumnHandlers.Sum(r => r.Control.Width); + var rowCount = RowCount; + var range = new NSRange(0, rowCount); + var loaded = loadComplete; + var width = ColumnHandlers.Sum(r => loaded ? r.Control.Width : r.GetPreferredWidth(range)); if (width == 0) width = 100; if (Border != BorderType.None) - width += 2; + width += ScrollView.FrameSizeForContentSize(new CGSize(0, 0), false, false).Width; var intercellSpacing = Control.IntercellSpacing; - width += Control.ColumnCount * intercellSpacing.Width; + width += (Control.ColumnCount - 1) * intercellSpacing.Width; + width += GetTableRowInsets(); - // it's okay to the hide last divider, it won't cause the control to scroll horizontally - width -= (int)Math.Round(intercellSpacing.Width / 3) - 1; + if (ScrollView.HasVerticalScroller && ScrollView.VerticalScroller.ScrollerStyle == NSScrollerStyle.Legacy) + width += NSScroller.GetScrollerWidth(ScrollView.VerticalScroller.ControlSize, ScrollView.VerticalScroller.ScrollerStyle); - var height = (int)((RowHeight + intercellSpacing.Height) * RowCount); + var height = (int)((RowHeight + intercellSpacing.Height) * rowCount); if (ShowHeader) height += 2 + (int)Control.HeaderView.Frame.Height; return new SizeF((float)width, height); diff --git a/test/Eto.Test.Mac/UnitTests/GridViewTests.cs b/test/Eto.Test.Mac/UnitTests/GridViewTests.cs index 7f4f633e88..93330404aa 100644 --- a/test/Eto.Test.Mac/UnitTests/GridViewTests.cs +++ b/test/Eto.Test.Mac/UnitTests/GridViewTests.cs @@ -7,6 +7,8 @@ namespace Eto.Test.Mac.UnitTests public abstract class GridTests : TestBase where T: Grid, new() { + protected abstract Test.UnitTests.Forms.Controls.GridTests BaseGridTests { get; } + class GridTestItem : TreeGridItem { public string Text { get; set; } @@ -35,15 +37,20 @@ public IEnumerable CreateDataStore(int rows = 40) [TestCase(NSTableViewStyle.FullWidth, -1, 1)] [TestCase(NSTableViewStyle.FullWidth, -1, 3)] [TestCase(NSTableViewStyle.FullWidth, 3, 3)] + [TestCase(NSTableViewStyle.FullWidth, 0, 3)] [TestCase(NSTableViewStyle.Inset, -1, 1)] [TestCase(NSTableViewStyle.Inset, -1, 3)] [TestCase(NSTableViewStyle.Inset, 3, 3)] + [TestCase(NSTableViewStyle.Inset, 0, 3)] [TestCase(NSTableViewStyle.SourceList, -1, 1)] [TestCase(NSTableViewStyle.SourceList, -1, 3)] [TestCase(NSTableViewStyle.SourceList, 3, 3)] + [TestCase(NSTableViewStyle.SourceList, 0, 3)] [TestCase(NSTableViewStyle.Plain, -1, 1)] [TestCase(NSTableViewStyle.Plain, -1, 3)] + [TestCase(NSTableViewStyle.Plain, 20, 3)] [TestCase(NSTableViewStyle.Plain, 3, 3)] + [TestCase(NSTableViewStyle.Plain, 0, 3)] public void ScrollingExpandedColumnShouldKeepItsSize(NSTableViewStyle style, int intercellSpacing, int numColumns) { ManualForm("Scrolling should not cause the widths of the columns to go beyond the width of the grid,\nso the horizontal scrollbar should never show up.", form => @@ -51,19 +58,7 @@ public void ScrollingExpandedColumnShouldKeepItsSize(NSTableViewStyle style, int form.Title = $"TesNSTableViewStyle: {style}"; var grid = new T(); grid.Height = 200; - if (grid.ControlObject is NSTableView tableView) - { - if (ObjCExtensions.InstancesRespondToSelector(Selector.GetHandle("style"))) - tableView.Style = style; - else - { - // macos 10.15 and older - if (style == NSTableViewStyle.SourceList) - tableView.SelectionHighlightStyle = NSTableViewSelectionHighlightStyle.SourceList; - } - if (intercellSpacing >= 0) - tableView.IntercellSpacing = new CGSize(intercellSpacing, 2); - } + SetParameters(style, intercellSpacing, grid); SetDataStore(grid, CreateDataStore()); @@ -78,17 +73,55 @@ public void ScrollingExpandedColumnShouldKeepItsSize(NSTableViewStyle style, int return grid; }); } + + private static void SetParameters(NSTableViewStyle style, int intercellSpacing, T grid) + { + if (grid.ControlObject is NSTableView tableView) + { + if (ObjCExtensions.InstancesRespondToSelector(Selector.GetHandle("style"))) + tableView.Style = style; + else + { + // macos 10.15 and older + if (style == NSTableViewStyle.SourceList) + tableView.SelectionHighlightStyle = NSTableViewSelectionHighlightStyle.SourceList; + } + if (intercellSpacing >= 0) + tableView.IntercellSpacing = new CGSize(intercellSpacing, 2); + } + } + + [ManualTest] + [TestCase(NSTableViewStyle.FullWidth, -1, "Some Text", 100)] + [TestCase(NSTableViewStyle.FullWidth, -1, "Some Much Longer Text That Should Still Work", 100)] + [TestCase(NSTableViewStyle.Inset, -1, "Some Text", 100)] + [TestCase(NSTableViewStyle.Inset, -1, "Some Much Longer Text That Should Still Work", 100)] + [TestCase(NSTableViewStyle.SourceList, -1, "Some Text", 100)] + [TestCase(NSTableViewStyle.SourceList, -1, "Some Much Longer Text That Should Still Work", 100)] + [TestCase(NSTableViewStyle.Plain, -1, "Some Text", 100)] + [TestCase(NSTableViewStyle.Plain, -1, "Some Much Longer Text That Should Still Work", 100)] + [TestCase(NSTableViewStyle.Plain, 20, "Some Text", 100)] + [TestCase(NSTableViewStyle.Plain, 3, "Some Text", 100)] + [TestCase(NSTableViewStyle.Plain, 0, "Some Much Longer Text That Should Still Work", 100)] + public void AutoSizedColumnShouldChangeSizeOfControl(NSTableViewStyle style, int intercellSpacing, string text, int rows) + { + BaseGridTests.AutoSizedColumnShouldChangeSizeOfControl(text, rows, grid => { + SetParameters(style, intercellSpacing, grid); + }); + } } [TestFixture] public class GridViewTests : GridTests { + protected override Test.UnitTests.Forms.Controls.GridTests BaseGridTests => new Test.UnitTests.Forms.Controls.GridViewTests(); protected override void SetDataStore(GridView grid, IEnumerable dataStore) => grid.DataStore = dataStore; } [TestFixture] public class TreeGridViewTests : GridTests { + protected override Test.UnitTests.Forms.Controls.GridTests BaseGridTests => new Test.UnitTests.Forms.Controls.TreeGridViewTests(); protected override void SetDataStore(TreeGridView grid, IEnumerable dataStore) => grid.DataStore = (ITreeGridStore)dataStore; } } \ No newline at end of file diff --git a/test/Eto.Test/UnitTests/Forms/Controls/GridTests.cs b/test/Eto.Test/UnitTests/Forms/Controls/GridTests.cs index fdf05794e6..83884c2bf0 100644 --- a/test/Eto.Test/UnitTests/Forms/Controls/GridTests.cs +++ b/test/Eto.Test/UnitTests/Forms/Controls/GridTests.cs @@ -395,5 +395,67 @@ public void CustomCellShouldGetMouseEvents() Assert.AreEqual(4, mode, "Mode should be 4 after going through all steps"); } + [ManualTest] + [TestCase("Some Text", 1)] + [TestCase("Some Text", 100)] + [TestCase("Some Much Longer Text That Should Still Work", 1)] + [TestCase("Some Much Longer Text That Should Still Work", 100)] + [TestCase("Short", 1)] + [TestCase("Short", 100)] + public void AutoSizedColumnShouldChangeSizeOfControl(string text, int rows) => AutoSizedColumnShouldChangeSizeOfControl(text, rows, null); + + public void AutoSizedColumnShouldChangeSizeOfControl(string text, int rows, Action customize) + { + ManualForm("GridView should auto size to the\ncolumn content and not scroll horizontally", form => + { + var gridView = new T + { + Height = 180, + }; + customize?.Invoke(gridView); + gridView.Columns.Add(new GridColumn + { + AutoSize = true, + DataCell = new TextBoxCell { Binding = Binding.Property((DataItem m) => m.TextValue) } + }); + + var collection = new TreeGridItemCollection(); + SetDataStore(gridView, collection); + DataItem mainItem = null; + for (int i = 0; i < rows; i++) + { + var item = new DataItem { TextValue = text }; + collection.Add(item); + if (mainItem == null) + mainItem = item; + } + + var textBox = new TextBox(); + textBox.Focus(); + textBox.TextBinding.Bind(mainItem, i => i.TextValue); + textBox.TextChanged += (sender, e) => + { + if (gridView is GridView gv) + gv.ReloadData(0); + else if (gridView is TreeGridView tgv) + tgv.ReloadItem(mainItem); + }; + + var layout = new DynamicLayout(); + layout.BeginVertical(yscale: true); + layout.AddRow(gridView, null); // gridView is auto sized + layout.EndVertical(); + + layout.AddSeparateRow("Text:", textBox); + + return layout; + }); + } + + [Test, ManualTest] + public void AutoSizedColumnShouldReportCorrectPreferredSize() + { + } + } } diff --git a/test/Eto.Test/UnitTests/Forms/Controls/GridViewTests.cs b/test/Eto.Test/UnitTests/Forms/Controls/GridViewTests.cs index b64b11e27d..287e71c9f5 100755 --- a/test/Eto.Test/UnitTests/Forms/Controls/GridViewTests.cs +++ b/test/Eto.Test/UnitTests/Forms/Controls/GridViewTests.cs @@ -142,43 +142,6 @@ public void CollectionChangedWithResetShouldShowItems() } - [Test, ManualTest] - public void AutoSizedColumnShouldChangeSizeOfControl() - { - ManualForm("GridView should auto size to content", form => - { - var collection = new ObservableCollection(); - var gridView = new GridView - { - Height = 180, - DataStore = collection, - Columns = - { - new GridColumn - { - AutoSize = true, - DataCell = new TextBoxCell { Binding = Binding.Property((DataItem m) => m.TextValue) } - } - } - }; - var item = new DataItem { TextValue = "Some Text" }; - collection.Add(item); - - var textBox = new TextBox(); - textBox.Focus(); - textBox.TextBinding.Bind(item, i => i.TextValue); - textBox.TextChanged += (sender, e) => gridView.ReloadData(0); - - var layout = new DynamicLayout(); - layout.BeginVertical(yscale: true); - layout.AddRow(gridView, null); // gridView is auto sized - layout.EndVertical(); - - layout.AddSeparateRow("Text:", textBox); - - return layout; - }); - } class CustomCellWithTableLayout : CustomCell diff --git a/test/Eto.Test/UnitTests/Forms/GridViewUtils.cs b/test/Eto.Test/UnitTests/Forms/GridViewUtils.cs index 3dc375e6ff..3f080d6e46 100644 --- a/test/Eto.Test/UnitTests/Forms/GridViewUtils.cs +++ b/test/Eto.Test/UnitTests/Forms/GridViewUtils.cs @@ -1,10 +1,15 @@ namespace Eto.Test.UnitTests.Forms { - class DataItem + class DataItem : ITreeGridItem { public string TextValue { get; set; } public int Id { get; private set; } + public bool Expanded { get; set; } + + public bool Expandable => false; + + public ITreeGridItem Parent { get; set; } public DataItem() {