diff options
Diffstat (limited to 'Xamarin.PropertyEditing.Mac')
8 files changed, 144 insertions, 153 deletions
diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/BrushTabViewController.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/BrushTabViewController.cs index bde2128..08cea38 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/Custom/BrushTabViewController.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/BrushTabViewController.cs @@ -44,7 +44,7 @@ namespace Xamarin.PropertyEditing.Mac set { ViewModel = (BrushPropertyViewModel)value; } } - NSView IEditorView.NativeView => View; + NSView INativeContainer.NativeView => View; public bool IsDynamicallySized => false;
public bool NeedsPropertyButton => false; diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/CommonBrushView.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/CommonBrushView.cs index 0201795..9f4531f 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/Custom/CommonBrushView.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/CommonBrushView.cs @@ -13,7 +13,7 @@ namespace Xamarin.PropertyEditing.Mac set => (Layer as CommonBrushLayer).Brush = value; } - NSView IValueView.NativeView => this; + NSView INativeContainer.NativeView => this; public CommonBrushView (IHostResourceProvider hostResources) { diff --git a/Xamarin.PropertyEditing.Mac/Controls/EditorContainer.cs b/Xamarin.PropertyEditing.Mac/Controls/EditorContainer.cs index 643947d..9b39415 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/EditorContainer.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/EditorContainer.cs @@ -1,67 +1,17 @@ -using System; using AppKit; -using CoreGraphics; -using Foundation; using Xamarin.PropertyEditing.ViewModels; namespace Xamarin.PropertyEditing.Mac { internal class EditorContainer - : NSView + : PropertyContainer { public EditorContainer (IHostResourceProvider hostResources, IEditorView editorView) + : base (hostResources, editorView, editorView?.NeedsPropertyButton ?? false) { - if (hostResources == null) - throw new ArgumentNullException (nameof (hostResources)); - - EditorView = editorView; - - AddSubview (this.label); - - AddConstraints (new[] { - NSLayoutConstraint.Create (this.label, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this, NSLayoutAttribute.Right, Mac.Layout.GoldenRatioLeft, 0f), - NSLayoutConstraint.Create (this.label, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 18), - }); - - if (EditorView != null) { - AddSubview (EditorView.NativeView); - EditorView.NativeView.TranslatesAutoresizingMaskIntoConstraints = false; - - if (EditorView.NativeView is PropertyEditorControl pec && pec.FirstKeyView != null) { - AddConstraint (NSLayoutConstraint.Create (this.label, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, pec.FirstKeyView, NSLayoutAttribute.CenterY, 1, 0)); - } else { - AddConstraint (NSLayoutConstraint.Create (this.label, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1, 3)); - } - - AddConstraints (new[] { - NSLayoutConstraint.Create (EditorView.NativeView, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1f, 0f), - NSLayoutConstraint.Create (EditorView.NativeView, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this.label, NSLayoutAttribute.Right, 1f, LabelToControlSpacing), - NSLayoutConstraint.Create (EditorView.NativeView, NSLayoutAttribute.Height, NSLayoutRelation.Equal, this, NSLayoutAttribute.Height, 1f, 0) - }); - - if (editorView.NeedsPropertyButton) { - this.propertyButton = new PropertyButton (hostResources) { - TranslatesAutoresizingMaskIntoConstraints = false - }; - - AddSubview (this.propertyButton); - AddConstraints (new[] { - NSLayoutConstraint.Create (this.propertyButton, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this.label, NSLayoutAttribute.CenterY, 1, 0), - NSLayoutConstraint.Create (EditorView.NativeView, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this.propertyButton, NSLayoutAttribute.Left, 1f, -EditorToButtonSpacing), - NSLayoutConstraint.Create (this.propertyButton, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this, NSLayoutAttribute.Right, 1f, -ButtonToWallSpacing), - NSLayoutConstraint.Create (this.propertyButton, NSLayoutAttribute.Width, NSLayoutRelation.Equal, 1f, PropertyButton.DefaultSize), - }); - } else { - AddConstraint (NSLayoutConstraint.Create (EditorView.NativeView, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this, NSLayoutAttribute.Right, 1f, 0f)); - } - } else { - AddConstraint (NSLayoutConstraint.Create (this.label, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1, 0)); - } } - public IEditorView EditorView { - get; - } + public IEditorView EditorView => (IEditorView)NativeContainer; public EditorViewModel ViewModel { @@ -72,15 +22,7 @@ namespace Xamarin.PropertyEditing.Mac return; EditorView.ViewModel = value; - this.propertyButton.ViewModel = value as PropertyViewModel; - } - } - - public string Label { - get { return this.label.StringValue; } - set { - this.label.StringValue = value + ":"; - this.label.ToolTip = value; + PropertyButton.ViewModel = value as PropertyViewModel; } } @@ -120,30 +62,13 @@ namespace Xamarin.PropertyEditing.Mac base.ViewWillMoveToSuperview (newSuperview); } - private UnfocusableTextField label = new UnfocusableTextField { - Alignment = NSTextAlignment.Right, - Cell = { - LineBreakMode = NSLineBreakMode.TruncatingHead, - }, - TranslatesAutoresizingMaskIntoConstraints = false, - }; - #if DEBUG // Currently only used to highlight which controls haven't been implemented public NSColor LabelTextColor { - set { this.label.TextColor = value; } + set { LabelControl.TextColor = value; } } #endif - - internal const float LabelToControlSpacing = 13f; - internal static float PropertyTotalWidth => PropertyButton.DefaultSize + ButtonToWallSpacing + EditorToButtonSpacing; - private NSView leftEdgeView; private NSLayoutConstraint leftEdgeLeftConstraint, leftEdgeVCenterConstraint; - private readonly IHostResourceProvider hostResources; - private readonly PropertyButton propertyButton; - - private const float EditorToButtonSpacing = 4f; - private const float ButtonToWallSpacing = 9f; } } diff --git a/Xamarin.PropertyEditing.Mac/Controls/GroupEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/GroupEditorControl.cs index d43b56c..7b6ada3 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/GroupEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/GroupEditorControl.cs @@ -26,9 +26,11 @@ namespace Xamarin.PropertyEditing.Mac AutoresizingMask = NSViewResizingMask.HeightSizable | NSViewResizingMask.WidthSizable }; - this.table = new GroupedTableView { RowHeight = 24 }; - this.table.AddColumn (new NSTableColumn (PropertyIdentifier)); - this.table.AddColumn (new NSTableColumn (PreviewIdentifier)); + this.table = new GroupedTableView { + RowHeight = 24, + IntercellSpacing = new CGSize (0, 0) + }; + this.table.AddColumn (new NSTableColumn ()); this.container.AddView (this.table, NSStackViewGravity.Top); this.host = new NSBox { @@ -46,7 +48,7 @@ namespace Xamarin.PropertyEditing.Mac ViewDidChangeEffectiveAppearance (); } - NSView IEditorView.NativeView => this; + NSView INativeContainer.NativeView => this; EditorViewModel IEditorView.ViewModel { @@ -101,10 +103,6 @@ namespace Xamarin.PropertyEditing.Mac } } - private const string PropertyIdentifier = "property"; - private const string PreviewIdentifier = "preview"; - private const string ButtonIdentifier = "button"; - private readonly NSTableView table; private readonly NSStackView container; private readonly NSBox host; @@ -165,76 +163,46 @@ namespace Xamarin.PropertyEditing.Mac public override NSView GetViewForItem (NSTableView tableView, NSTableColumn tableColumn, nint row) { - if (!this.resized) { - var cols = tableView.TableColumns (); - cols[0].Width = (tableView.Frame.Width + 45) * Mac.Layout.GoldenRatioLeft; - cols[1].Width = tableView.Frame.Width - cols[0].Width; - this.resized = true; - } - PropertyViewModel pvm = ViewModel.Properties[(int)row]; - switch (tableColumn.Identifier) { - case PropertyIdentifier: - return new UnfocusableTextField { StringValue = pvm.Property.Name + ":", Alignment = NSTextAlignment.Right }; - case PreviewIdentifier: - return GetPreview (tableView, pvm); - } - - return null; - } - - public override void SelectionDidChange (NSNotification notification) - { - this.host.UpdateHosted (); - } - - private readonly GroupEditorControl host; - private readonly PropertyInlinePreviewSelector selector = new PropertyInlinePreviewSelector (); - private bool resized; - - private NSView GetPreview (NSTableView table, PropertyViewModel pvm) - { - string identifier = pvm.GetType().FullName; - PreviewView view = table.MakeView (identifier, table) as PreviewView; + string identifier = pvm.GetType ().FullName; + var view = tableView.MakeView (identifier, tableView) as PreviewView; if (view == null) { IValueView valueView = this.selector.CreateView (this.host.hostResources, pvm.Property.Type); if (valueView == null) return new NSView (); - - view = new PreviewView (this.host.hostResources, valueView, new CGRect (0, 0, table.TableColumns ()[1].Width, table.RowHeight)) { + + view = new PreviewView (this.host.hostResources, valueView) { Identifier = identifier }; } + view.Label = pvm.Name; view.ViewModel = pvm; return view; } + + public override void SelectionDidChange (NSNotification notification) + { + this.host.UpdateHosted (); + } + + private readonly GroupEditorControl host; + private readonly PropertyInlinePreviewSelector selector = new PropertyInlinePreviewSelector (); } private class PreviewView - : NSView + : PropertyContainer { - public PreviewView (IHostResourceProvider hostResources, IValueView valueView, CGRect frame) + public PreviewView (IHostResourceProvider hostResources, IValueView valueView) + : base (hostResources, valueView, includePropertyButton: true, vertInset: -6f) { - Frame = frame; - this.view = valueView; - valueView.NativeView.Frame = new CGRect (0, 3, frame.Width - PropertyButton.DefaultSize, frame.Height - 6); - valueView.NativeView.AutoresizingMask = NSViewResizingMask.WidthSizable | NSViewResizingMask.HeightSizable; - AddSubview (valueView.NativeView); - - this.propertyButton = new PropertyButton (hostResources) { - Frame = new CGRect (valueView.NativeView.Frame.Width, 0, PropertyButton.DefaultSize, 24), - AutoresizingMask = NSViewResizingMask.MinXMargin - }; - - AddSubview (this.propertyButton); } public PropertyViewModel ViewModel { - get { return this.propertyButton.ViewModel; } + get { return this.vm; } set { if (this.vm == value) @@ -244,15 +212,17 @@ namespace Xamarin.PropertyEditing.Mac this.vm.PropertyChanged -= OnPropertyChanged; this.vm = value; - this.view.SetValue (((IPropertyValue)this.vm).Value); - this.vm.PropertyChanged += OnPropertyChanged; - this.propertyButton.ViewModel = value; + if (this.vm != null) { + this.view.SetValue (((IPropertyValue)this.vm).Value); + this.vm.PropertyChanged += OnPropertyChanged; + } + + PropertyButton.ViewModel = value; } } private PropertyViewModel vm; private IValueView view; - private PropertyButton propertyButton; private void OnPropertyChanged (object sender, PropertyChangedEventArgs e) { diff --git a/Xamarin.PropertyEditing.Mac/Controls/IEditorView.cs b/Xamarin.PropertyEditing.Mac/Controls/IEditorView.cs index 7d3f9fb..a7ac0d1 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/IEditorView.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/IEditorView.cs @@ -6,24 +6,27 @@ using Xamarin.PropertyEditing.ViewModels; namespace Xamarin.PropertyEditing.Mac { internal interface IEditorView + : INativeContainer { - /// <summary> - /// Gets the native view. - /// </summary> - /// <value>Generally just `this`.</value> - NSView NativeView { get; } - EditorViewModel ViewModel { get; set; } -
+ bool NeedsPropertyButton { get; } bool IsDynamicallySized { get; } nint GetHeight (EditorViewModel vm); }
internal interface IValueView
+ : INativeContainer
{
- NSView NativeView { get; }
-
void SetValue (object value);
} + + internal interface INativeContainer + { + /// <summary> + /// Gets the native view. + /// </summary> + /// <value>Generally just `this`.</value> + NSView NativeView { get; } + } } diff --git a/Xamarin.PropertyEditing.Mac/Controls/PropertyContainer.cs b/Xamarin.PropertyEditing.Mac/Controls/PropertyContainer.cs new file mode 100644 index 0000000..f2b212f --- /dev/null +++ b/Xamarin.PropertyEditing.Mac/Controls/PropertyContainer.cs @@ -0,0 +1,94 @@ +using System; +using AppKit; + +namespace Xamarin.PropertyEditing.Mac +{ + internal class PropertyContainer + : NSView + { + public PropertyContainer (IHostResourceProvider hostResources, INativeContainer nativeView, bool includePropertyButton, float vertInset = 0) + { + if (hostResources == null) + throw new ArgumentNullException (nameof (hostResources)); + + NativeContainer = nativeView; + + AddSubview (this.label); + + AddConstraints (new[] { + NSLayoutConstraint.Create (this.label, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this, NSLayoutAttribute.Right, Mac.Layout.GoldenRatioLeft, 0f), + NSLayoutConstraint.Create (this.label, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 18), + }); + + if (NativeContainer != null) { + AddSubview (NativeContainer.NativeView); + NativeContainer.NativeView.TranslatesAutoresizingMaskIntoConstraints = false; + + if (NativeContainer.NativeView is PropertyEditorControl pec && pec.FirstKeyView != null) { + AddConstraint (NSLayoutConstraint.Create (this.label, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, pec.FirstKeyView, NSLayoutAttribute.CenterY, 1, 0)); + } else { + AddConstraint (NSLayoutConstraint.Create (this.label, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1, 3)); + } + + AddConstraints (new[] { + NSLayoutConstraint.Create (NativeContainer.NativeView, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1f, 0f), + NSLayoutConstraint.Create (NativeContainer.NativeView, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this.label, NSLayoutAttribute.Right, 1f, LabelToControlSpacing), + NSLayoutConstraint.Create (NativeContainer.NativeView, NSLayoutAttribute.Height, NSLayoutRelation.Equal, this, NSLayoutAttribute.Height, 1f, vertInset) + }); + + if (includePropertyButton) { + this.propertyButton = new PropertyButton (hostResources) { + TranslatesAutoresizingMaskIntoConstraints = false + }; + + AddSubview (this.propertyButton); + AddConstraints (new[] { + NSLayoutConstraint.Create (this.propertyButton, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this.label, NSLayoutAttribute.CenterY, 1, 0), + NSLayoutConstraint.Create (NativeContainer.NativeView, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this.propertyButton, NSLayoutAttribute.Left, 1f, -EditorToButtonSpacing), + NSLayoutConstraint.Create (this.propertyButton, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this, NSLayoutAttribute.Right, 1f, -ButtonToWallSpacing), + NSLayoutConstraint.Create (this.propertyButton, NSLayoutAttribute.Width, NSLayoutRelation.Equal, 1f, PropertyButton.DefaultSize), + }); + } else { + AddConstraint (NSLayoutConstraint.Create (NativeContainer.NativeView, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this, NSLayoutAttribute.Right, 1f, 0f)); + } + } else { + AddConstraint (NSLayoutConstraint.Create (this.label, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1, 0)); + } + } + + public string Label + { + get { return this.label.StringValue; } + set + { + this.label.StringValue = value + ":"; + this.label.ToolTip = value; + } + } + + protected INativeContainer NativeContainer + { + get; + } + + protected UnfocusableTextField LabelControl => this.label; + + protected PropertyButton PropertyButton => this.propertyButton; + + internal const float LabelToControlSpacing = 13f; + internal static float PropertyTotalWidth => PropertyButton.DefaultSize + ButtonToWallSpacing + EditorToButtonSpacing; + + private const float EditorToButtonSpacing = 4f; + private const float ButtonToWallSpacing = 9f; + + private readonly IHostResourceProvider hostResources; + private readonly PropertyButton propertyButton; + private readonly UnfocusableTextField label = new UnfocusableTextField { + Alignment = NSTextAlignment.Right, + Cell = { + LineBreakMode = NSLineBreakMode.TruncatingHead, + }, + TranslatesAutoresizingMaskIntoConstraints = false, + }; + } +} diff --git a/Xamarin.PropertyEditing.Mac/Controls/PropertyEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/PropertyEditorControl.cs index acd208c..429d014 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/PropertyEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/PropertyEditorControl.cs @@ -1,7 +1,5 @@ using System; -using System.Collections; using AppKit; -using CoreGraphics; using Foundation; using Xamarin.PropertyEditing.ViewModels; @@ -63,7 +61,7 @@ namespace Xamarin.PropertyEditing.Mac set { ViewModel = (PropertyViewModel)value; } } - NSView IEditorView.NativeView => this; + NSView INativeContainer.NativeView => this; [Export ("_primitiveSetDefaultNextKeyView:")] public void SetDefaultNextKeyView (NSView child) diff --git a/Xamarin.PropertyEditing.Mac/Xamarin.PropertyEditing.Mac.csproj b/Xamarin.PropertyEditing.Mac/Xamarin.PropertyEditing.Mac.csproj index 2884194..0a63541 100644 --- a/Xamarin.PropertyEditing.Mac/Xamarin.PropertyEditing.Mac.csproj +++ b/Xamarin.PropertyEditing.Mac/Xamarin.PropertyEditing.Mac.csproj @@ -154,6 +154,7 @@ <Compile Include="Controls\Custom\FocusablePopupButton.cs" />
<Compile Include="Controls\Custom\FocusableBooleanButton.cs" />
<Compile Include="Controls\Custom\FocusableButton.cs" />
+ <Compile Include="Controls\PropertyContainer.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="Controls\" />
|