diff options
author | Dominique Louis <dominique@yen-x1-31.fareast.corp.microsoft.com> | 2018-12-02 11:36:19 +0300 |
---|---|---|
committer | Dominique Louis <dominique@yen-x1-31.fareast.corp.microsoft.com> | 2018-12-02 11:52:09 +0300 |
commit | 2f16fd1451e3e7c9adcca9fe852fe767834468be (patch) | |
tree | 071efa534ea30fa170ea1201bde9c01f053ad496 /Xamarin.PropertyEditing.Mac | |
parent | 794123986062cb0a8ab2885bbb449bb62f9f13ad (diff) |
[Mac] Remove DoConstraints dependency and use NSLayoutConstraint.Create calls directly. Should be slightly faster on startup.
Diffstat (limited to 'Xamarin.PropertyEditing.Mac')
17 files changed, 161 insertions, 149 deletions
diff --git a/Xamarin.PropertyEditing.Mac/Controls/BaseEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/BaseEditorControl.cs index 3e3c983..a3dfaff 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/BaseEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/BaseEditorControl.cs @@ -11,31 +11,27 @@ namespace Xamarin.PropertyEditing.Mac { internal abstract class BaseEditorControl : NSView { - IEnumerable errorList; - const int DefaultActioButtonSize = 16; + private IEnumerable errorList; + private const int DefaultActioButtonSize = 16; public event EventHandler ActionButtonClicked; - NSButton actionButton; - public NSButton ActionButton - { - get { return actionButton; } - } - PropertyButton propertyButton; - public PropertyButton PropertyButton - { - get { return propertyButton; } - } + private NSButton actionButton; + public NSButton ActionButton => this.actionButton; + + private PropertyButton propertyButton; + public PropertyButton PropertyButton => this.propertyButton; + public BaseEditorControl () { - propertyButton = new PropertyButton { + this.propertyButton = new PropertyButton { TranslatesAutoresizingMaskIntoConstraints = false }; - AddSubview (propertyButton); + AddSubview (this.propertyButton); - actionButton = new NSButton { + this.actionButton = new NSButton { Bordered = false, Enabled = false, ImageScaling = NSImageScale.AxesIndependently, @@ -46,19 +42,19 @@ namespace Xamarin.PropertyEditing.Mac }; #if DESIGNER_DEBUG - actionButton.Image = PropertyEditorPanel.ThemeManager.GetImageForTheme ("action-warning-16"); + this.actionButton.Image = PropertyEditorPanel.ThemeManager.GetImageForTheme ("action-warning-16"); #endif - actionButton.Activated += (object sender, EventArgs e) => { - if (errorList != null) { - var Container = new ErrorMessageView (errorList); + this.actionButton.Activated += (object sender, EventArgs e) => { + if (this.errorList != null) { + var Container = new ErrorMessageView (this.errorList); var errorMessagePopUp = new NSPopover { Behavior = NSPopoverBehavior.Semitransient, ContentViewController = new NSViewController (null, null) { View = Container }, }; - errorMessagePopUp.Show (default (CGRect), actionButton, NSRectEdge.MinYEdge); + errorMessagePopUp.Show (default (CGRect), this.actionButton, NSRectEdge.MinYEdge); } NotifyActionButtonClicked (); @@ -66,15 +62,16 @@ namespace Xamarin.PropertyEditing.Mac AddSubview (actionButton); - this.DoConstraints (new[] { - propertyButton.ConstraintTo (this, (ab, c) => ab.Width == PropertyButton.DefaultSize), - propertyButton.ConstraintTo (this, (ab, c) => ab.Height == PropertyButton.DefaultSize), - propertyButton.ConstraintTo (this, (ab, c) => ab.Top == c.Top + 1), - propertyButton.ConstraintTo (this, (ab, c) => ab.Left == c.Right - 33), - actionButton.ConstraintTo (this, (eb, c) => eb.Width == DefaultActioButtonSize), - actionButton.ConstraintTo (this, (eb, c) => eb.Height == DefaultActioButtonSize), - actionButton.ConstraintTo (propertyButton, (eb, ab) => eb.Left == ab.Left + PropertyButton.DefaultSize), - actionButton.ConstraintTo (this, (eb, c) => eb.Top == c.Top + 3), // TODO: Better centering based on the icon height + 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), }); PropertyEditorPanel.ThemeManager.ThemeChanged += ThemeManager_ThemeChanged; @@ -99,13 +96,13 @@ namespace Xamarin.PropertyEditing.Mac protected void SetErrors (IEnumerable errors) { - errorList = errors; + this.errorList = errors; - actionButton.Enabled = errors != null; - actionButton.Hidden = !actionButton.Enabled; + 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 - actionButton.Image = actionButton.Enabled ? PropertyEditorPanel.ThemeManager.GetImageForTheme ("action-warning-16") : null; + this.actionButton.Image = this.actionButton.Enabled ? PropertyEditorPanel.ThemeManager.GetImageForTheme ("action-warning-16") : null; } void NotifyActionButtonClicked () diff --git a/Xamarin.PropertyEditing.Mac/Controls/BasePointEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/BasePointEditorControl.cs index dd32a50..a1f5d3f 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/BasePointEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/BasePointEditorControl.cs @@ -40,11 +40,12 @@ namespace Xamarin.PropertyEditing.Mac AddSubview (YLabel); AddSubview (YEditor); - this.DoConstraints (new[] { - XEditor.ConstraintTo (this, (xe, c) => xe.Width == 90), - XEditor.ConstraintTo (this, (xe, c) => xe.Height == DefaultControlHeight), - YEditor.ConstraintTo (this, (ye, c) => ye.Width == 90), - YEditor.ConstraintTo (this, (ye, c) => ye.Height == DefaultControlHeight), + this.AddConstraints (new[] { + NSLayoutConstraint.Create (XEditor, NSLayoutAttribute.Width, NSLayoutRelation.Equal, 1f, 90f), + NSLayoutConstraint.Create (XEditor, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, DefaultControlHeight), + + NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Width, NSLayoutRelation.Equal, 1f, 90f), + NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, DefaultControlHeight), }); UpdateTheme (); diff --git a/Xamarin.PropertyEditing.Mac/Controls/BaseRectangleEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/BaseRectangleEditorControl.cs index b9deb09..97f9c05 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/BaseRectangleEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/BaseRectangleEditorControl.cs @@ -58,15 +58,18 @@ namespace Xamarin.PropertyEditing.Mac AddSubview (HeightLabel); AddSubview (HeightEditor); - this.DoConstraints (new[] { - XEditor.ConstraintTo (this, (xe, c) => xe.Width == 90), - XEditor.ConstraintTo (this, (xe, c) => xe.Height == DefaultControlHeight), - YEditor.ConstraintTo (this, (ye, c) => ye.Width == 90), - YEditor.ConstraintTo (this, (ye, c) => ye.Height == DefaultControlHeight), - WidthEditor.ConstraintTo (this, (we, c) => we.Width == 90), - WidthEditor.ConstraintTo (this, (we, c) => we.Height == DefaultControlHeight), - HeightEditor.ConstraintTo (this, (he, c) => he.Width == 90), - HeightEditor.ConstraintTo (this, (he, c) => he.Height == DefaultControlHeight), + this.AddConstraints (new[] { + NSLayoutConstraint.Create (XEditor, NSLayoutAttribute.Width, NSLayoutRelation.Equal, 1f, 90f), + NSLayoutConstraint.Create (XEditor, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, DefaultControlHeight), + + NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Width, NSLayoutRelation.Equal, 1f, 90f), + NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, DefaultControlHeight), + + NSLayoutConstraint.Create (WidthEditor, NSLayoutAttribute.Width, NSLayoutRelation.Equal, 1f, 90f), + NSLayoutConstraint.Create (WidthEditor, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, DefaultControlHeight), + + NSLayoutConstraint.Create (HeightEditor, NSLayoutAttribute.Width, NSLayoutRelation.Equal, 1f, 90f), + NSLayoutConstraint.Create (HeightEditor, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, DefaultControlHeight), }); UpdateTheme (); diff --git a/Xamarin.PropertyEditing.Mac/Controls/BooleanEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/BooleanEditorControl.cs index b0d5986..887443e 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/BooleanEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/BooleanEditorControl.cs @@ -35,9 +35,9 @@ namespace Xamarin.PropertyEditing.Mac AddSubview (BooleanEditor); - this.DoConstraints (new[] { - BooleanEditor.ConstraintTo (this, (be, c) => be.Width == c.Width - 50), - BooleanEditor.ConstraintTo (this, (be, c) => be.Top == c.Top + 6), + 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), }); UpdateTheme (); diff --git a/Xamarin.PropertyEditing.Mac/Controls/BrushEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/BrushEditorControl.cs index c64fd08..d3f01e8 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/BrushEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/BrushEditorControl.cs @@ -57,14 +57,14 @@ namespace Xamarin.PropertyEditing.Mac this.popupButtonList = new NSMenu (); this.popUpButton.Menu = this.popupButtonList; - this.DoConstraints (new [] { - this.popUpButton.ConstraintTo (this, (pub, c) => pub.Width == c.Width - 33), - this.popUpButton.ConstraintTo (this, (pub, c) => pub.Height == DefaultControlHeight), - this.popUpButton.ConstraintTo (this, (pub, c) => pub.Top == c.Top + 0), - }); - AddSubview (this.popUpButton); + this.AddConstraints (new[] { + NSLayoutConstraint.Create (this.popUpButton, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 0f), + NSLayoutConstraint.Create (this.popUpButton, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, -33f), + NSLayoutConstraint.Create (this.popUpButton, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, DefaultControlHeight + 1), + }); + UpdateTheme (); } diff --git a/Xamarin.PropertyEditing.Mac/Controls/ConstraintExtensions.cs b/Xamarin.PropertyEditing.Mac/Controls/ConstraintExtensions.cs index 21ebe29..f2816a4 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/ConstraintExtensions.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/ConstraintExtensions.cs @@ -45,10 +45,12 @@ namespace Xamarin.PropertyEditing.Mac if (mainExpression.Right.NodeType == ExpressionType.Constant) { var c = Convert.ToSingle (((ConstantExpression)mainExpression.Right).Value); + // Console.WriteLine ("NSLayoutConstraint.Create ({0}, NSLayoutAttribute.{1}, NSLayoutRelation.{2}, {3}, NSLayoutAttribute.{4}, {5}f, {6}f),", view1, propLeft, relation, null, propRight, 1, c); return NSLayoutConstraint.Create (view1, propLeft, relation, null, NSLayoutAttribute.NoAttribute, 1, c); } else if (mainExpression.Right is MemberExpression) { propRight = (NSLayoutAttribute)Enum.Parse (typeof (NSLayoutAttribute), ((MemberExpression)mainExpression.Right).Member.Name); + // Console.WriteLine ("NSLayoutConstraint.Create ({0}, NSLayoutAttribute.{1}, NSLayoutRelation.{2}, {3}, NSLayoutAttribute.{4}, {5}f, {6}f),", view1, propLeft, relation, view2, propRight, 1, 0); return NSLayoutConstraint.Create (view1, propLeft, relation, view2, propRight, 1, 0); } @@ -84,8 +86,8 @@ namespace Xamarin.PropertyEditing.Mac var member = (MemberExpression)(addNode.Right is MemberExpression ? addNode.Right : addNode.Left); propRight = (NSLayoutAttribute)Enum.Parse (typeof (NSLayoutAttribute), member.Member.Name); } - - // Console.WriteLine ("NSLayoutConstraint.Create ({0}, {1}, {2}, {3}, {4}, {5}, {6});", view1, propLeft, relation, view2, propRight, multiplier, constant); + + // Console.WriteLine ("NSLayoutConstraint.Create ({0}, NSLayoutAttribute.{1}, NSLayoutRelation.{2}, {3}, NSLayoutAttribute.{4}, {5}f, {6}f),", view1, propLeft, relation, view2, propRight, multiplier, constant); return NSLayoutConstraint.Create (view1, propLeft, relation, view2, propRight, multiplier, constant); } diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/BasePopOverControl.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/BasePopOverControl.cs index 809da6d..f8f3c54 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/Custom/BasePopOverControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/BasePopOverControl.cs @@ -34,16 +34,17 @@ namespace Xamarin.PropertyEditing.Mac AddSubview (viewTitle); - this.DoConstraints (new[] { - iconView.ConstraintTo (this, (iv, c) => iv.Top == c.Top + 5), - iconView.ConstraintTo (this, (iv, c) => iv.Left == c.Left + 5), - iconView.ConstraintTo (this, (iv, c) => iv.Width == DefaultIconButtonSize), - iconView.ConstraintTo (this, (iv, c) => iv.Height == DefaultIconButtonSize), - - viewTitle.ConstraintTo (this, (vt, c) => vt.Top == c.Top + 8), - viewTitle.ConstraintTo (this, (vt, c) => vt.Left == c.Left + 38), - viewTitle.ConstraintTo (this, (vt, c) => vt.Width == 120), - viewTitle.ConstraintTo (this, (vt, c) => vt.Height == 24), + this.AddConstraints (new[] { + NSLayoutConstraint.Create (iconView, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 5f), + NSLayoutConstraint.Create (iconView, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, 5f), + NSLayoutConstraint.Create (iconView, NSLayoutAttribute.Width, NSLayoutRelation.Equal, 1f, DefaultIconButtonSize), + NSLayoutConstraint.Create (iconView, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, DefaultIconButtonSize), + + NSLayoutConstraint.Create (viewTitle, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 7f), + 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), }); Appearance = PropertyEditorPanel.ThemeManager.CurrentAppearance; diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/NumericSpinEditor.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/NumericSpinEditor.cs index 8707e6b..f1c3c7c 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/Custom/NumericSpinEditor.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/NumericSpinEditor.cs @@ -215,19 +215,19 @@ namespace Xamarin.PropertyEditing.Mac AddSubview (incrementButton); AddSubview (decrementButton); - this.DoConstraints (new[] { - numericEditor.ConstraintTo (this, (n, c) => n.Width == c.Width - (stepperWidth + stepperSpace + 1)), - numericEditor.ConstraintTo (this, (n, c) => n.Height == PropertyEditorControl.DefaultControlHeight - 3), - - incrementButton.ConstraintTo (numericEditor, (s, n) => s.Left == n.Right + stepperSpace), - incrementButton.ConstraintTo (numericEditor, (s, n) => s.Top == n.Top), - incrementButton.ConstraintTo (numericEditor, (s, n) => s.Width == stepperWidth), - incrementButton.ConstraintTo (numericEditor, (s, n) => s.Height == stepperTopHeight), - - decrementButton.ConstraintTo (numericEditor, (s, n) => s.Left == n.Right + stepperSpace), - decrementButton.ConstraintTo (numericEditor, (s, n) => s.Top == n.Top + stepperTopHeight), - decrementButton.ConstraintTo (numericEditor, (s, n) => s.Width == stepperWidth), - decrementButton.ConstraintTo (numericEditor, (s, n) => s.Height == stepperBotHeight), + 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.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.Width, NSLayoutRelation.Equal, 1f, stepperWidth), + 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.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), }); PropertyEditorPanel.ThemeManager.ThemeChanged += ThemeManager_ThemeChanged; diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/UnfocusableTextField.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/UnfocusableTextField.cs index 5636bc8..d3abc2a 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/Custom/UnfocusableTextField.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/UnfocusableTextField.cs @@ -33,6 +33,11 @@ namespace Xamarin.PropertyEditing.Mac internal set { this.label.StringValue = value; } } + public NSColor TextColor { + get { return this.label.TextColor; } + internal set { this.label.TextColor = value; } + } + public UnfocusableTextField () { SetDefaultTextProperties (); diff --git a/Xamarin.PropertyEditing.Mac/Controls/CustomExpressionView.cs b/Xamarin.PropertyEditing.Mac/Controls/CustomExpressionView.cs index 3c6942b..4ac1973 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/CustomExpressionView.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/CustomExpressionView.cs @@ -23,23 +23,23 @@ namespace Xamarin.PropertyEditing.Mac TranslatesAutoresizingMaskIntoConstraints = false, }; - vmType = viewModel.GetType (); - customExpressionPropertyInfo = vmType.GetProperty (CustomExpressionPropertyString); - var value = customExpressionPropertyInfo.GetValue (viewModel); + this.vmType = viewModel.GetType (); + this.customExpressionPropertyInfo = vmType.GetProperty (CustomExpressionPropertyString); + var value = this.customExpressionPropertyInfo.GetValue (viewModel); if (value != null) customExpressionField.StringValue = (string)value; customExpressionField.Activated += (sender, e) => { - customExpressionPropertyInfo.SetValue (viewModel, customExpressionField.StringValue); + this.customExpressionPropertyInfo.SetValue (viewModel, customExpressionField.StringValue); }; AddSubview (customExpressionField); - this.DoConstraints (new[] { - customExpressionField.ConstraintTo (this, (s, c) => s.Top == c.Top + 37), - customExpressionField.ConstraintTo (this, (s, c) => s.Left == c.Left + 38), - customExpressionField.ConstraintTo (this, (s, c) => s.Width == c.Width - 57), - customExpressionField.ConstraintTo (this, (s, c) => s.Height == 24), + this.AddConstraints (new[] { + 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), }); } } diff --git a/Xamarin.PropertyEditing.Mac/Controls/ErrorMessageView.cs b/Xamarin.PropertyEditing.Mac/Controls/ErrorMessageView.cs index 0b55b72..7089718 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/ErrorMessageView.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/ErrorMessageView.cs @@ -11,7 +11,7 @@ namespace Xamarin.PropertyEditing.Mac { const int DefaultIconButtonSize = 24; - NSTextField ErrorMessages; + private NSTextField errorMessages; public ErrorMessageView (IEnumerable errors) { @@ -33,31 +33,34 @@ namespace Xamarin.PropertyEditing.Mac AddSubview (viewTitle); - ErrorMessages = new NSTextField { + this.errorMessages = new NSTextField { BackgroundColor = NSColor.Clear, Editable = false, TranslatesAutoresizingMaskIntoConstraints = false, }; - ErrorMessages.Cell.Wraps = true; + this.errorMessages.Cell.Wraps = true; foreach (var error in errors) { - ErrorMessages.StringValue += error + "\n"; + this.errorMessages.StringValue += error + "\n"; } - AddSubview (ErrorMessages); + AddSubview (this.errorMessages); - this.DoConstraints (new[] { - iconView.ConstraintTo (this, (iv, c) => iv.Top == c.Top + 5), - iconView.ConstraintTo (this, (iv, c) => iv.Left == c.Left + 5), - iconView.ConstraintTo (this, (iv, c) => iv.Width == DefaultIconButtonSize), - iconView.ConstraintTo (this, (iv, c) => iv.Height == DefaultIconButtonSize), - viewTitle.ConstraintTo (this, (vt, c) => vt.Top == c.Top + 7), - viewTitle.ConstraintTo (this, (vt, c) => vt.Width == 120), - viewTitle.ConstraintTo (this, (vt, c) => vt.Height == 24), - ErrorMessages.ConstraintTo (this, (s, c) => s.Top == c.Top + 35), - ErrorMessages.ConstraintTo (this, (s, c) => s.Left == c.Left + 5), - ErrorMessages.ConstraintTo (this, (s, c) => s.Width == c.Width - 10), - ErrorMessages.ConstraintTo (this, (s, c) => s.Height == c.Height - 40), + this.AddConstraints (new[] { + NSLayoutConstraint.Create (iconView, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 5f), + NSLayoutConstraint.Create (iconView, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, 5f), + NSLayoutConstraint.Create (iconView, NSLayoutAttribute.Width, NSLayoutRelation.Equal, 1f, DefaultIconButtonSize), + NSLayoutConstraint.Create (iconView, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, DefaultIconButtonSize), + + NSLayoutConstraint.Create (viewTitle, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 7f), + NSLayoutConstraint.Create (viewTitle, NSLayoutAttribute.Left, NSLayoutRelation.Equal, iconView, NSLayoutAttribute.Right, 1f, 5f), + NSLayoutConstraint.Create (viewTitle, NSLayoutAttribute.Width, NSLayoutRelation.Equal, 1f, 120), + NSLayoutConstraint.Create (viewTitle, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, PropertyEditorControl.DefaultControlHeight), + + NSLayoutConstraint.Create (this.errorMessages, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 35f), + NSLayoutConstraint.Create (this.errorMessages, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, 5f), + NSLayoutConstraint.Create (this.errorMessages, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, -10f), + NSLayoutConstraint.Create (this.errorMessages, NSLayoutAttribute.Height, NSLayoutRelation.Equal, this, NSLayoutAttribute.Height, 1f, -40f), }); this.Appearance = PropertyEditorPanel.ThemeManager.CurrentAppearance; diff --git a/Xamarin.PropertyEditing.Mac/Controls/NumericEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/NumericEditorControl.cs index 337cdf9..84a5206 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/NumericEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/NumericEditorControl.cs @@ -38,9 +38,9 @@ namespace Xamarin.PropertyEditing.Mac AddSubview (NumericEditor); - this.DoConstraints ( new[] { - NumericEditor.ConstraintTo (this, (n, c) => n.Top == c.Top + 1), - NumericEditor.ConstraintTo (this, (n, c) => n.Width == c.Width - 32), + this.AddConstraints (new[] { + NSLayoutConstraint.Create (NumericEditor, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 1f), + NSLayoutConstraint.Create (NumericEditor, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, -32f), }); } diff --git a/Xamarin.PropertyEditing.Mac/Controls/PredefinedValuesEditor.cs b/Xamarin.PropertyEditing.Mac/Controls/PredefinedValuesEditor.cs index b44d516..2a8fcd3 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/PredefinedValuesEditor.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/PredefinedValuesEditor.cs @@ -88,16 +88,16 @@ namespace Xamarin.PropertyEditing.Mac if (!this.dataPopulated) { if (ViewModel.IsConstrainedToPredefined) { this.popupButtonList.RemoveAllItems (); - foreach (string item in ViewModel.PossibleValues) { + foreach (var item in ViewModel.PossibleValues) { this.popupButtonList.AddItem (new NSMenuItem (item)); } AddSubview (this.popUpButton); - this.DoConstraints (new[] { - this.popUpButton.ConstraintTo (this, (pub, c) => pub.Width == c.Width - 33), - this.popUpButton.ConstraintTo (this, (pub, c) => pub.Height == DefaultControlHeight + 1), - this.popUpButton.ConstraintTo (this, (pub, c) => pub.Top == pub.Top + 0), + this.AddConstraints (new[] { + NSLayoutConstraint.Create (this.popUpButton, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 0f), + NSLayoutConstraint.Create (this.popUpButton, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, -33f), + NSLayoutConstraint.Create (this.popUpButton, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, DefaultControlHeight + 1), }); this.firstKeyView = this.popUpButton; @@ -112,11 +112,11 @@ namespace Xamarin.PropertyEditing.Mac AddSubview (this.comboBox); - this.DoConstraints (new[] { - this.comboBox.ConstraintTo (this, (cb, c) => cb.Width == c.Width - 34), - this.comboBox.ConstraintTo (this, (cb, c) => cb.Height == DefaultControlHeight), - this.comboBox.ConstraintTo (this, (cb, c) => cb.Top == cb.Top + 0), - this.comboBox.ConstraintTo (this, (cb, c) => cb.Left == cb.Left + 0), + 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, 0f), + NSLayoutConstraint.Create (this.comboBox, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, -34f), + NSLayoutConstraint.Create (this.comboBox, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, DefaultControlHeight), }); this.firstKeyView = this.comboBox; @@ -144,8 +144,8 @@ namespace Xamarin.PropertyEditing.Mac this.popUpButton.AccessibilityEnabled = this.popUpButton.Enabled; this.popUpButton.AccessibilityTitle = string.Format (LocalizationResources.AccessibilityCombobox, ViewModel.Property.Name); } else { - comboBox.AccessibilityEnabled = comboBox.Enabled; - comboBox.AccessibilityTitle = string.Format (LocalizationResources.AccessibilityCombobox, ViewModel.Property.Name); + this.comboBox.AccessibilityEnabled = this.comboBox.Enabled; + this.comboBox.AccessibilityTitle = string.Format (LocalizationResources.AccessibilityCombobox, ViewModel.Property.Name); } } } diff --git a/Xamarin.PropertyEditing.Mac/Controls/RatioEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/RatioEditorControl.cs index ac305fd..fedf160 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/RatioEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/RatioEditorControl.cs @@ -31,10 +31,10 @@ namespace Xamarin.PropertyEditing.Mac }; AddSubview (this.ratioEditor); - this.DoConstraints (new[] { - this.ratioEditor.ConstraintTo (this, (re, c) => re.Top == c.Top - 2), - this.ratioEditor.ConstraintTo (this, (re, c) => re.Width == c.Width - 32), - this.ratioEditor.ConstraintTo (this, (re, c) => re.Height == DefaultControlHeight), + 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), }); UpdateTheme (); diff --git a/Xamarin.PropertyEditing.Mac/Controls/RequestResource/RequestResourcePanel.cs b/Xamarin.PropertyEditing.Mac/Controls/RequestResource/RequestResourcePanel.cs index 394dec8..4907d2a 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/RequestResource/RequestResourcePanel.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/RequestResource/RequestResourcePanel.cs @@ -118,9 +118,9 @@ namespace Xamarin.PropertyEditing.Mac this.previewPanel = new RequestResourcePreviewPanel (new CGRect (Frame.Width - FrameWidthThird, 0, FrameWidthThird, Frame.Height)); AddSubview (this.previewPanel); - this.DoConstraints (new NSLayoutConstraint[] { - this.tableContainer.ConstraintTo (this, (t, c) => t.Width == c.Width - 190), - this.tableContainer.ConstraintTo (this, (t, c) => t.Height == c.Height), + this.AddConstraints (new[] { + NSLayoutConstraint.Create (this.tableContainer, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, -190f), + NSLayoutConstraint.Create (this.tableContainer, NSLayoutAttribute.Height, NSLayoutRelation.Equal, this, NSLayoutAttribute.Height, 1f, 0f), }); ReloadData (); diff --git a/Xamarin.PropertyEditing.Mac/Controls/StringEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/StringEditorControl.cs index 8b530b0..da659cf 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/StringEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/StringEditorControl.cs @@ -26,10 +26,10 @@ namespace Xamarin.PropertyEditing.Mac }; AddSubview (StringEditor); - this.DoConstraints (new[] { - StringEditor.ConstraintTo (this, (s, c) => s.Width == c.Width - 34), - StringEditor.ConstraintTo (this, (s, c) => s.Height == DefaultControlHeight - 3), - StringEditor.ConstraintTo (this, (s, c) => s.Top == s.Top + 1), + this.AddConstraints (new[] { + NSLayoutConstraint.Create (StringEditor, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 1f), + NSLayoutConstraint.Create (StringEditor, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, -34f), + NSLayoutConstraint.Create (StringEditor, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, DefaultControlHeight - 3), }); UpdateTheme (); diff --git a/Xamarin.PropertyEditing.Mac/PropertyEditorPanel.cs b/Xamarin.PropertyEditing.Mac/PropertyEditorPanel.cs index 1a8cd1e..30e9b7f 100644 --- a/Xamarin.PropertyEditing.Mac/PropertyEditorPanel.cs +++ b/Xamarin.PropertyEditing.Mac/PropertyEditorPanel.cs @@ -172,22 +172,22 @@ namespace Xamarin.PropertyEditing.Mac tableContainer.DocumentView = this.propertyTable; AddSubview (tableContainer); - this.DoConstraints (new NSLayoutConstraint[] { - this.propertyArrangeModeLabel.ConstraintTo(this, (pl, c) => pl.Top == c.Top + 5), - this.propertyArrangeModeLabel.ConstraintTo(this, (pl, c) => pl.Left == c.Left + 10), - - this.propertyArrangeMode.ConstraintTo(this, (pa, c) => pa.Top == c.Top + 4), - this.propertyArrangeMode.ConstraintTo(this, (pa, c) => pa.Left == c.Left + 90), - this.propertyArrangeMode.ConstraintTo(this, (pa, c) => pa.Width == 130), - - this.propertyFilter.ConstraintTo(this, (pf, c) => pf.Top == c.Top + 3), - this.propertyFilter.ConstraintTo(this, (pf, c) => pf.Left == c.Left + 255), - this.propertyFilter.ConstraintTo(this, (pa, c) => pa.Width == c.Width - 265), - - tableContainer.ConstraintTo(this, (t, c) => t.Top == c.Top + 30), - tableContainer.ConstraintTo(this, (t, c) => t.Left == c.Left + 10), - tableContainer.ConstraintTo(this, (t, c) => t.Width == c.Width - 20), - tableContainer.ConstraintTo(this, (t, c) => t.Height == c.Height - 37), + this.AddConstraints (new[] { + NSLayoutConstraint.Create (this.propertyArrangeModeLabel, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 5f), + NSLayoutConstraint.Create (this.propertyArrangeModeLabel, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, 10f), + + NSLayoutConstraint.Create (this.propertyArrangeMode, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 4f), + NSLayoutConstraint.Create (this.propertyArrangeMode, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, 90f), + NSLayoutConstraint.Create (this.propertyArrangeMode, NSLayoutAttribute.Width, NSLayoutRelation.Equal, 1f, 130f), + + NSLayoutConstraint.Create (this.propertyFilter, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 3f), + NSLayoutConstraint.Create (this.propertyFilter, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, 255f), + NSLayoutConstraint.Create (this.propertyFilter, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, -265f), + + NSLayoutConstraint.Create (tableContainer, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 30f), + NSLayoutConstraint.Create (tableContainer, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, 10f), + NSLayoutConstraint.Create (tableContainer, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, -20f), + NSLayoutConstraint.Create (tableContainer, NSLayoutAttribute.Height, NSLayoutRelation.Equal, this, NSLayoutAttribute.Height, 1f, -37f), }); ThemeManager.ThemeChanged += ThemeManager_ThemeChanged; |