diff options
Diffstat (limited to 'Xamarin.PropertyEditing.Mac')
29 files changed, 212 insertions, 255 deletions
diff --git a/Xamarin.PropertyEditing.Mac/Controls/BaseEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/BaseEditorControl.cs deleted file mode 100644 index d5044b6..0000000 --- a/Xamarin.PropertyEditing.Mac/Controls/BaseEditorControl.cs +++ /dev/null @@ -1,104 +0,0 @@ -using System; -using System.Collections; - -using AppKit; -using CoreGraphics; - -using Xamarin.PropertyEditing.Mac.Resources; - -namespace Xamarin.PropertyEditing.Mac -{ - internal abstract class BaseEditorControl : NSView - { - private IEnumerable errorList; - private const int DefaultActioButtonSize = 16; - - public event EventHandler ActionButtonClicked; - - private NSButton actionButton; - public NSButton ActionButton => this.actionButton; - - private PropertyButton propertyButton; - public PropertyButton PropertyButton => this.propertyButton; - - - public BaseEditorControl (IHostResourceProvider hostResources) - { - if (hostResources == null) - throw new ArgumentNullException (nameof (hostResources)); - - HostResources = hostResources; - - this.propertyButton = new PropertyButton (hostResources) { - TranslatesAutoresizingMaskIntoConstraints = false - }; - - AddSubview (this.propertyButton); - - this.actionButton = new NSButton { - Bordered = false, - Enabled = false, - ImageScaling = NSImageScale.AxesIndependently, - Title = string.Empty, - TranslatesAutoresizingMaskIntoConstraints = false, - AccessibilityTitle = LocalizationResources.AccessibilityActionButton, - AccessibilityHelp = LocalizationResources.AccessibilityActionButtonDescription, - }; - - this.actionButton.Activated += (object sender, EventArgs e) => { - if (this.errorList != null) { - var Container = new ErrorMessageView (HostResources, this.errorList); - - var errorMessagePopUp = new NSPopover { - Behavior = NSPopoverBehavior.Semitransient, - ContentViewController = new NSViewController (null, null) { View = Container }, - }; - - errorMessagePopUp.Show (default (CGRect), this.actionButton, NSRectEdge.MinYEdge); - } - - NotifyActionButtonClicked (); - }; - - AddSubview (actionButton); - - this.AddConstraints (new[] { - NSLayoutConstraint.Create (this.propertyButton, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 1f), - NSLayoutConstraint.Create (this.propertyButton, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Right, 1f, -33f), - NSLayoutConstraint.Create (this.propertyButton, NSLayoutAttribute.Width, NSLayoutRelation.Equal, 1f, PropertyButton.DefaultSize), - NSLayoutConstraint.Create (this.propertyButton, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, PropertyButton.DefaultSize), - - NSLayoutConstraint.Create (this.actionButton, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 3f), // TODO: Better centering based on the icon height - NSLayoutConstraint.Create (this.actionButton, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this.propertyButton, NSLayoutAttribute.Left, 1f, 20f), - NSLayoutConstraint.Create (this.actionButton, NSLayoutAttribute.Width, NSLayoutRelation.Equal, 1f, DefaultActioButtonSize), - NSLayoutConstraint.Create (this.actionButton, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, DefaultActioButtonSize), - }); - } - - public override void ViewDidChangeEffectiveAppearance () - { - this.actionButton.Image = this.actionButton.Enabled ? HostResources.GetNamedImage ("pe-action-warning-16") : null; - } - - protected IHostResourceProvider HostResources - { - get; - } - - protected void SetErrors (IEnumerable errors) - { - this.errorList = errors; - - this.actionButton.Enabled = errors != null; - this.actionButton.Hidden = !this.actionButton.Enabled; - - // Using NSImageName.Caution for now, we can change this later at the designers behest - this.actionButton.Image = this.actionButton.Enabled ? HostResources.GetNamedImage ("pe-action-warning-16") : null; - } - - void NotifyActionButtonClicked () - { - ActionButtonClicked?.Invoke (this, EventArgs.Empty); - } - } -} diff --git a/Xamarin.PropertyEditing.Mac/Controls/BasePointEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/BasePointEditorControl.cs index 1b6b0e4..e53a850 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/BasePointEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/BasePointEditorControl.cs @@ -47,22 +47,23 @@ namespace Xamarin.PropertyEditing.Mac AddSubview (YLabel); AddSubview (YEditor); + const float editorHeight = 18; this.AddConstraints (new[] { - NSLayoutConstraint.Create (XEditor, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 0f), + NSLayoutConstraint.Create (XEditor, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 3f), NSLayoutConstraint.Create (XEditor, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, 0f), NSLayoutConstraint.Create (XEditor, NSLayoutAttribute.Right, NSLayoutRelation.Equal, YEditor, NSLayoutAttribute.Left, 1f, -10f), - NSLayoutConstraint.Create (XEditor, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, DefaultControlHeight), + NSLayoutConstraint.Create (XEditor, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, editorHeight), NSLayoutConstraint.Create (XLabel, NSLayoutAttribute.Top, NSLayoutRelation.Equal, XEditor, NSLayoutAttribute.Bottom, 1f, -4f), - NSLayoutConstraint.Create (XLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, DefaultControlHeight), + NSLayoutConstraint.Create (XLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, editorHeight), - NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 0f), - NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this, NSLayoutAttribute.Right, 1f, -32f), + NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 3f), + NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this, NSLayoutAttribute.Right, 1f, 0), NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Width, NSLayoutRelation.Equal, XEditor, NSLayoutAttribute.Width, 1f, 0f), - NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, DefaultControlHeight), + NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, editorHeight), NSLayoutConstraint.Create (YLabel, NSLayoutAttribute.Top, NSLayoutRelation.Equal, XLabel, NSLayoutAttribute.Top, 1f, 0f), - NSLayoutConstraint.Create (YLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, DefaultControlHeight), + NSLayoutConstraint.Create (YLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, editorHeight), NSLayoutConstraint.Create (XLabel, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, XEditor.Subviews[0], NSLayoutAttribute.CenterX, 1f, 0), NSLayoutConstraint.Create (YLabel, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, YEditor.Subviews[0], NSLayoutAttribute.CenterX, 1f, 0), diff --git a/Xamarin.PropertyEditing.Mac/Controls/BaseRectangleEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/BaseRectangleEditorControl.cs index b9f3152..2936016 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/BaseRectangleEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/BaseRectangleEditorControl.cs @@ -76,37 +76,37 @@ namespace Xamarin.PropertyEditing.Mac AddSubview (HeightEditor); this.AddConstraints (new[] { - NSLayoutConstraint.Create (XEditor, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 0f), + NSLayoutConstraint.Create (XEditor, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 3f), NSLayoutConstraint.Create (XEditor, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, 0f), NSLayoutConstraint.Create (XEditor, NSLayoutAttribute.Right, NSLayoutRelation.Equal, YEditor, NSLayoutAttribute.Left, 1f, -10f), - NSLayoutConstraint.Create (XEditor, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, DefaultControlHeight), + NSLayoutConstraint.Create (XEditor, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 18), NSLayoutConstraint.Create (XLabel, NSLayoutAttribute.Top, NSLayoutRelation.Equal, XEditor, NSLayoutAttribute.Bottom, 1f, -4f), - NSLayoutConstraint.Create (XLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, DefaultControlHeight), + NSLayoutConstraint.Create (XLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 18), - NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 0f), - NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this, NSLayoutAttribute.Right, 1f, -32f), + NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 3f), + NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this, NSLayoutAttribute.Right, 1f, 0), NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Width, NSLayoutRelation.Equal, XEditor, NSLayoutAttribute.Width, 1f, 0f), - NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, DefaultControlHeight), + NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 18), NSLayoutConstraint.Create (YLabel, NSLayoutAttribute.Top, NSLayoutRelation.Equal, XLabel, NSLayoutAttribute.Top, 1f, 0f), - NSLayoutConstraint.Create (YLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, DefaultControlHeight), + NSLayoutConstraint.Create (YLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 18), NSLayoutConstraint.Create (WidthEditor, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 33f), NSLayoutConstraint.Create (WidthEditor, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, 0f), NSLayoutConstraint.Create (WidthEditor, NSLayoutAttribute.Right, NSLayoutRelation.Equal, HeightEditor, NSLayoutAttribute.Left, 1f, -10f), - NSLayoutConstraint.Create (WidthEditor, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, DefaultControlHeight), + NSLayoutConstraint.Create (WidthEditor, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 18), NSLayoutConstraint.Create (WidthLabel, NSLayoutAttribute.Top, NSLayoutRelation.Equal, WidthEditor, NSLayoutAttribute.Bottom, 1f, -4f), - NSLayoutConstraint.Create (WidthLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, DefaultControlHeight), + NSLayoutConstraint.Create (WidthLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 18), NSLayoutConstraint.Create (HeightEditor, NSLayoutAttribute.Top, NSLayoutRelation.Equal, WidthEditor, NSLayoutAttribute.Top, 1f, 0f), - NSLayoutConstraint.Create (HeightEditor, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this, NSLayoutAttribute.Right, 1f, -32f), + NSLayoutConstraint.Create (HeightEditor, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this, NSLayoutAttribute.Right, 1f, 0), NSLayoutConstraint.Create (HeightEditor, NSLayoutAttribute.Width, NSLayoutRelation.Equal, WidthEditor, NSLayoutAttribute.Width, 1f, 0f), - NSLayoutConstraint.Create (HeightEditor, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, DefaultControlHeight), + NSLayoutConstraint.Create (HeightEditor, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 18), NSLayoutConstraint.Create (HeightLabel, NSLayoutAttribute.Top, NSLayoutRelation.Equal, WidthLabel, NSLayoutAttribute.Top, 1f, 0f), - NSLayoutConstraint.Create (HeightLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, DefaultControlHeight), + NSLayoutConstraint.Create (HeightLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 18), NSLayoutConstraint.Create (XLabel, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, XEditor.Subviews[0], NSLayoutAttribute.CenterX, 1f, 0), diff --git a/Xamarin.PropertyEditing.Mac/Controls/BooleanEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/BooleanEditorControl.cs index 16c29b0..1df39dd 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/BooleanEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/BooleanEditorControl.cs @@ -31,8 +31,8 @@ namespace Xamarin.PropertyEditing.Mac AddSubview (BooleanEditor); this.AddConstraints (new[] { - NSLayoutConstraint.Create (BooleanEditor, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 6f), - NSLayoutConstraint.Create (BooleanEditor, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, -50f), + NSLayoutConstraint.Create (BooleanEditor, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1f, 0f), + NSLayoutConstraint.Create (BooleanEditor, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, 0f), }); } diff --git a/Xamarin.PropertyEditing.Mac/Controls/BrushEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/BrushEditorControl.cs index ae00c0c..b1caa5e 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/BrushEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/BrushEditorControl.cs @@ -54,7 +54,8 @@ namespace Xamarin.PropertyEditing.Mac }; this.popUpButton = new ColorPopUpButton { - Font = NSFont.FromFontName (DefaultFontName, DefaultFontSize), + ControlSize = NSControlSize.Small, + Font = NSFont.SystemFontOfSize (NSFont.SystemFontSizeForControlSize (NSControlSize.Small)), TranslatesAutoresizingMaskIntoConstraints = false, }; @@ -64,9 +65,9 @@ namespace Xamarin.PropertyEditing.Mac AddSubview (this.popUpButton); this.AddConstraints (new[] { - NSLayoutConstraint.Create (this.popUpButton, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 2f), - NSLayoutConstraint.Create (this.popUpButton, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, -32f), - NSLayoutConstraint.Create (this.popUpButton, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, DefaultControlHeight - 3), + NSLayoutConstraint.Create (this.popUpButton, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, 0), + NSLayoutConstraint.Create (this.popUpButton, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 16), + NSLayoutConstraint.Create (this.popUpButton, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1f, 0), }); ViewDidChangeEffectiveAppearance (); diff --git a/Xamarin.PropertyEditing.Mac/Controls/CombinablePropertyEditor.cs b/Xamarin.PropertyEditing.Mac/Controls/CombinablePropertyEditor.cs index 61c2de9..7300514 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/CombinablePropertyEditor.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/CombinablePropertyEditor.cs @@ -31,7 +31,7 @@ namespace Xamarin.PropertyEditing.Mac public override nint GetHeight (EditorViewModel vm) { var realVm = (CombinablePropertyViewModel<T>)vm; - return DefaultControlHeight * realVm.Choices.Count; + return subrowHeight * realVm.Choices.Count + 6; } protected override void HandleErrorsChanged (object sender, DataErrorsChangedEventArgs e) @@ -63,7 +63,7 @@ namespace Xamarin.PropertyEditing.Mac if (ViewModel == null) return; - float top = 0; + float top = 3; while (this.combinableList.Count > ViewModel.Choices.Count) { var child = this.combinableList.KeyAt (ViewModel.Choices.Count); @@ -78,7 +78,6 @@ namespace Xamarin.PropertyEditing.Mac NSButton checkbox; if (i >= this.combinableList.Count) { checkbox = new FocusableBooleanButton (); - checkbox.Activated += SelectionChanged; AddSubview (checkbox); @@ -86,8 +85,8 @@ namespace Xamarin.PropertyEditing.Mac this.AddConstraints (new[] { NSLayoutConstraint.Create (checkbox, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, top), NSLayoutConstraint.Create (checkbox, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, 0f), - NSLayoutConstraint.Create (checkbox, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, -33f), - NSLayoutConstraint.Create (checkbox, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, DefaultControlHeight), + NSLayoutConstraint.Create (checkbox, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, 0), + NSLayoutConstraint.Create (checkbox, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, subrowHeight), }); } else { checkbox = this.combinableList.KeyAt (i); @@ -96,7 +95,7 @@ namespace Xamarin.PropertyEditing.Mac checkbox.Title = choice.Name; this.combinableList[checkbox] = choice; - top += DefaultControlHeight; + top += subrowHeight; } // Set our tabable order @@ -127,6 +126,7 @@ namespace Xamarin.PropertyEditing.Mac } } + private const int subrowHeight = 20; private readonly OrderedDictionary<NSButton, FlaggableChoiceViewModel<T>> combinableList = new OrderedDictionary<NSButton, FlaggableChoiceViewModel<T>> (); private NSView firstKeyView; private NSView lastKeyView; diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/BasePopOverControl.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/BasePopOverControl.cs index 76868b6..708a832 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/Custom/BasePopOverControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/BasePopOverControl.cs @@ -48,7 +48,7 @@ namespace Xamarin.PropertyEditing.Mac NSLayoutConstraint.Create (viewTitle, NSLayoutAttribute.Left, NSLayoutRelation.Equal, iconView, NSLayoutAttribute.Right, 1f, 5f), //NSLayoutConstraint.Create (viewTitle, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, 38f), NSLayoutConstraint.Create (viewTitle, NSLayoutAttribute.Width, NSLayoutRelation.Equal, 1f, 120), - NSLayoutConstraint.Create (viewTitle, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, PropertyEditorControl.DefaultControlHeight), + NSLayoutConstraint.Create (viewTitle, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 24), }); } diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/BrushTabViewController.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/BrushTabViewController.cs index 6fa2dd5..bde2128 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/Custom/BrushTabViewController.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/BrushTabViewController.cs @@ -25,7 +25,7 @@ namespace Xamarin.PropertyEditing.Mac this.filterResource = new NSSearchField {
ControlSize = NSControlSize.Mini,
- Font = NSFont.FromFontName (PropertyEditorControl.DefaultFontName, PropertyEditorControl.DefaultFontSize),
+ Font = NSFont.SystemFontOfSize (NSFont.SystemFontSizeForControlSize (NSControlSize.Mini)),
PlaceholderString = Properties.Resources.SearchResourcesTitle,
};
@@ -46,7 +46,8 @@ namespace Xamarin.PropertyEditing.Mac NSView IEditorView.NativeView => View; - public bool IsDynamicallySized => false; + public bool IsDynamicallySized => false;
+ public bool NeedsPropertyButton => false; public nint GetHeight (EditorViewModel viewModel) { diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/FocusableBooleanButton.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/FocusableBooleanButton.cs index 219fb95..f8ed20d 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/Custom/FocusableBooleanButton.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/FocusableBooleanButton.cs @@ -14,7 +14,7 @@ namespace Xamarin.PropertyEditing.Mac Cell.LineBreakMode = NSLineBreakMode.TruncatingTail; Cell.UsesSingleLineMode = true; ControlSize = NSControlSize.Small; - Font = NSFont.FromFontName (PropertyEditorControl.DefaultFontName, PropertyEditorControl.DefaultFontSize); + Font = NSFont.SystemFontOfSize (NSFont.SystemFontSizeForControlSize (NSControlSize.Small)); Title = string.Empty; TranslatesAutoresizingMaskIntoConstraints = false; diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/FocusableButton.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/FocusableButton.cs index 5dba23c..9e3366d 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/Custom/FocusableButton.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/FocusableButton.cs @@ -14,7 +14,7 @@ namespace Xamarin.PropertyEditing.Mac Cell.LineBreakMode = NSLineBreakMode.TruncatingTail; Cell.UsesSingleLineMode = true; ControlSize = NSControlSize.Small; - Font = NSFont.FromFontName (PropertyEditorControl.DefaultFontName, PropertyEditorControl.DefaultFontSize); + Font = NSFont.SystemFontOfSize (NSFont.SystemFontSizeForControlSize (NSControlSize.Small)); Title = string.Empty; TranslatesAutoresizingMaskIntoConstraints = false; } diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/NumericSpinEditor.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/NumericSpinEditor.cs index 30dd7a0..aa5c648 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/Custom/NumericSpinEditor.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/NumericSpinEditor.cs @@ -18,12 +18,6 @@ namespace Xamarin.PropertyEditing.Mac internal class NumericSpinEditor : NSView, INSAccessibilityGroup { - internal const int StepperSpace = 2; - internal const int StepperWidth = 11; - const int stepperTopHeight = 9; - const int stepperBotHeight = 10; - const int inputModeWidth = 60; - private NumericTextField numericEditor; public NumericTextField NumericEditor { get { return this.numericEditor; } @@ -203,7 +197,7 @@ namespace Xamarin.PropertyEditing.Mac this.numericEditor = new NumericTextField { Alignment = NSTextAlignment.Right, TranslatesAutoresizingMaskIntoConstraints = false, - Font = NSFont.FromFontName (PropertyEditorControl.DefaultFontName, PropertyEditorControl.DefaultFontSize), + Font = NSFont.SystemFontOfSize (NSFont.SystemFontSizeForControlSize (NSControlSize.Small)), ControlSize = NSControlSize.Small, Formatter = this.formatter }; @@ -221,18 +215,20 @@ namespace Xamarin.PropertyEditing.Mac AddSubview (this.decrementButton); this.AddConstraints (new[] { - NSLayoutConstraint.Create (this.numericEditor, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, -(StepperWidth + StepperSpace + 1)), - NSLayoutConstraint.Create (this.numericEditor, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, PropertyEditorControl.DefaultControlHeight - 3), + NSLayoutConstraint.Create (this.numericEditor, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, 0), + NSLayoutConstraint.Create (this.numericEditor, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 18), - NSLayoutConstraint.Create (this.incrementButton, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this.numericEditor, NSLayoutAttribute.Top, 1f, 0f), - NSLayoutConstraint.Create (this.incrementButton, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this.numericEditor, NSLayoutAttribute.Right, 1f, StepperSpace), + NSLayoutConstraint.Create (this.incrementButton, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this.numericEditor, NSLayoutAttribute.Top, 1f, 0f), + NSLayoutConstraint.Create (this.incrementButton, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this.numericEditor, NSLayoutAttribute.Right, 1f, StepperSpace), + NSLayoutConstraint.Create (this.incrementButton, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this, NSLayoutAttribute.Right, 1f, 0), NSLayoutConstraint.Create (this.incrementButton, NSLayoutAttribute.Width, NSLayoutRelation.Equal, 1f, StepperWidth), - NSLayoutConstraint.Create (this.incrementButton, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, stepperTopHeight), + NSLayoutConstraint.Create (this.incrementButton, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, StepperTopHeight), - NSLayoutConstraint.Create (this.decrementButton, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this.numericEditor, NSLayoutAttribute.Top, 1f, stepperTopHeight), + NSLayoutConstraint.Create (this.decrementButton, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this.numericEditor, NSLayoutAttribute.Top, 1f, StepperTopHeight), + NSLayoutConstraint.Create (this.decrementButton, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this, NSLayoutAttribute.Right, 1f, 0), NSLayoutConstraint.Create (this.decrementButton, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this.numericEditor, NSLayoutAttribute.Right, 1f, StepperSpace), NSLayoutConstraint.Create (this.decrementButton, NSLayoutAttribute.Width, NSLayoutRelation.Equal, 1f, StepperWidth), - NSLayoutConstraint.Create (this.decrementButton, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, stepperBotHeight), + NSLayoutConstraint.Create (this.decrementButton, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, StepperBotHeight), }); } @@ -296,6 +292,11 @@ namespace Xamarin.PropertyEditing.Mac return (double)Decimal.Round ((decimal)(value < MinimumValue ? MinimumValue : value > MaximumValue ? MaximumValue : value), Digits); } + private const int StepperSpace = 2; + private const int StepperWidth = 11; + private const int StepperTopHeight = 9; + private const int StepperBotHeight = 10; + private readonly IHostResourceProvider hostResources; } } diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/PropertyButton.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/PropertyButton.cs index 012fbc7..31055ab 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/Custom/PropertyButton.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/PropertyButton.cs @@ -9,7 +9,7 @@ namespace Xamarin.PropertyEditing.Mac public class PropertyButton : UnfocusableButton { - public const int DefaultSize = 20; + public const int DefaultSize = 6; NSMenu popUpContextMenu; diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/UnfocusableTextField.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/UnfocusableTextField.cs index 5f9dfab..c449d66 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/Custom/UnfocusableTextField.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/UnfocusableTextField.cs @@ -65,7 +65,7 @@ namespace Xamarin.PropertyEditing.Mac Bordered = false, ControlSize = NSControlSize.Small, Editable = false, - Font = NSFont.FromFontName (PropertyEditorControl.DefaultFontName, PropertyEditorControl.DefaultPropertyLabelFontSize), + Font = NSFont.SystemFontOfSize (NSFont.SystemFontSizeForControlSize (NSControlSize.Small)), Selectable = false, TranslatesAutoresizingMaskIntoConstraints = false, }; diff --git a/Xamarin.PropertyEditing.Mac/Controls/CustomExpressionView.cs b/Xamarin.PropertyEditing.Mac/Controls/CustomExpressionView.cs index 94ec4cd..49ed8b0 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/CustomExpressionView.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/CustomExpressionView.cs @@ -40,7 +40,7 @@ namespace Xamarin.PropertyEditing.Mac NSLayoutConstraint.Create (customExpressionField, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 37f), NSLayoutConstraint.Create (customExpressionField, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, 38f), NSLayoutConstraint.Create (customExpressionField, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, -57f), - NSLayoutConstraint.Create (customExpressionField, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, PropertyEditorControl.DefaultControlHeight), + NSLayoutConstraint.Create (customExpressionField, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 18), }); } } diff --git a/Xamarin.PropertyEditing.Mac/Controls/EditorContainer.cs b/Xamarin.PropertyEditing.Mac/Controls/EditorContainer.cs index b9fac5c..643947d 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/EditorContainer.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/EditorContainer.cs @@ -2,6 +2,7 @@ using System; using AppKit; using CoreGraphics; using Foundation; +using Xamarin.PropertyEditing.ViewModels; namespace Xamarin.PropertyEditing.Mac { @@ -17,22 +18,44 @@ namespace Xamarin.PropertyEditing.Mac AddSubview (this.label); - this.AddConstraints (new[] { - NSLayoutConstraint.Create (this.label, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 0f), + 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, PropertyEditorControl.DefaultControlHeight), + NSLayoutConstraint.Create (this.label, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 18), }); if (EditorView != null) { AddSubview (EditorView.NativeView); EditorView.NativeView.TranslatesAutoresizingMaskIntoConstraints = false; - this.AddConstraints (new[] { + 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.Right, NSLayoutRelation.Equal, this, NSLayoutAttribute.Right, 1f, 0f), - NSLayoutConstraint.Create (EditorView.NativeView, NSLayoutAttribute.Height, NSLayoutRelation.Equal, this, NSLayoutAttribute.Height, 1f, 0f) + 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)); } } @@ -40,6 +63,19 @@ namespace Xamarin.PropertyEditing.Mac get; } + public EditorViewModel ViewModel + { + get => EditorView?.ViewModel; + set + { + if (EditorView == null) + return; + + EditorView.ViewModel = value; + this.propertyButton.ViewModel = value as PropertyViewModel; + } + } + public string Label { get { return this.label.StringValue; } set { @@ -98,9 +134,16 @@ namespace Xamarin.PropertyEditing.Mac } #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 const float LabelToControlSpacing = 13f; + 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 05776c5..d43b56c 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/GroupEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/GroupEditorControl.cs @@ -56,6 +56,8 @@ namespace Xamarin.PropertyEditing.Mac public bool IsDynamicallySized => true; + public bool NeedsPropertyButton => false; + public nint GetHeight (EditorViewModel viewModel) { if (!(viewModel is PropertyGroupViewModel gvm)) diff --git a/Xamarin.PropertyEditing.Mac/Controls/IEditorView.cs b/Xamarin.PropertyEditing.Mac/Controls/IEditorView.cs index a173c72..7d3f9fb 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/IEditorView.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/IEditorView.cs @@ -14,7 +14,8 @@ namespace Xamarin.PropertyEditing.Mac NSView NativeView { get; } EditorViewModel ViewModel { get; set; } - +
+ bool NeedsPropertyButton { get; } bool IsDynamicallySized { get; } nint GetHeight (EditorViewModel vm); }
diff --git a/Xamarin.PropertyEditing.Mac/Controls/NumericEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/NumericEditorControl.cs index 7af5487..c049c42 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/NumericEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/NumericEditorControl.cs @@ -41,11 +41,13 @@ namespace Xamarin.PropertyEditing.Mac AddSubview (NumericEditor); - this.numericEditorWidthConstraint = NSLayoutConstraint.Create (NumericEditor, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, -32f); + this.editorRightConstraint = NSLayoutConstraint.Create (NumericEditor, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this, NSLayoutAttribute.Right, 1f, 0); this.AddConstraints (new[] { - NSLayoutConstraint.Create (NumericEditor, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 1f), - this.numericEditorWidthConstraint, + NSLayoutConstraint.Create (NumericEditor, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1f, 0), + NSLayoutConstraint.Create (NumericEditor, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1, 0), + this.editorRightConstraint, + NSLayoutConstraint.Create (NumericEditor, NSLayoutAttribute.Height, NSLayoutRelation.Equal, this, NSLayoutAttribute.Height, 1, -6), }); } @@ -69,13 +71,6 @@ namespace Xamarin.PropertyEditing.Mac } } - private Type underlyingType; - - internal NSPopUpButton inputModePopup; - private IReadOnlyList<InputMode> viewModelInputModes; - - private NSLayoutConstraint numericEditorWidthConstraint; - protected override void UpdateErrorsDisplayed (IEnumerable errors) { if (ViewModel.HasErrors) { @@ -140,9 +135,12 @@ namespace Xamarin.PropertyEditing.Mac if (ViewModel == null) return; + this.editorRightConstraint.Active = !ViewModel.HasInputModes; if (ViewModel.HasInputModes) { if (this.inputModePopup == null) { this.inputModePopup = new FocusablePopUpButton { + ControlSize = NSControlSize.Small, + Font = NSFont.SystemFontOfSize (NSFont.SystemFontSizeForControlSize (NSControlSize.Small)), Menu = new NSMenu (), TranslatesAutoresizingMaskIntoConstraints = false, }; @@ -153,12 +151,13 @@ namespace Xamarin.PropertyEditing.Mac }; AddSubview (this.inputModePopup); - + this.editorInputModeConstraint = NSLayoutConstraint.Create (NumericEditor, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this.inputModePopup, NSLayoutAttribute.Left, 1, -4); this.AddConstraints (new[] { - NSLayoutConstraint.Create (this.inputModePopup, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 1f), - NSLayoutConstraint.Create (this.inputModePopup, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this, NSLayoutAttribute.Right, 1f, -33f), + this.editorInputModeConstraint, + NSLayoutConstraint.Create (this.inputModePopup, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1f, 0f), + NSLayoutConstraint.Create (this.inputModePopup, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this, NSLayoutAttribute.Right, 1f, 0f), NSLayoutConstraint.Create (this.inputModePopup, NSLayoutAttribute.Width, NSLayoutRelation.Equal, 1f, 80f), - NSLayoutConstraint.Create (this.inputModePopup, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, DefaultControlHeight - 3 ), + NSLayoutConstraint.Create (this.inputModePopup, NSLayoutAttribute.Height, NSLayoutRelation.Equal, NumericEditor, NSLayoutAttribute.Height, 1f, 0), }); } @@ -167,17 +166,24 @@ namespace Xamarin.PropertyEditing.Mac foreach (InputMode item in this.viewModelInputModes) { this.inputModePopup.Menu.AddItem (new NSMenuItem (item.Identifier)); } - - this.numericEditorWidthConstraint.Constant = -117f; // Shorten the stringEditor if we have Inputmodes Showing. - } else { - this.numericEditorWidthConstraint.Constant = -32f; // Lengthen the stringEditor if we have Inputmodes Hidden. } // If we are reusing the control we'll have to hid the inputMode if this doesn't have InputMode. - if (this.inputModePopup != null) + if (this.inputModePopup != null) { this.inputModePopup.Hidden = !ViewModel.HasInputModes; + this.editorInputModeConstraint.Active = ViewModel.HasInputModes; + } SetEnabled (); } + + private Type underlyingType; + + internal NSPopUpButton inputModePopup; + private IReadOnlyList<InputMode> viewModelInputModes; + + private readonly NSLayoutConstraint editorRightConstraint; + private NSLayoutConstraint editorInputModeConstraint; } } + diff --git a/Xamarin.PropertyEditing.Mac/Controls/ObjectEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/ObjectEditorControl.cs index 275bde6..eaf70e8 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/ObjectEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/ObjectEditorControl.cs @@ -21,7 +21,7 @@ namespace Xamarin.PropertyEditing.Mac this.createObject = new FocusableButton { Title = Properties.Resources.New, - BezelStyle = NSBezelStyle.Rounded + BezelStyle = NSBezelStyle.Rounded, }; this.createObject.Activated += OnNewPressed; AddSubview (this.createObject); diff --git a/Xamarin.PropertyEditing.Mac/Controls/PanelHeaderEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/PanelHeaderEditorControl.cs index f733fb6..3e7e488 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/PanelHeaderEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/PanelHeaderEditorControl.cs @@ -63,22 +63,22 @@ namespace Xamarin.PropertyEditing.Mac NSLayoutConstraint.Create (this.propertyIcon, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1, 5), NSLayoutConstraint.Create (this.propertyIcon, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1, 32), - NSLayoutConstraint.Create (this.objectNameLabel, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1, 0), - NSLayoutConstraint.Create (this.objectNameLabel, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this, NSLayoutAttribute.Right, Mac.Layout.GoldenRatioLeft, 0f), - NSLayoutConstraint.Create (this.objectNameLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, PropertyEditorControl.DefaultControlHeight), + NSLayoutConstraint.Create (this.objectNameLabel, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1, 5), + NSLayoutConstraint.Create (this.objectNameLabel, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this, NSLayoutAttribute.Right, Mac.Layout.GoldenRatioLeft, 0), + NSLayoutConstraint.Create (this.objectNameLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 20), NSLayoutConstraint.Create (this.propertyObjectName, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this.objectNameLabel, NSLayoutAttribute.CenterY, 1, 0), - NSLayoutConstraint.Create (this.propertyObjectName, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this.objectNameLabel, NSLayoutAttribute.Right, 1, 4.5f), - NSLayoutConstraint.Create (this.propertyObjectName, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this, NSLayoutAttribute.Right, 1, -(14.5f + PropertyButton.DefaultSize)), + NSLayoutConstraint.Create (this.propertyObjectName, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this.objectNameLabel, NSLayoutAttribute.Right, 1, EditorContainer.LabelToControlSpacing), + NSLayoutConstraint.Create (this.propertyObjectName, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this, NSLayoutAttribute.Right, 1, -(EditorContainer.PropertyTotalWidth)), NSLayoutConstraint.Create (this.typeLabel, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this.propertyObjectName, NSLayoutAttribute.Bottom, 1, 5), - NSLayoutConstraint.Create (this.typeLabel, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this, NSLayoutAttribute.Right, Mac.Layout.GoldenRatioLeft, 0f), - NSLayoutConstraint.Create (this.typeLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, PropertyEditorControl.DefaultControlHeight), + NSLayoutConstraint.Create (this.typeLabel, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this, NSLayoutAttribute.Right, Mac.Layout.GoldenRatioLeft, 0), + NSLayoutConstraint.Create (this.typeLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 20), NSLayoutConstraint.Create (this.typeDisplay, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this.typeLabel, NSLayoutAttribute.Top, 1, 0), NSLayoutConstraint.Create (this.typeDisplay, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this.propertyObjectName, NSLayoutAttribute.Width, 1, 0), - NSLayoutConstraint.Create (this.typeDisplay, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this.typeLabel, NSLayoutAttribute.Right, 1, 4), - NSLayoutConstraint.Create (this.typeDisplay, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, PropertyEditorControl.DefaultControlHeight), + NSLayoutConstraint.Create (this.typeDisplay, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this.typeLabel, NSLayoutAttribute.Right, 1, EditorContainer.LabelToControlSpacing), + NSLayoutConstraint.Create (this.typeDisplay, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 20), }); } diff --git a/Xamarin.PropertyEditing.Mac/Controls/PredefinedValuesEditor.cs b/Xamarin.PropertyEditing.Mac/Controls/PredefinedValuesEditor.cs index 65d92cb..d62524a 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/PredefinedValuesEditor.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/PredefinedValuesEditor.cs @@ -1,11 +1,8 @@ using System; -using System.Collections; -using System.Diagnostics; using System.ComponentModel; using Foundation; using AppKit; -using CoreGraphics; using Xamarin.PropertyEditing.ViewModels; using Xamarin.PropertyEditing.Mac.Resources; @@ -28,7 +25,7 @@ namespace Xamarin.PropertyEditing.Mac UsesSingleLineMode = true, }, ControlSize = NSControlSize.Small, - Font = NSFont.FromFontName (DefaultFontName, DefaultFontSize), + Font = NSFont.SystemFontOfSize (NSFont.SystemFontSizeForControlSize (NSControlSize.Small)), TranslatesAutoresizingMaskIntoConstraints = false, StringValue = String.Empty, }; @@ -44,7 +41,7 @@ namespace Xamarin.PropertyEditing.Mac UsesSingleLineMode = true, }, ControlSize = NSControlSize.Small, - Font = NSFont.FromFontName (DefaultFontName, DefaultFontSize), + Font = NSFont.SystemFontOfSize (NSFont.SystemFontSizeForControlSize (NSControlSize.Small)), TranslatesAutoresizingMaskIntoConstraints = false, StringValue = String.Empty, }; @@ -109,10 +106,9 @@ namespace Xamarin.PropertyEditing.Mac AddSubview (this.popUpButton); this.AddConstraints (new[] { - NSLayoutConstraint.Create (this.popUpButton, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 0f), - NSLayoutConstraint.Create (this.popUpButton, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, -1f), - NSLayoutConstraint.Create (this.popUpButton, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, -32f), - NSLayoutConstraint.Create (this.popUpButton, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, DefaultControlHeight + 1), + NSLayoutConstraint.Create (this.popUpButton, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1f, 0f), + NSLayoutConstraint.Create (this.popUpButton, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, 0f), + NSLayoutConstraint.Create (this.popUpButton, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, 0), }); this.firstKeyView = this.popUpButton; @@ -128,10 +124,9 @@ namespace Xamarin.PropertyEditing.Mac AddSubview (this.comboBox); this.AddConstraints (new[] { - NSLayoutConstraint.Create (this.comboBox, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 0f), - NSLayoutConstraint.Create (this.comboBox, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, -1f), - NSLayoutConstraint.Create (this.comboBox, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, -33f), - NSLayoutConstraint.Create (this.comboBox, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, DefaultControlHeight), + NSLayoutConstraint.Create (this.comboBox, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1f, 0f), + NSLayoutConstraint.Create (this.comboBox, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, 0f), + NSLayoutConstraint.Create (this.comboBox, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, 0), }); this.firstKeyView = this.comboBox; diff --git a/Xamarin.PropertyEditing.Mac/Controls/PropertyEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/PropertyEditorControl.cs index 2fd5c68..0434f66 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/PropertyEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/PropertyEditorControl.cs @@ -8,11 +8,19 @@ using Xamarin.PropertyEditing.ViewModels; namespace Xamarin.PropertyEditing.Mac { internal abstract class PropertyEditorControl - : BaseEditorControl, IEditorView + : NSView, IEditorView { protected PropertyEditorControl (IHostResourceProvider hostResources) - : base (hostResources) { + if (hostResources == null) + throw new ArgumentNullException (nameof (hostResources)); + + HostResources = hostResources; + } + + public IHostResourceProvider HostResources + { + get; } public string Label { get; set; } @@ -67,6 +75,8 @@ namespace Xamarin.PropertyEditing.Mac } } + public virtual bool NeedsPropertyButton => true; + public void UpdateKeyViews () { nint row = TableView.RowForView (this); @@ -92,7 +102,7 @@ namespace Xamarin.PropertyEditing.Mac /// <remarks>You should treat the implementation of this as static.</remarks> public virtual nint GetHeight (EditorViewModel vm) { - return DefaultControlHeight; + return 24; } protected abstract void UpdateValue (); @@ -104,8 +114,6 @@ namespace Xamarin.PropertyEditing.Mac UpdateValue (); UpdateAccessibilityValues (); } - - PropertyButton.ViewModel = viewModel; } protected virtual void OnPropertyChanged (object sender, System.ComponentModel.PropertyChangedEventArgs e) diff --git a/Xamarin.PropertyEditing.Mac/Controls/RatioEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/RatioEditorControl.cs index 9f76079..a899306 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/RatioEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/RatioEditorControl.cs @@ -33,9 +33,9 @@ namespace Xamarin.PropertyEditing.Mac AddSubview (this.ratioEditor); this.AddConstraints (new[] { - NSLayoutConstraint.Create (this.ratioEditor, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, -2f), - NSLayoutConstraint.Create (this.ratioEditor, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, -32f), - NSLayoutConstraint.Create (this.ratioEditor, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, DefaultControlHeight), + NSLayoutConstraint.Create (this.ratioEditor, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1f, 0), + NSLayoutConstraint.Create (this.ratioEditor, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, 0), + NSLayoutConstraint.Create (this.ratioEditor, NSLayoutAttribute.Height, NSLayoutRelation.Equal, this, NSLayoutAttribute.Height, 1, -6), }); } diff --git a/Xamarin.PropertyEditing.Mac/Controls/RequestResource/RequestResourceView.cs b/Xamarin.PropertyEditing.Mac/Controls/RequestResource/RequestResourceView.cs index 607d453..b329471 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/RequestResource/RequestResourceView.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/RequestResource/RequestResourceView.cs @@ -63,7 +63,7 @@ namespace Xamarin.PropertyEditing.Mac this.searchResources = new NSSearchField { ControlSize = controlSize, - Font = NSFont.FromFontName (PropertyEditorControl.DefaultFontName, PropertyEditorControl.DefaultFontSize), + Font = NSFont.SystemFontOfSize (NSFont.SystemFontSizeForControlSize (NSControlSize.Small)), PlaceholderString = Properties.Resources.SearchResourcesTitle, TranslatesAutoresizingMaskIntoConstraints = false, }; @@ -113,7 +113,7 @@ namespace Xamarin.PropertyEditing.Mac }); this.segmentedControl.SetImage (HostResources.GetNamedImage ("pe-resource-editor-16"), 2); this.segmentedControl.Frame = new CGRect ((FrameWidthThird - (segmentedControl.Bounds.Width) / 2), 5, (Frame.Width - (FrameWidthThird)) - 10, 24); - this.segmentedControl.Font = NSFont.FromFontName (PropertyEditorControl.DefaultFontName, PropertyEditorControl.DefaultFontSize); + this.segmentedControl.Font = NSFont.SystemFontOfSize (NSFont.SystemFontSizeForControlSize (NSControlSize.Small)); this.segmentedControl.TranslatesAutoresizingMaskIntoConstraints = false; this.segmentedControl.SetSelected (true, 0); this.resourceSelectorPanel.ViewModel.ShowBothResourceTypes = true; diff --git a/Xamarin.PropertyEditing.Mac/Controls/RequestResource/ResourceTableDelegate.cs b/Xamarin.PropertyEditing.Mac/Controls/RequestResource/ResourceTableDelegate.cs index 55f20ad..c05abc9 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/RequestResource/ResourceTableDelegate.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/RequestResource/ResourceTableDelegate.cs @@ -86,7 +86,7 @@ namespace Xamarin.PropertyEditing.Mac public override nfloat GetRowHeight (NSTableView tableView, nint row) { - return PropertyEditorControl.DefaultControlHeight; + return 24; } public override void SelectionDidChange (NSNotification notification) diff --git a/Xamarin.PropertyEditing.Mac/Controls/StringEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/StringEditorControl.cs index f715576..3aeae5f 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/StringEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/StringEditorControl.cs @@ -1,11 +1,9 @@ -using System; using System.Collections; using System.Collections.Generic; -using System.Diagnostics; using System.Linq; + using AppKit; -using CoreGraphics; -using Foundation; + using Xamarin.PropertyEditing.Mac.Resources; using Xamarin.PropertyEditing.ViewModels; @@ -14,26 +12,17 @@ namespace Xamarin.PropertyEditing.Mac internal class StringEditorControl : PropertyEditorControl<PropertyViewModel<string>> { - private NSTextField stringEditor { get; set; } - - private NSLayoutConstraint stringEditorWidthConstraint; - public override NSView FirstKeyView => this.stringEditor; private NSView lastKeyView; public override NSView LastKeyView => this.lastKeyView; - internal NSPopUpButton inputModePopup; - private IReadOnlyList<InputMode> viewModelInputModes; - - private bool CanEnable => ViewModel.Property.CanWrite && (((ViewModel.InputMode != null) && !ViewModel.InputMode.IsSingleValue) || (this.inputModePopup == null)); - - public StringEditorControl (IHostResourceProvider hostResource) - : base (hostResource) + public StringEditorControl (IHostResourceProvider hostResources) + : base (hostResources) { this.stringEditor = new PropertyTextField { BackgroundColor = NSColor.Clear, ControlSize = NSControlSize.Small, - Font = NSFont.FromFontName (DefaultFontName, DefaultFontSize), + Font = NSFont.SystemFontOfSize (NSFont.SystemFontSizeForControlSize (NSControlSize.Small)), StringValue = string.Empty, TranslatesAutoresizingMaskIntoConstraints = false, }; @@ -45,13 +34,13 @@ namespace Xamarin.PropertyEditing.Mac AddSubview (this.stringEditor); this.lastKeyView = this.stringEditor; - - this.stringEditorWidthConstraint = NSLayoutConstraint.Create (this.stringEditor, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, -117f); + this.editorRightConstraint = NSLayoutConstraint.Create (this.stringEditor, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this, NSLayoutAttribute.Right, 1f, 0); this.AddConstraints (new[] { - NSLayoutConstraint.Create (this.stringEditor, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 1f), - this.stringEditorWidthConstraint, - NSLayoutConstraint.Create (this.stringEditor, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, DefaultControlHeight - 3), + NSLayoutConstraint.Create (this.stringEditor, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1f, 0), + NSLayoutConstraint.Create (this.stringEditor, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1, 0), + this.editorRightConstraint, + NSLayoutConstraint.Create (this.stringEditor, NSLayoutAttribute.Height, NSLayoutRelation.Equal, this, NSLayoutAttribute.Height, 1, -6), }); } @@ -75,11 +64,14 @@ namespace Xamarin.PropertyEditing.Mac if (ViewModel == null) return; + this.editorRightConstraint.Active = !ViewModel.HasInputModes; if (ViewModel.HasInputModes) { if (this.inputModePopup == null) { this.inputModePopup = new FocusablePopUpButton { Menu = new NSMenu (), - TranslatesAutoresizingMaskIntoConstraints = false, + ControlSize = NSControlSize.Small, + Font = NSFont.SystemFontOfSize (NSFont.SystemFontSizeForControlSize (NSControlSize.Small)), + TranslatesAutoresizingMaskIntoConstraints = false }; this.inputModePopup.Activated += (o, e) => { @@ -89,11 +81,14 @@ namespace Xamarin.PropertyEditing.Mac AddSubview (this.inputModePopup); - this.AddConstraints (new[] { - NSLayoutConstraint.Create (this.inputModePopup, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 1f), - NSLayoutConstraint.Create (this.inputModePopup, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this, NSLayoutAttribute.Right, 1f, -33f), + this.editorInputModeConstraint = NSLayoutConstraint.Create (this.stringEditor, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this.inputModePopup, NSLayoutAttribute.Left, 1, -4); + + AddConstraints (new[] { + this.editorInputModeConstraint, + NSLayoutConstraint.Create (this.inputModePopup, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1f, 0f), + NSLayoutConstraint.Create (this.inputModePopup, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this, NSLayoutAttribute.Right, 1f, 0), NSLayoutConstraint.Create (this.inputModePopup, NSLayoutAttribute.Width, NSLayoutRelation.Equal, 1f, 80f), - NSLayoutConstraint.Create (this.inputModePopup, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, DefaultControlHeight - 3 ), + NSLayoutConstraint.Create (this.inputModePopup, NSLayoutAttribute.Height, NSLayoutRelation.Equal, this.stringEditor, NSLayoutAttribute.Height, 1, 0), }); this.lastKeyView = this.inputModePopup; @@ -104,15 +99,13 @@ namespace Xamarin.PropertyEditing.Mac foreach (InputMode item in this.viewModelInputModes) { this.inputModePopup.Menu.AddItem (new NSMenuItem (item.Identifier)); } - - this.stringEditorWidthConstraint.Constant = -117f; // Shorten the stringEditor if we have Inputmodes Showing. - } else { - this.stringEditorWidthConstraint.Constant = -34f; // Lengthen the stringEditor if we have Inputmodes Hidden. } // If we are reusing the control we'll have to hid the inputMode if this doesn't have InputMode. - if (this.inputModePopup != null) + if (this.inputModePopup != null) { this.inputModePopup.Hidden = !ViewModel.HasInputModes; + this.editorInputModeConstraint.Active = ViewModel.HasInputModes; + } SetEnabled (); } @@ -143,5 +136,13 @@ namespace Xamarin.PropertyEditing.Mac this.inputModePopup.AccessibilityTitle = string.Format (LocalizationResources.AccessibilityInpueModeEditor, ViewModel.Property.Name); } } + + private readonly NSTextField stringEditor; + private NSLayoutConstraint editorRightConstraint, editorInputModeConstraint; + internal NSPopUpButton inputModePopup; + private IReadOnlyList<InputMode> viewModelInputModes; + + private bool CanEnable => ViewModel.Property.CanWrite && (((ViewModel.InputMode != null) && !ViewModel.InputMode.IsSingleValue) || (this.inputModePopup == null)); } } + diff --git a/Xamarin.PropertyEditing.Mac/HostResourceProvider.cs b/Xamarin.PropertyEditing.Mac/HostResourceProvider.cs index bd2b509..87c02a8 100644 --- a/Xamarin.PropertyEditing.Mac/HostResourceProvider.cs +++ b/Xamarin.PropertyEditing.Mac/HostResourceProvider.cs @@ -14,8 +14,6 @@ namespace Xamarin.PropertyEditing.Mac set; } - private readonly NSBundle resourceBundle; - public HostResourceProvider () { var containingDir = Path.GetDirectoryName (typeof (HostResourceProvider).Assembly.Location); @@ -59,6 +57,8 @@ namespace Xamarin.PropertyEditing.Mac { return NSFont.FromFontName (name, fontSize); } + + private readonly NSBundle resourceBundle; } public static class NamedResources diff --git a/Xamarin.PropertyEditing.Mac/PropertyTableDelegate.cs b/Xamarin.PropertyEditing.Mac/PropertyTableDelegate.cs index 7b5c90e..83d5e47 100644 --- a/Xamarin.PropertyEditing.Mac/PropertyTableDelegate.cs +++ b/Xamarin.PropertyEditing.Mac/PropertyTableDelegate.cs @@ -102,8 +102,6 @@ namespace Xamarin.PropertyEditing.Mac } if (editor != null) { - editor.ViewModel = evm; - var ovm = evm as ObjectPropertyViewModel; if (ovm != null && editorOrContainer is EditorContainer container) { if (container.LeftEdgeView == null) { @@ -112,6 +110,10 @@ namespace Xamarin.PropertyEditing.Mac } else if (!ovm.CanDelve) { container.LeftEdgeView = null; } + + container.ViewModel = evm; + } else { + editor.ViewModel = evm; } bool openObjectRow = ovm != null && outlineView.IsItemExpanded (item); @@ -203,7 +205,7 @@ namespace Xamarin.PropertyEditing.Mac IEditorView view = ((editorOrContainer as EditorContainer)?.EditorView) ?? editorOrContainer as IEditorView; if (view == null) { - registration.RowSize = PropertyEditorControl.DefaultControlHeight; + registration.RowSize = 24; } else if (view.IsDynamicallySized) { registration.SizingInstance = view; } else { diff --git a/Xamarin.PropertyEditing.Mac/Xamarin.PropertyEditing.Mac.csproj b/Xamarin.PropertyEditing.Mac/Xamarin.PropertyEditing.Mac.csproj index 35ff6d7..2884194 100644 --- a/Xamarin.PropertyEditing.Mac/Xamarin.PropertyEditing.Mac.csproj +++ b/Xamarin.PropertyEditing.Mac/Xamarin.PropertyEditing.Mac.csproj @@ -159,7 +159,6 @@ <Folder Include="Controls\" />
<Folder Include="Controls\Custom\" />
<Folder Include="Resources\" />
- <Compile Include="Controls\BaseEditorControl.cs" />
<Compile Include="Controls\ErrorMessageView.cs" />
<Folder Include="Controls\RequestResource\" />
<Folder Include="PropertyEditingResource\Contents\Resources\" />
|