diff options
author | Eric Maupin <ermaup@microsoft.com> | 2019-01-10 22:57:49 +0300 |
---|---|---|
committer | Eric Maupin <ermaup@microsoft.com> | 2019-01-11 23:19:25 +0300 |
commit | 747eeefbab8a87ad4789eddc81acf065ee6cee95 (patch) | |
tree | a50aad68b196d7552a26e76e24a377a4027a162a /Xamarin.PropertyEditing.Mac/Controls | |
parent | 77afbdcdfb26a2d3e3fc32f097fadd64afc105cb (diff) |
[mac] Improve group/brush editors
Diffstat (limited to 'Xamarin.PropertyEditing.Mac/Controls')
7 files changed, 126 insertions, 42 deletions
diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/BrushTabViewController.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/BrushTabViewController.cs index 52b9c31..50e07e5 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/Custom/BrushTabViewController.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/BrushTabViewController.cs @@ -15,10 +15,13 @@ namespace Xamarin.PropertyEditing.Mac { public BrushTabViewController (IHostResourceProvider hostResources)
: base (hostResources) - { - PreferredContentSize = new CGSize (430, 230); + {
+ TabBorderColor = NamedResources.TabBorderColor;
+ TabBackgroundColor = NamedResources.PadBackgroundColor;
+ + PreferredContentSize = new CGSize (430, 280); TransitionOptions = NSViewControllerTransitionOptions.None; - EdgeInsets = new NSEdgeInsets (0, 12, 12, 12);
+ ContentPadding = new NSEdgeInsets (10, 10, 10, 10);
this.filterResource = new NSSearchField {
ControlSize = NSControlSize.Mini,
@@ -47,7 +50,7 @@ namespace Xamarin.PropertyEditing.Mac public nint GetHeight (EditorViewModel viewModel) { - return (int)(PreferredContentSize.Height + EdgeInsets.Top + EdgeInsets.Bottom); + return (int)(PreferredContentSize.Height + ContentPadding.Top + ContentPadding.Bottom); } public override void OnViewModelChanged (BrushPropertyViewModel oldModel) @@ -129,7 +132,7 @@ namespace Xamarin.PropertyEditing.Mac }
if (image != null) { - item.Identifier = new NSString (image); // Using the Identifier object, to avoid unused NSImage creation when selection happens in GetView () + item.Identifier = new NSObjectFacade (image); // Using the Identifier object, to avoid unused NSImage creation when selection happens in GetView () }
InsertTabViewItem (item, i); diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/PropertyButton.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/PropertyButton.cs index ef7e464..6158cdf 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/Custom/PropertyButton.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/PropertyButton.cs @@ -187,6 +187,8 @@ namespace Xamarin.PropertyEditing.Mac ToolTip = string.Empty; break; } + + ToggleFocusImage (); } private void OnPropertyChanged (object sender, System.ComponentModel.PropertyChangedEventArgs e) diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/ResourceBrushViewController.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/ResourceBrushViewController.cs index 82c0256..cf73e47 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/Custom/ResourceBrushViewController.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/ResourceBrushViewController.cs @@ -80,7 +80,7 @@ namespace Xamarin.PropertyEditing.Mac // create a table view and a scroll view var tableContainer = new NSScrollView (new CGRect (10, PreferredContentSize.Height - 210, PreferredContentSize.Width, PreferredContentSize.Height)) { - TranslatesAutoresizingMaskIntoConstraints = false, + AutoresizingMask = NSViewResizingMask.WidthSizable | NSViewResizingMask.HeightSizable }; // add the panel to the window diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/ResourceOutlineView.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/ResourceOutlineView.cs index d5c748c..380791e 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/Custom/ResourceOutlineView.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/ResourceOutlineView.cs @@ -1,5 +1,6 @@ using System; using AppKit; +using CoreGraphics; using Foundation; using Xamarin.PropertyEditing.Mac.Resources; using Xamarin.PropertyEditing.ViewModels; @@ -14,6 +15,7 @@ namespace Xamarin.PropertyEditing.Mac public ResourceOutlineView () { Initialize (); + RowHeight = 24; } // Called when created from unmanaged code diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/ResourceOutlineViewDelegate.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/ResourceOutlineViewDelegate.cs index 2777c78..e2e03f0 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/Custom/ResourceOutlineViewDelegate.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/ResourceOutlineViewDelegate.cs @@ -28,7 +28,8 @@ namespace Xamarin.PropertyEditing.Mac if (cbv == null) { cbv = new CommonBrushView (this.hostResources) { Identifier = resourceIdentifier, - Frame = new CGRect (0, 0, 30, 10), + Frame = new CGRect (0, 0, 30, 18), + AutoresizingMask = NSViewResizingMask.WidthSizable }; } @@ -51,12 +52,6 @@ namespace Xamarin.PropertyEditing.Mac } } - - public override nfloat GetRowHeight (NSOutlineView outlineView, NSObject item) - { - return PropertyEditorControl.DefaultControlHeight; - } - private const string labelIdentifier = "label"; private const string resourceIdentifier = "resource"; diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/UnderlinedTabViewController.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/UnderlinedTabViewController.cs index 0a32a71..350a960 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/Custom/UnderlinedTabViewController.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/UnderlinedTabViewController.cs @@ -1,6 +1,7 @@ -using System;
-using System.Linq; +using System; + using AppKit; +using CoreGraphics; using Foundation; namespace Xamarin.PropertyEditing.Mac @@ -15,6 +16,26 @@ namespace Xamarin.PropertyEditing.Mac throw new ArgumentNullException (nameof (hostResources));
HostResources = hostResources; + + this.tabContainer = new DynamicFill (hostResources, null); + this.border = new DynamicFill (hostResources, null) { + Frame = new CGRect (0, 0, 1, 1), + BorderWidth = 0, + BoxType = NSBoxType.NSBoxCustom, + AutoresizingMask = NSViewResizingMask.WidthSizable, + }; + } + + public string TabBackgroundColor + { + get => this.tabContainer.FillColorName; + set => this.tabContainer.FillColorName = value; + } + + public string TabBorderColor + { + get => this.border.FillColorName; + set => this.border.FillColorName = value; }
public override void InsertTabViewItem (NSTabViewItem tabViewItem, nint index) @@ -33,14 +54,12 @@ namespace Xamarin.PropertyEditing.Mac base.RemoveTabViewItem (tabViewItem); } - public NSEdgeInsets EdgeInsets { + /// <remarks>This doesn't actually support independent left/right padding, they'll be added and content centered.</remarks> + public NSEdgeInsets ContentPadding { get => this.edgeInsets; set { this.edgeInsets = value; - if (this.outerStack != null) { - this.outerStack.EdgeInsets = value; - this.innerStack.EdgeInsets = value; - } + UpdatePadding (); } } @@ -72,33 +91,38 @@ namespace Xamarin.PropertyEditing.Mac } public override void LoadView () - { - this.outerStack = new NSStackView () { - Orientation = NSUserInterfaceLayoutOrientation.Horizontal, - Spacing = 0, - EdgeInsets = new NSEdgeInsets (0, edgeInsets.Left, 0, edgeInsets.Right) - }; + {
+ this.innerStack = new NSStackView () {
+ Spacing = 0,
+ Alignment = NSLayoutAttribute.Left,
+ Orientation = NSUserInterfaceLayoutOrientation.Vertical,
+ };
+
+ this.tabContainer.ContentView = this.tabStack; - this.innerStack = new NSStackView () { - Spacing = 0, - Alignment = NSLayoutAttribute.Left, - Orientation = NSUserInterfaceLayoutOrientation.Vertical, - EdgeInsets = new NSEdgeInsets (edgeInsets.Top, 0, edgeInsets.Bottom, 0) - }; + this.innerStack.AddView (this.tabContainer, NSStackViewGravity.Top);
+ this.innerStack.AddView (border, NSStackViewGravity.Top); + this.innerStack.AddView (TabView, NSStackViewGravity.Bottom);
+ + View = this.innerStack;
+
+ this.innerStack.AddConstraints (new[] {
+ NSLayoutConstraint.Create (this.tabContainer, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this.innerStack, NSLayoutAttribute.Width, 1, 0),
+ NSLayoutConstraint.Create (TabView, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, this.innerStack, NSLayoutAttribute.CenterX, 1, 0),
+ }); - this.outerStack.AddView (this.innerStack, NSStackViewGravity.Leading); - this.innerStack.AddView (this.tabStack, NSStackViewGravity.Leading); - this.innerStack.AddView (TabView, NSStackViewGravity.Bottom); - View = this.outerStack; + UpdatePadding (); }
protected IHostResourceProvider HostResources { get; - }
+ } + + private NSLayoutConstraint sidePadding, topPadding, bottomPadding;
- private IUnderliningTabView selected;
- private NSStackView outerStack;
+ private IUnderliningTabView selected; + private DynamicFill tabContainer, border;
private NSStackView innerStack;
private NSStackView tabStack = new NSStackView () {
Spacing = 10f,
@@ -108,6 +132,62 @@ namespace Xamarin.PropertyEditing.Mac private NSEdgeInsets edgeInsets = new NSEdgeInsets (0, 0, 0, 0);
+ private class DynamicFill
+ : NSBox + {
+ public DynamicFill (IHostResourceProvider hostResources, string colorName) + { + this.hostResources = hostResources;
+ BorderWidth = 0;
+ BoxType = NSBoxType.NSBoxCustom;
+ TranslatesAutoresizingMaskIntoConstraints = false; + this.colorName = colorName; + if (colorName == null) + FillColor = NSColor.Clear; + + ViewDidChangeEffectiveAppearance (); + } + + public string FillColorName + { + get => this.colorName; + set + { + this.colorName = value; + if (value == null) + FillColor = NSColor.Clear; + + ViewDidChangeEffectiveAppearance (); + } + }
+ + public override void ViewDidChangeEffectiveAppearance () + { + if (this.colorName == null) + return; + + FillColor = this.hostResources.GetNamedColor (this.colorName); + }
+
+ private readonly IHostResourceProvider hostResources; + private string colorName; + }
+
+ private void UpdatePadding() + { + if (this.innerStack == null) + return; + + if (this.sidePadding != null) + this.innerStack.RemoveConstraints (new[] { this.sidePadding, this.topPadding, this.bottomPadding }); + + this.sidePadding = NSLayoutConstraint.Create (TabView, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this.innerStack, NSLayoutAttribute.Width, 1, -(ContentPadding.Left + ContentPadding.Right)); + this.bottomPadding = NSLayoutConstraint.Create (TabView, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, this.innerStack, NSLayoutAttribute.Bottom, 1, -(ContentPadding.Bottom)); + this.topPadding = NSLayoutConstraint.Create (TabView, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this.border, NSLayoutAttribute.Bottom, 1, ContentPadding.Top); + + this.innerStack.AddConstraints (new[] { this.sidePadding, this.topPadding, this.bottomPadding }); + } + private void SetSelected (int index)
{
if (this.selected != null) {
@@ -120,10 +200,11 @@ namespace Xamarin.PropertyEditing.Mac }
private NSView GetView (NSTabViewItem item)
- {
+ { + var id = item.Identifier as NSObjectFacade;
NSView tabView;
- if (item.Identifier != null) {
- tabView = new UnderlinedImageView (HostResources, ((NSString)item.Identifier).ToString()) {
+ if (id != null) {
+ tabView = new UnderlinedImageView (HostResources, ((string)id.Target)) {
Selected = this.tabStack.Views.Length == SelectedTabViewItemIndex,
ToolTip = item.ToolTip
};
diff --git a/Xamarin.PropertyEditing.Mac/Controls/GroupEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/GroupEditorControl.cs index 95f458a..05776c5 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/GroupEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/GroupEditorControl.cs @@ -35,6 +35,7 @@ namespace Xamarin.PropertyEditing.Mac BoxType = NSBoxType.NSBoxCustom, BorderWidth = 0, TranslatesAutoresizingMaskIntoConstraints = false, + ContentViewMargins = new CGSize (0, 0) }; this.container.AddView (this.host, NSStackViewGravity.Top); |