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: Fix ListBox.GetPreferredSize() to return correct sizes #2635

Merged
Merged
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
24 changes: 8 additions & 16 deletions src/Eto.Mac/Forms/Controls/ListBoxHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -334,28 +334,20 @@ protected override SizeF GetNaturalSize(SizeF availableSize)

var intercellSpacing = Control.IntercellSpacing;
var count = Control.RowCount;
var height = (int)((Control.RowHeight + intercellSpacing.Height) * count);

// we need to go through each item to calculate its preferred size
var size = new CGSize(0, height);
var cell = new MacImageTextView();
var font = Font.ToNS();
if (font != null)
cell.TextField.Font = font;
var dataSource = Control.DataSource;
var column = Control.TableColumns()[0];
var size = new CGSize(0, intercellSpacing.Height * count);
for (nint i = 0; i < count; i++)
{
var data = dataSource.GetObjectValue(Control, column, i) as MacImageData;
if (data != null)
{
cell.TextField.ObjectValue = data.Text;
cell.Image = data.Image;
size.Width = (nfloat)Math.Max(size.Width, cell.FittingSize.Width);
}
var fittingSize = Control.GetCell(0, i).CellSize;
size.Width = (nfloat)Math.Max(size.Width, fittingSize.Width);
size.Height += fittingSize.Height;
}

var frameSize = scroll.FrameSizeForContentSize(size, false, false);
var hbar = size.Width > availableSize.Width;
var vbar = size.Height > availableSize.Height;

var frameSize = scroll.FrameSizeForContentSize(size, hbar, vbar);

var etoFrameSize = frameSize.ToEto();

Expand Down
Loading