diff options
author | Eric Maupin <ermaup@microsoft.com> | 2019-02-26 23:42:32 +0300 |
---|---|---|
committer | Eric Maupin <ermaup@microsoft.com> | 2019-03-06 21:49:07 +0300 |
commit | 5ed8c35ad486e3d15b05178f68c63b129b0bf690 (patch) | |
tree | 54cd072d08ef6b39c56bb85405e289fe884d4f8e /Xamarin.PropertyEditing.Mac/Controls/PropertyContainer.cs | |
parent | f8d6e23327f790b46531c696e6666e8dc2d2346a (diff) |
[mac] Fix group editor layout
Diffstat (limited to 'Xamarin.PropertyEditing.Mac/Controls/PropertyContainer.cs')
-rw-r--r-- | Xamarin.PropertyEditing.Mac/Controls/PropertyContainer.cs | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/Xamarin.PropertyEditing.Mac/Controls/PropertyContainer.cs b/Xamarin.PropertyEditing.Mac/Controls/PropertyContainer.cs new file mode 100644 index 0000000..f2b212f --- /dev/null +++ b/Xamarin.PropertyEditing.Mac/Controls/PropertyContainer.cs @@ -0,0 +1,94 @@ +using System; +using AppKit; + +namespace Xamarin.PropertyEditing.Mac +{ + internal class PropertyContainer + : NSView + { + public PropertyContainer (IHostResourceProvider hostResources, INativeContainer nativeView, bool includePropertyButton, float vertInset = 0) + { + if (hostResources == null) + throw new ArgumentNullException (nameof (hostResources)); + + NativeContainer = nativeView; + + AddSubview (this.label); + + AddConstraints (new[] { + NSLayoutConstraint.Create (this.label, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this, NSLayoutAttribute.Right, Mac.Layout.GoldenRatioLeft, 0f), + NSLayoutConstraint.Create (this.label, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 18), + }); + + if (NativeContainer != null) { + AddSubview (NativeContainer.NativeView); + NativeContainer.NativeView.TranslatesAutoresizingMaskIntoConstraints = false; + + if (NativeContainer.NativeView is PropertyEditorControl pec && pec.FirstKeyView != null) { + AddConstraint (NSLayoutConstraint.Create (this.label, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, pec.FirstKeyView, NSLayoutAttribute.CenterY, 1, 0)); + } else { + AddConstraint (NSLayoutConstraint.Create (this.label, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1, 3)); + } + + AddConstraints (new[] { + NSLayoutConstraint.Create (NativeContainer.NativeView, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1f, 0f), + NSLayoutConstraint.Create (NativeContainer.NativeView, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this.label, NSLayoutAttribute.Right, 1f, LabelToControlSpacing), + NSLayoutConstraint.Create (NativeContainer.NativeView, NSLayoutAttribute.Height, NSLayoutRelation.Equal, this, NSLayoutAttribute.Height, 1f, vertInset) + }); + + if (includePropertyButton) { + this.propertyButton = new PropertyButton (hostResources) { + TranslatesAutoresizingMaskIntoConstraints = false + }; + + AddSubview (this.propertyButton); + AddConstraints (new[] { + NSLayoutConstraint.Create (this.propertyButton, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this.label, NSLayoutAttribute.CenterY, 1, 0), + NSLayoutConstraint.Create (NativeContainer.NativeView, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this.propertyButton, NSLayoutAttribute.Left, 1f, -EditorToButtonSpacing), + NSLayoutConstraint.Create (this.propertyButton, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this, NSLayoutAttribute.Right, 1f, -ButtonToWallSpacing), + NSLayoutConstraint.Create (this.propertyButton, NSLayoutAttribute.Width, NSLayoutRelation.Equal, 1f, PropertyButton.DefaultSize), + }); + } else { + AddConstraint (NSLayoutConstraint.Create (NativeContainer.NativeView, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this, NSLayoutAttribute.Right, 1f, 0f)); + } + } else { + AddConstraint (NSLayoutConstraint.Create (this.label, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1, 0)); + } + } + + public string Label + { + get { return this.label.StringValue; } + set + { + this.label.StringValue = value + ":"; + this.label.ToolTip = value; + } + } + + protected INativeContainer NativeContainer + { + get; + } + + protected UnfocusableTextField LabelControl => this.label; + + protected PropertyButton PropertyButton => this.propertyButton; + + internal const float LabelToControlSpacing = 13f; + internal static float PropertyTotalWidth => PropertyButton.DefaultSize + ButtonToWallSpacing + EditorToButtonSpacing; + + private const float EditorToButtonSpacing = 4f; + private const float ButtonToWallSpacing = 9f; + + private readonly IHostResourceProvider hostResources; + private readonly PropertyButton propertyButton; + private readonly UnfocusableTextField label = new UnfocusableTextField { + Alignment = NSTextAlignment.Right, + Cell = { + LineBreakMode = NSLineBreakMode.TruncatingHead, + }, + TranslatesAutoresizingMaskIntoConstraints = false, + }; + } +} |