-
-
Notifications
You must be signed in to change notification settings - Fork 337
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2359 from cwensley/curtis/grid-column-autosizing
Mac: Fix issues autosizing columns in some cases
- Loading branch information
Showing
16 changed files
with
206 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Eto.Drawing; | ||
using Eto.Forms; | ||
using Eto.Mac; | ||
using Eto.Test.UnitTests; | ||
using NUnit.Framework; | ||
|
||
namespace Eto.Test.Mac.UnitTests | ||
{ | ||
public abstract class GridTests<T> : TestBase | ||
where T: Grid, new() | ||
{ | ||
class GridTestItem : TreeGridItem | ||
{ | ||
public string Text { get; set; } | ||
|
||
public Image Image { get; set; } | ||
|
||
public override string ToString() => Text ?? base.ToString(); | ||
} | ||
|
||
protected abstract void SetDataStore(T grid, IEnumerable<object> dataStore); | ||
|
||
public IEnumerable<object> CreateDataStore(int rows = 40) | ||
{ | ||
var list = new TreeGridItemCollection(); | ||
for (int i = 0; i < rows; i++) | ||
{ | ||
Image image = i % 2 == 0 ? (Image)TestIcons.Logo : (Image)TestIcons.TestImage; | ||
list.Add(new GridTestItem { Text = $"Item {i}", Image = image, Values = new[] { $"col {i}.2", $"col {i}.3", $"col {i}.4", $"col {i}.5" } }); | ||
} | ||
return list; | ||
} | ||
|
||
[ManualTest] | ||
[TestCase(NSTableViewStyle.FullWidth, -1, 1)] | ||
[TestCase(NSTableViewStyle.FullWidth, -1, 3)] | ||
[TestCase(NSTableViewStyle.FullWidth, 3, 3)] | ||
[TestCase(NSTableViewStyle.Inset, -1, 1)] | ||
[TestCase(NSTableViewStyle.Inset, -1, 3)] | ||
[TestCase(NSTableViewStyle.Inset, 3, 3)] | ||
[TestCase(NSTableViewStyle.SourceList, -1, 1)] | ||
[TestCase(NSTableViewStyle.SourceList, -1, 3)] | ||
[TestCase(NSTableViewStyle.SourceList, 3, 3)] | ||
[TestCase(NSTableViewStyle.Plain, -1, 1)] | ||
[TestCase(NSTableViewStyle.Plain, -1, 3)] | ||
[TestCase(NSTableViewStyle.Plain, 3, 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 => | ||
{ | ||
form.Title = $"TesNSTableViewStyle: {style}"; | ||
var grid = new T(); | ||
grid.Height = 200; | ||
if (grid.ControlObject is NSTableView tableView) | ||
{ | ||
if (ObjCExtensions.InstancesRespondToSelector<NSTableView>(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); | ||
} | ||
|
||
SetDataStore(grid, CreateDataStore()); | ||
|
||
grid.Columns.Add(new GridColumn { DataCell = new ImageTextCell { TextBinding = Binding.Property((GridTestItem m) => m.Text), ImageBinding = Binding.Property((GridTestItem m) => m.Image) } }); | ||
for (int i = 0; i < numColumns; i++) | ||
grid.Columns.Add(new GridColumn { DataCell = new TextBoxCell(i) }); | ||
|
||
var expandColumn = grid.Columns[0]; | ||
expandColumn.HeaderText = "Expanded"; | ||
expandColumn.Expand = true; | ||
|
||
return grid; | ||
}); | ||
} | ||
} | ||
|
||
[TestFixture] | ||
public class GridViewTests : GridTests<GridView> | ||
{ | ||
protected override void SetDataStore(GridView grid, IEnumerable<object> dataStore) => grid.DataStore = dataStore; | ||
} | ||
|
||
[TestFixture] | ||
public class TreeGridViewTests : GridTests<TreeGridView> | ||
{ | ||
protected override void SetDataStore(TreeGridView grid, IEnumerable<object> dataStore) => grid.DataStore = (ITreeGridStore<ITreeGridItem>)dataStore; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.