Skip to content

Commit

Permalink
Mac: Fix ListBox.GetPreferredSize() to return correct sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
cwensley committed Mar 25, 2024
1 parent 868ffe8 commit 6012c5c
Showing 1 changed file with 8 additions and 16 deletions.
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

0 comments on commit 6012c5c

Please sign in to comment.