diff --git a/Xamarin.PropertyEditing.Mac/Controls/BasePointEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/BasePointEditorControl.cs index e4b61f6a3..60f044073 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/BasePointEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/BasePointEditorControl.cs @@ -16,7 +16,7 @@ internal abstract class BasePointEditorControl : PropertyEditorControl XEditor; public override NSView LastKeyView => YEditor.DecrementButton; - protected override nint BaseHeight => 33; + protected override nint BaseHeight => 36; protected BasePointEditorControl (IHostResourceProvider hostResources) : base (hostResources) diff --git a/Xamarin.PropertyEditing.Mac/Controls/BaseRectangleEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/BaseRectangleEditorControl.cs index 5ba9d0191..e1289bb18 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/BaseRectangleEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/BaseRectangleEditorControl.cs @@ -22,7 +22,7 @@ internal abstract class BaseRectangleEditorControl : PropertyEditorControl XEditor; public override NSView LastKeyView => HeightEditor.DecrementButton; - protected override nint BaseHeight => 66; + protected override nint BaseHeight => 68; protected BaseRectangleEditorControl (IHostResourceProvider hostResources) : base (hostResources) diff --git a/Xamarin.PropertyEditing.Mac/Controls/EditorContainer.cs b/Xamarin.PropertyEditing.Mac/Controls/EditorContainer.cs index 5570c5a79..a02fb7563 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/EditorContainer.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/EditorContainer.cs @@ -17,6 +17,7 @@ public EditorContainer (IHostResourceProvider hostResources, IEditorView editorV } private const string FrameChangedObservableProperty = "frame"; + private readonly NSString observerKeyPath = new NSString (FrameChangedObservableProperty); public IEditorView EditorView => (IEditorView)NativeContainer; @@ -131,41 +132,43 @@ private void UpdateVariations () if (this.viewModelAsPropertyViewModel.HasVariations) { if (this.viewModelAsPropertyViewModel.IsVariant) { + this.deleteVariantButton = new VariationButton (HostResources, "pe-variation-delete-button-active-mac-10", "pe-variation-delete-button-mac-10") { + AccessibilityEnabled = true, + AccessibilityTitle = Properties.Resources.AccessibilityDeleteVariationButton, + Command = this.viewModelAsPropertyViewModel.RemoveVariationCommand, + ToolTip = Properties.Resources.RemoveVariant, + TranslatesAutoresizingMaskIntoConstraints = false, + }; - if (this.deleteVariantButton == null) { - this.deleteVariantButton = new VariationButton (HostResources, "pe-variation-delete-button-active-mac-10", "pe-variation-delete-button-mac-10") { - AccessibilityEnabled = true, - AccessibilityTitle = Properties.Resources.AccessibilityDeleteVariationButton, - Command = this.viewModelAsPropertyViewModel.RemoveVariationCommand, - ToolTip = Properties.Resources.RemoveVariant, - TranslatesAutoresizingMaskIntoConstraints = false, - }; + AddSubview (this.deleteVariantButton); + AddConstraints (new[] { + NSLayoutConstraint.Create (this.deleteVariantButton, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 8f), + NSLayoutConstraint.Create (this.deleteVariantButton, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, 20f), + }); - AddSubview (this.deleteVariantButton); - AddConstraints (new[] { - NSLayoutConstraint.Create (this.deleteVariantButton, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 8f), - NSLayoutConstraint.Create (this.deleteVariantButton, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, 20f), - }); + this.variationControlsList.Add (this.deleteVariantButton); - this.variationControlsList.Add (this.deleteVariantButton); + // Hook into the delete button's frame change, so we can fire off some drawing. If there's a better way, let me know. + this.deleteVariantButton.AddObserver (this, this.observerKeyPath, NSKeyValueObservingOptions.New, IntPtr.Zero); - // Hook into the delete button's frame change, so we can fire off some drawing. If there's a better way, let me know. - this.deleteVariantButton.AddObserver (this, new NSString (FrameChangedObservableProperty), NSKeyValueObservingOptions.New, IntPtr.Zero); - } + NextKeyView = this.deleteVariantButton; + + // Cache these before the loop + var variationBgColour = HostResources.GetNamedColor (NamedResources.FrameBoxButtonBackgroundColor); NSView previousControl = this.deleteVariantButton; foreach (PropertyVariationOption item in this.viewModelAsPropertyViewModel.Variation) { - var selectedVariationTextField = new UnfocusableTextField { - BackgroundColor = HostResources.GetNamedColor (NamedResources.FrameBoxButtonBackgroundColor), + var selectedVariationTextField = new UnfocusableTextField { + BackgroundColor = variationBgColour, Bordered = false, - Font = NSFont.SystemFontOfSize (NSFont.SystemFontSizeForControlSize (NSControlSize.Small) - 1f), + Font = VariationOptionFont, TranslatesAutoresizingMaskIntoConstraints = false, StringValue = string.Format (" {0}: {1} ", item.Category, item.Name), }; AddSubview (selectedVariationTextField); - AddConstraints (new[] { - NSLayoutConstraint.Create (selectedVariationTextField, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 5f), + AddConstraints (new[] { + NSLayoutConstraint.Create (selectedVariationTextField, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, VariationBorderOffset), NSLayoutConstraint.Create (selectedVariationTextField, NSLayoutAttribute.Left, NSLayoutRelation.Equal, previousControl, NSLayoutAttribute.Right, 1f, 6f), NSLayoutConstraint.Create (selectedVariationTextField, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 16f), }); @@ -173,20 +176,19 @@ private void UpdateVariations () previousControl = selectedVariationTextField; this.variationControlsList.Add (selectedVariationTextField); } - } else { - if (this.addVariantButton == null) { - this.addVariantButton = new VariationButton (HostResources, "pe-variation-add-button-active-mac-10", "pe-variation-add-button-mac-10") { - AccessibilityEnabled = true, - AccessibilityTitle = Properties.Resources.AccessibilityAddVariationButton, - Command = this.viewModelAsPropertyViewModel.RequestCreateVariantCommand, - ToolTip = Properties.Resources.AddVariant, - TranslatesAutoresizingMaskIntoConstraints = false, - }; - - LeftEdgeView = this.addVariantButton; - - this.variationControlsList.Add (this.addVariantButton); - } + } else { + this.addVariantButton = new VariationButton (HostResources, "pe-variation-add-button-active-mac-10", "pe-variation-add-button-mac-10") { + AccessibilityEnabled = true, + AccessibilityTitle = Properties.Resources.AccessibilityAddVariationButton, + Command = this.viewModelAsPropertyViewModel.RequestCreateVariantCommand, + ToolTip = Properties.Resources.AddVariant, + TranslatesAutoresizingMaskIntoConstraints = false, + }; + + LeftEdgeView = this.addVariantButton; + NextKeyView = this.addVariantButton; + + this.variationControlsList.Add (this.addVariantButton); } } } @@ -201,7 +203,11 @@ private void ClearSubViews () this.variationControlsList.Clear (); this.addVariantButton = null; - this.deleteVariantButton = null; + + if (this.deleteVariantButton != null) { + this.deleteVariantButton.RemoveObserver (this, this.observerKeyPath); + this.deleteVariantButton = null; + } } private void ClearChildLayers () @@ -315,8 +321,10 @@ public NSColor LabelTextColor { private VariationButton addVariantButton; private const float treeLineLeftEdge = 14f; private const float treeLineLeafIndent = 4f; + internal const float VariationBorderOffset = 5f; + internal static NSFont VariationOptionFont = NSFont.SystemFontOfSize (NSFont.SystemFontSizeForControlSize (NSControlSize.Small) - 1f); private nfloat ViewVariationChildVerticalDrawPoint => this.deleteVariantButton.Frame.Top + 5; private nfloat ViewVariationParentVerticalDrawPoint => this.addVariantButton.Frame.Top - 2; private PropertyViewModel viewModelAsPropertyViewModel; } -} +} \ No newline at end of file diff --git a/Xamarin.PropertyEditing.Mac/Controls/PointEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/PointEditorControl.cs index ea146358d..74d2cff9a 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/PointEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/PointEditorControl.cs @@ -10,8 +10,6 @@ namespace Xamarin.PropertyEditing.Mac { internal abstract class PointEditorControl : BasePointEditorControl { - protected override float HeightScaleFactor => 1.8f; - public PointEditorControl (IHostResourceProvider hostResources) : base (hostResources) { diff --git a/Xamarin.PropertyEditing.Mac/Controls/PropertyEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/PropertyEditorControl.cs index f91290376..59d7456b5 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/PropertyEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/PropertyEditorControl.cs @@ -37,13 +37,12 @@ public IHostResourceProvider HostResources public virtual bool IsDynamicallySized => false; public const float BottomOffset = -2f; protected virtual nint BaseHeight => 24; - protected virtual float HeightScaleFactor => 2.0f; PropertyViewModel viewModel; public PropertyViewModel ViewModel { get { return this.viewModel; } set { - if (this.ViewModel == value) + if (this.viewModel == value) return; PropertyViewModel oldModel = this.viewModel; @@ -93,11 +92,11 @@ public void UpdateKeyViews () } while (row > 0 && ctrl == null); if (ctrl != null) { - VariationButton vb = Superview.Subviews.OfType ().FirstOrDefault (); - if (vb != null) { - vb.NextKeyView = FirstKeyView; - ctrl.LastKeyView.NextKeyView = vb; - } else { + if (Superview is EditorContainer editorContainer && editorContainer.NextKeyView != null) { + editorContainer.NextKeyView.NextKeyView = FirstKeyView; + ctrl.LastKeyView.NextKeyView = editorContainer.NextKeyView; + } + else { ctrl.LastKeyView.NextKeyView = FirstKeyView; } ctrl.UpdateKeyViews (); @@ -110,7 +109,7 @@ public void UpdateKeyViews () public virtual nint GetHeight (EditorViewModel vm) { if (vm is PropertyViewModel realVm && realVm.IsVariant) { - return (nint)(BaseHeight * HeightScaleFactor); + return (nint)(BaseHeight + EditorContainer.VariationOptionFont.BoundingRectForFont.Height + (EditorContainer.VariationBorderOffset * 2)); // * 2 for upper and lower borders } return BaseHeight; diff --git a/Xamarin.PropertyEditing.Mac/Controls/RectangleEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/RectangleEditorControl.cs index e4f7cbac6..e85100d4e 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/RectangleEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/RectangleEditorControl.cs @@ -11,8 +11,6 @@ namespace Xamarin.PropertyEditing.Mac internal abstract class RectangleEditorControl : BaseRectangleEditorControl { - protected override float HeightScaleFactor => 1.4f; - protected RectangleEditorControl (IHostResourceProvider hostResources) : base (hostResources) {