diff options
Diffstat (limited to 'Xamarin.Forms.Platform.MacOS/Cells/CellRenderer.cs')
-rw-r--r-- | Xamarin.Forms.Platform.MacOS/Cells/CellRenderer.cs | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/Xamarin.Forms.Platform.MacOS/Cells/CellRenderer.cs b/Xamarin.Forms.Platform.MacOS/Cells/CellRenderer.cs new file mode 100644 index 00000000..54e540a6 --- /dev/null +++ b/Xamarin.Forms.Platform.MacOS/Cells/CellRenderer.cs @@ -0,0 +1,68 @@ +using System; +using AppKit; +using CoreGraphics; + +namespace Xamarin.Forms.Platform.MacOS +{ + public class CellRenderer : IRegisterable + { + static readonly BindableProperty s_realCellProperty = BindableProperty.CreateAttached("RealCell", typeof(NSView), + typeof(Cell), null); + + EventHandler _onForceUpdateSizeRequested; + + public virtual NSView GetCell(Cell item, NSView reusableView, NSTableView tv) + { + var tvc = reusableView as CellNSView ?? new CellNSView(NSTableViewCellStyle.Default); + + tvc.Cell = item; + + WireUpForceUpdateSizeRequested(item, tvc, tv); + + tvc.TextLabel.StringValue = item.ToString(); + + UpdateBackground(tvc, item); + + return tvc; + } + + protected void UpdateBackground(NSView tableViewCell, Cell cell) + { + tableViewCell.WantsLayer = true; + var bgColor = NSColor.White; + var element = cell.RealParent as VisualElement; + if (element != null) + bgColor = element.BackgroundColor == Color.Default ? bgColor : element.BackgroundColor.ToNSColor(); + + UpdateBackgroundChild(cell, bgColor); + + tableViewCell.Layer.BackgroundColor = bgColor.CGColor; + } + + protected void WireUpForceUpdateSizeRequested(ICellController cell, NSView nativeCell, NSTableView tableView) + { + cell.ForceUpdateSizeRequested -= _onForceUpdateSizeRequested; + + _onForceUpdateSizeRequested = (sender, e) => + { + //TODO: Implement ForceUpdateSize + }; + + cell.ForceUpdateSizeRequested += _onForceUpdateSizeRequested; + } + + internal virtual void UpdateBackgroundChild(Cell cell, NSColor backgroundColor) + { + } + + internal static NSView GetRealCell(BindableObject cell) + { + return (NSView)cell.GetValue(s_realCellProperty); + } + + internal static void SetRealCell(BindableObject cell, NSView renderer) + { + cell.SetValue(s_realCellProperty, renderer); + } + } +}
\ No newline at end of file |