Skip to content
This repository has been archived by the owner on Sep 4, 2024. It is now read-only.

Commit

Permalink
[Mac] Fix ListBox column autosizing
Browse files Browse the repository at this point in the history
Remove deprecated column sizing code, since column sizing
is now handled by the base backend code (changed in #662)

(fixes #765)
  • Loading branch information
sevoku committed Jan 3, 2018
1 parent fa9239a commit a831761
Showing 1 changed file with 0 additions and 32 deletions.
32 changes: 0 additions & 32 deletions Xwt.XamMac/Xwt.Mac/ListBoxBackend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,38 +64,6 @@ public void SetViews (CellViewCollection views)
column.Views.Add (v);
UpdateColumn (column, columnHandle, ListViewColumnChange.Cells);
}

public override void SetSource (IListDataSource source, IBackend sourceBackend)
{
base.SetSource (source, sourceBackend);

source.RowInserted += HandleColumnSizeChanged;
source.RowDeleted += HandleColumnSizeChanged;
source.RowChanged += HandleColumnSizeChanged;
ResetColumnSize (source);
}

void HandleColumnSizeChanged (object sender, ListRowEventArgs e)
{
var source = (IListDataSource)sender;
ResetColumnSize (source);
}

void ResetColumnSize (IListDataSource source)
{
// Calculate size of column
// This is how Apple implements it; unfortunately, they don't expose this functionality in the API.
// https://developer.apple.com/library/mac/documentation/Cocoa/Reference/NSTableViewDelegate_Protocol/index.html#//apple_ref/occ/intfm/NSTableViewDelegate/tableView:sizeToFitWidthOfColumn:
nfloat w = 0;
for (var row = 0; row < source.RowCount; row++) {
using (var cell = Table.GetCell (0, row)) {
var size = cell.CellSize;
w = (nfloat)Math.Max (w, size.Width);
}
}
columnHandle.MinWidth = (nfloat)Math.Ceiling (w);
columnHandle.Width = (nfloat)Math.Ceiling (w);
}
}
}

0 comments on commit a831761

Please sign in to comment.