Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mac: Add border size to Tree/GridView preferred height #2562

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions src/Eto.Mac/Forms/Controls/GridHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -703,24 +703,30 @@ protected override SizeF GetNaturalSize(SizeF availableSize)
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;
var size = new SizeF();
size.Width = (float)ColumnHandlers.Sum(r => loaded ? r.Control.Width : r.GetPreferredWidth(range));
if (size.Width == 0)
size.Width = 100;

if (Border != BorderType.None)
width += ScrollView.FrameSizeForContentSize(new CGSize(0, 0), false, false).Width;
size += ScrollView.FrameSizeForContentSize(new CGSize(0, 0), false, false).ToEto();

var intercellSpacing = Control.IntercellSpacing;
width += (Control.ColumnCount - 1) * intercellSpacing.Width;
width += GetTableRowInsets();
size.Width += (Control.ColumnCount - 1) * (float)intercellSpacing.Width;
size.Width += (float)GetTableRowInsets();

var contentHeight = (float)((RowHeight + intercellSpacing.Height) * rowCount);
if (ScrollView.HasVerticalScroller && ScrollView.VerticalScroller.ScrollerStyle == NSScrollerStyle.Legacy)
width += NSScroller.GetScrollerWidth(ScrollView.VerticalScroller.ControlSize, ScrollView.VerticalScroller.ScrollerStyle);
{
if (!float.IsNaN(availableSize.Height) && contentHeight > availableSize.Height)
size.Width += (float)NSScroller.GetScrollerWidth(ScrollView.VerticalScroller.ControlSize, ScrollView.VerticalScroller.ScrollerStyle);
}

size.Height += contentHeight;

var height = (int)((RowHeight + intercellSpacing.Height) * rowCount);
if (ShowHeader)
height += 2 + (int)Control.HeaderView.Frame.Height;
return new SizeF((float)width, height);
size.Height += 2 + (int)Control.HeaderView.Frame.Height;
return size;
}

public void OnCellFormatting(GridCellFormatEventArgs args)
Expand Down
30 changes: 18 additions & 12 deletions test/Eto.Test.Mac/UnitTests/GridViewTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,20 +92,26 @@ private static void SetParameters(NSTableViewStyle style, int intercellSpacing,
}

[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.FullWidth, -1, "Some Text", 100, 180)]
[TestCase(NSTableViewStyle.FullWidth, -1, "Some Text", 15, -1)]
[TestCase(NSTableViewStyle.FullWidth, -1, "Some Much Longer Text That Should Still Work", 100, 180)]
[TestCase(NSTableViewStyle.Inset, -1, "Some Text", 100, 180)]
[TestCase(NSTableViewStyle.Inset, -1, "Some Text", 15, -1)]
[TestCase(NSTableViewStyle.Inset, -1, "Some Much Longer Text That Should Still Work", 100, 180)]
[TestCase(NSTableViewStyle.SourceList, -1, "Some Text", 100, 180)]
[TestCase(NSTableViewStyle.SourceList, -1, "Some Text", 15, -1)]
[TestCase(NSTableViewStyle.SourceList, -1, "Some Much Longer Text That Should Still Work", 100, 180)]
[TestCase(NSTableViewStyle.Plain, -1, "Some Text", 100, 180)]
[TestCase(NSTableViewStyle.Plain, -1, "Some Text", 15, -1)]
[TestCase(NSTableViewStyle.Plain, -1, "Some Much Longer Text That Should Still Work", 100, 180)]
[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)
[TestCase(NSTableViewStyle.Plain, 20, "Some Text", 15, -1)]
[TestCase(NSTableViewStyle.Plain, 3, "Some Text", 100, 180)]
[TestCase(NSTableViewStyle.Plain, 3, "Some Text", 15, -1)]
[TestCase(NSTableViewStyle.Plain, 0, "Some Much Longer Text That Should Still Work", 100, 180)]
public void AutoSizedColumnShouldChangeSizeOfControl(NSTableViewStyle style, int intercellSpacing, string text, int rows, int height)
{
BaseGridTests.AutoSizedColumnShouldChangeSizeOfControl(text, rows, grid => {
BaseGridTests.AutoSizedColumnShouldChangeSizeOfControl(text, rows, height, grid => {
SetParameters(style, intercellSpacing, grid);
});
}
Expand Down
39 changes: 19 additions & 20 deletions test/Eto.Test/UnitTests/Forms/Controls/GridTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -396,22 +396,27 @@ public void CustomCellShouldGetMouseEvents()
}

[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);
[TestCase("Some Text", 1, 180)]
[TestCase("Some Text", 15, -1)]
[TestCase("Some Text", 100, 180)]
[TestCase("Some Much Longer Text That Should Still Work", 1, 180)]
[TestCase("Some Much Longer Text That Should Still Work", 15, -1)]
[TestCase("Some Much Longer Text That Should Still Work", 100, 180)]
[TestCase("Short", 1, 180)]
[TestCase("Short", 15, -1)]
[TestCase("Short", 100, 180)]
public void AutoSizedColumnShouldChangeSizeOfControl(string text, int rows, int height) => AutoSizedColumnShouldChangeSizeOfControl(text, rows, height, null);

public void AutoSizedColumnShouldChangeSizeOfControl(string text, int rows, Action<T> customize)
public void AutoSizedColumnShouldChangeSizeOfControl(string text, int rows, int height, Action<T> customize)
{
ManualForm("GridView should auto size to the\ncolumn content and not scroll horizontally", form =>
ManualForm($"GridView should auto size to the\ncolumn content and not scroll horizontally{(height == -1 ? " or vertically" : "")}", form =>
{
var gridView = new T
{
Height = 180,
};
var gridView = new T();
if (height > 0)
gridView.Height = height;

gridView.ShowHeader = false;

customize?.Invoke(gridView);
gridView.Columns.Add(new GridColumn
{
Expand All @@ -420,7 +425,6 @@ public void AutoSizedColumnShouldChangeSizeOfControl(string text, int rows, Acti
});

var collection = new TreeGridItemCollection();
SetDataStore(gridView, collection);
DataItem mainItem = null;
for (int i = 0; i < rows; i++)
{
Expand All @@ -429,6 +433,7 @@ public void AutoSizedColumnShouldChangeSizeOfControl(string text, int rows, Acti
if (mainItem == null)
mainItem = item;
}
SetDataStore(gridView, collection);

var textBox = new TextBox();
textBox.Focus();
Expand All @@ -451,11 +456,5 @@ public void AutoSizedColumnShouldChangeSizeOfControl(string text, int rows, Acti
return layout;
});
}

[Test, ManualTest]
public void AutoSizedColumnShouldReportCorrectPreferredSize()
{
}

}
}
Loading