summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.MacOS/Cells/TextCellRenderer.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Xamarin.Forms.Platform.MacOS/Cells/TextCellRenderer.cs')
-rw-r--r--Xamarin.Forms.Platform.MacOS/Cells/TextCellRenderer.cs66
1 files changed, 66 insertions, 0 deletions
diff --git a/Xamarin.Forms.Platform.MacOS/Cells/TextCellRenderer.cs b/Xamarin.Forms.Platform.MacOS/Cells/TextCellRenderer.cs
new file mode 100644
index 0000000..6e36ce7
--- /dev/null
+++ b/Xamarin.Forms.Platform.MacOS/Cells/TextCellRenderer.cs
@@ -0,0 +1,66 @@
+´╗┐using System.ComponentModel;
+using AppKit;
+
+namespace Xamarin.Forms.Platform.MacOS
+{
+ public class TextCellRenderer : CellRenderer
+ {
+ static readonly Color s_defaultDetailColor = new Color(.32, .4, .57);
+ static readonly Color s_defaultTextColor = Color.Black;
+
+ public override NSView GetCell(Cell item, NSView reusableView, NSTableView tv)
+ {
+ var textCell = (TextCell)item;
+
+ var tvc = reusableView as CellNSView ?? new CellNSView(NSTableViewCellStyle.Subtitle);
+
+ if (tvc.Cell != null)
+ tvc.Cell.PropertyChanged -= tvc.HandlePropertyChanged;
+
+ tvc.Cell = textCell;
+ textCell.PropertyChanged += tvc.HandlePropertyChanged;
+ tvc.PropertyChanged = HandlePropertyChanged;
+
+ tvc.TextLabel.StringValue = textCell.Text ?? "";
+ tvc.DetailTextLabel.StringValue = textCell.Detail ?? "";
+ tvc.TextLabel.TextColor = textCell.TextColor.ToNSColor(s_defaultTextColor);
+ tvc.DetailTextLabel.TextColor = textCell.DetailColor.ToNSColor(s_defaultDetailColor);
+
+ WireUpForceUpdateSizeRequested(item, tvc, tv);
+
+ UpdateIsEnabled(tvc, textCell);
+
+ UpdateBackground(tvc, item);
+
+ return tvc;
+ }
+
+ protected virtual void HandlePropertyChanged(object sender, PropertyChangedEventArgs args)
+ {
+ var tvc = (CellNSView)sender;
+ var textCell = (TextCell)tvc.Cell;
+ if (args.PropertyName == TextCell.TextProperty.PropertyName)
+ {
+ tvc.TextLabel.StringValue = textCell.Text ?? "";
+ tvc.TextLabel.SizeToFit();
+ }
+ else if (args.PropertyName == TextCell.DetailProperty.PropertyName)
+ {
+ tvc.DetailTextLabel.StringValue = textCell.Detail ?? "";
+ tvc.DetailTextLabel.SizeToFit();
+ }
+ else if (args.PropertyName == TextCell.TextColorProperty.PropertyName)
+ tvc.TextLabel.TextColor = textCell.TextColor.ToNSColor(s_defaultTextColor);
+ else if (args.PropertyName == TextCell.DetailColorProperty.PropertyName)
+ tvc.DetailTextLabel.TextColor = textCell.DetailColor.ToNSColor(s_defaultTextColor);
+ else if (args.PropertyName == Cell.IsEnabledProperty.PropertyName)
+ UpdateIsEnabled(tvc, textCell);
+ }
+
+ static void UpdateIsEnabled(CellNSView cell, TextCell entryCell)
+ {
+ cell.TextLabel.Enabled = entryCell.IsEnabled;
+ cell.DetailTextLabel.Enabled = entryCell.IsEnabled;
+ }
+ }
+} \ No newline at end of file