diff options
8 files changed, 132 insertions, 56 deletions
diff --git a/Xamarin.PropertyEditing.Mac/Controls/BrushEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/BrushEditorControl.cs index ca7cadb..f0964b1 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/BrushEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/BrushEditorControl.cs @@ -30,7 +30,7 @@ namespace Xamarin.PropertyEditing.Mac { if (Popover == null) return; - Popover.SetAppearance (PropertyEditorPanel.ThemeManager.CurrentAppearance); + //Popover.SetAppearance (PropertyEditorPanel.ThemeManager.CurrentAppearance); Popover?.Show (new CGRect (20, this.Frame.Height / 2 - 2.5, 5, 5), this, NSRectEdge.MinYEdge); } } @@ -39,17 +39,16 @@ namespace Xamarin.PropertyEditing.Mac { public BrushEditorControl () { - base.TranslatesAutoresizingMaskIntoConstraints = false; - - + TranslatesAutoresizingMaskIntoConstraints = false; this.colorEditor = new BrushTabViewController (); this.popover = new NSPopover (); popover.Behavior = NSPopoverBehavior.Transient; popover.ContentViewController = brushTabViewController = new BrushTabViewController { - PreferredContentSize = new CGSize (200, 200) + PreferredContentSize = new CGSize (300, 250) }; - RowHeight = 200 + 30; + + RowHeight = 200 + 28; this.popUpButton = new ColorPopUpButton { TranslatesAutoresizingMaskIntoConstraints = false, @@ -60,6 +59,19 @@ namespace Xamarin.PropertyEditing.Mac popupButtonList = new NSMenu (); popUpButton.Menu = popupButtonList; + var view = this.colorEditor.View; + + this.DoConstraints (new[] { + popUpButton.ConstraintTo (this, (pub, c) => pub.Width == c.Width - 34), + popUpButton.ConstraintTo (this, (pub, c) => pub.Height == DefaultControlHeight + 1), + popUpButton.ConstraintTo (this, (pub, c) => pub.Left == c.Left + 4), + popUpButton.ConstraintTo (this, (pub, c) => pub.Top == c.Top + 0), + view.ConstraintTo (popUpButton, (v, pub) => v.Top == pub.Bottom), + view.ConstraintTo (popUpButton, (v, pub) => v.Left == pub.Left) + }); + + AddSubview (this.popUpButton); + AddSubview (this.colorEditor.View); UpdateTheme (); } @@ -79,8 +91,6 @@ namespace Xamarin.PropertyEditing.Mac Frame = new CGRect (0, 0, 30, 10) }; - bool dataPopulated; - public override NSView FirstKeyView => this.popUpButton; public override NSView LastKeyView => this.popUpButton; @@ -142,19 +152,7 @@ namespace Xamarin.PropertyEditing.Mac protected override void OnViewModelChanged (PropertyViewModel oldModel) { - if (!dataPopulated) { - this.DoConstraints (new[] { - popUpButton.ConstraintTo (this, (pub, c) => pub.Width == c.Width - 34), - popUpButton.ConstraintTo (this, (pub, c) => pub.Height == DefaultControlHeight + 1), - popUpButton.ConstraintTo (this, (pub, c) => pub.Left == pub.Left + 4), - popUpButton.ConstraintTo (this, (pub, c) => pub.Top == pub.Top + 0), - }); - - AddSubview (this.popUpButton); - AddSubview (this.colorEditor.View); - } UpdateValue (); - dataPopulated = true; } - } + } } diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/BrushTabViewController.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/BrushTabViewController.cs index 9c50654..7f775f8 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/Custom/BrushTabViewController.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/BrushTabViewController.cs @@ -17,7 +17,7 @@ namespace Xamarin.PropertyEditing.Mac public MaterialBrushEditorViewController () { - PreferredContentSize = new CGSize (200, 200); + PreferredContentSize = new CGSize (200, 230); } public override void OnPropertyChanged (object sender, PropertyChangedEventArgs e) @@ -314,6 +314,11 @@ namespace Xamarin.PropertyEditing.Mac bool inhibitSelection; + public BrushTabViewController () + { + PreferredContentSize = new CGSize (300, 230); + } + public override void OnViewModelChanged (BrushPropertyViewModel oldModel) { inhibitSelection = true; @@ -344,19 +349,19 @@ namespace Xamarin.PropertyEditing.Mac item.ViewController = material; break; case CommonBrushType.Resource: - var material2 = new ResourceBrushViewController (); - material2.ViewModel = ViewModel; - item.ViewController = material2; + var resource = new ResourceBrushViewController (); + resource.ViewModel = ViewModel; + item.ViewController = resource; break; case CommonBrushType.Gradient: - var material3 = new EmptyBrushEditorViewController (); - material3.ViewModel = ViewModel; - item.ViewController = material3; + var gradient = new EmptyBrushEditorViewController (); + gradient.ViewModel = ViewModel; + item.ViewController = gradient; break; case CommonBrushType.NoBrush: - var material4 = new EmptyBrushEditorViewController (); - material4.ViewModel = ViewModel; - item.ViewController = material4; + var none = new EmptyBrushEditorViewController (); + none.ViewModel = ViewModel; + item.ViewController = none; break; } @@ -404,14 +409,18 @@ namespace Xamarin.PropertyEditing.Mac base.DidSelect (tabView, item); ViewModel.SelectedBrushType = ViewModel.BrushTypes[item.Label]; } - + public override void ViewDidLoad() { + var old = View.Frame; + old.Height = 200; + View.Frame = old; + inhibitSelection = true; base.ViewDidLoad(); inhibitSelection = false; - var old = View.Frame; + old = View.Frame; old.Height = 200; View.Frame = old; } diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/ColorComponentEditor.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/ColorComponentEditor.cs index 7328f21..8d47998 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/Custom/ColorComponentEditor.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/ColorComponentEditor.cs @@ -57,8 +57,10 @@ namespace Xamarin.PropertyEditing.Mac ce.Editor.TranslatesAutoresizingMaskIntoConstraints = true; ce.Editor.ValueChanged += UpdateComponent; + ce.Editor.BackgroundColor = NSColor.Clear; AddSubview (ce.Label); AddSubview (ce.Editor); + Layer.AddSublayer (ce.Gradient); return ce; } @@ -103,14 +105,40 @@ namespace Xamarin.PropertyEditing.Mac void Initialize () { + //TranslatesAutoresizingMaskIntoConstraints = false; WantsLayer = true; Editors = CreateEditors (EditorType); + /* + var top = new NSView { + TranslatesAutoresizingMaskIntoConstraints = false + }; + this.AddSubview (top); + + var list = new List<NSLayoutConstraint> (); + list.AddRange (new[] { + //this.ConstraintTo (null, (t, c) => t.Height == ), + //this.ConstraintTo (null, (t, c) => t.Width == 200), + top.ConstraintTo (this, (t, c) => t.Top == c.Top), + top.ConstraintTo (this, (t, c) => t.Left == c.Left), + top.ConstraintTo (this, (t, c) => t.Width == c.Width), + top.ConstraintTo (this, (t, c) => t.Height == 6) + }); - this.DoConstraints (Editors.Select ( - ce => new[] { - ce.Editor.ConstraintTo (this, (editor, c) => editor.Width == 90), - ce.Editor.ConstraintTo (this, (editor, c) => editor.Height == DefaultControlHeight) - }).SelectMany (e => e).ToArray ()); + NSView prev = top; + foreach (var ce in Editors) { + list.AddRange (new[] { + ce.Label.ConstraintTo (prev, (label, p) => label.Top == p.Bottom), + ce.Label.ConstraintTo (this, (label, c) => label.Left == c.Left + 6), + ce.Label.ConstraintTo (this, (label, c) => label.Height == DefaultControlHeight), + ce.Label.ConstraintTo (this, (label, c) => label.Width == 20), + ce.Editor.ConstraintTo (ce.Label, (editor, label) => editor.Left == label.Right), + ce.Editor.ConstraintTo (prev, (editor, p) => editor.Top == p.Bottom), + ce.Editor.ConstraintTo (this, (editor, c) => editor.Right == c.Right - 6), + ce.Editor.ConstraintTo (this, (editor, c) => editor.Height == DefaultControlHeight)}); + prev = ce.Label; + } + this.DoConstraints (list.ToArray ()); + */ } void UpdateComponent (object sender, EventArgs args) @@ -137,7 +165,12 @@ namespace Xamarin.PropertyEditing.Mac } } - ComponentSet set; + public override void UpdateConstraints() + { + base.UpdateConstraints(); + } + + ComponentSet set; public override void MouseDown (NSEvent theEvent) { if (!ClickableGradients) { @@ -194,15 +227,18 @@ namespace Xamarin.PropertyEditing.Mac public override void Layout () { base.Layout (); + var frame = Frame.Bounds ().Border (new CommonThickness (padding)); var labelFrame = new CGRect (frame.X, frame.Height - DefaultControlHeight, 20, DefaultControlHeight); var editorFrame = new CGRect (labelFrame.Right, labelFrame.Y, frame.Width - labelFrame.Right, DefaultControlHeight); var yOffset = DefaultControlHeight + DefaultGradientHeight + 3; + foreach (var e in Editors) { + //e.Label.TopAnchor.ConstraintEqualToAnchor (this.TopAnchor); e.Label.Frame = labelFrame; e.Editor.Frame = editorFrame; - e.Gradient.Frame = new CGRect (editorFrame.X, editorFrame.Y - DefaultGradientHeight + 1, e.Editor.TextField.Frame.Width, DefaultGradientHeight); + e.Gradient.Frame = new CGRect (editorFrame.X, editorFrame.Y - DefaultGradientHeight, editorFrame.Width - 16, DefaultGradientHeight); e.Gradient.BorderColor = NSColor.DisabledControlText.CGColor; e.Gradient.ContentsScale = Window?.Screen?.BackingScaleFactor ?? NSScreen.MainScreen.BackingScaleFactor; labelFrame = labelFrame.Translate (0, -yOffset); @@ -300,6 +336,7 @@ namespace Xamarin.PropertyEditing.Mac MinimumValue = component.MinimumValue; MaximumValue = component.MaximumValue; IncrementValue = component.IncrementValue; + Digits = 2; } public ComponentEditor ComponentEditor { get; } diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/ColorComponentViewController.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/ColorComponentViewController.cs index 48541fe..c26c776 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/Custom/ColorComponentViewController.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/ColorComponentViewController.cs @@ -1,6 +1,7 @@ using System; using System.ComponentModel; using AppKit; +using CoreGraphics; using Xamarin.PropertyEditing.ViewModels; namespace Xamarin.PropertyEditing.Mac @@ -11,6 +12,7 @@ namespace Xamarin.PropertyEditing.Mac public ColorComponentViewController (ChannelEditorType type) : base () { + PreferredContentSize = new CGSize (200, 200); this.EditorType = type; } diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/NumericSpinEditor.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/NumericSpinEditor.cs index da8c42e..c3715b7 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/Custom/NumericSpinEditor.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/NumericSpinEditor.cs @@ -42,7 +42,7 @@ namespace Xamarin.PropertyEditing.Mac public override CGSize IntrinsicContentSize { get { var baseSize = stepper.IntrinsicContentSize; - return new CGSize (baseSize.Width + 20, baseSize.Height); + return new CGSize (baseSize.Width + 40, baseSize.Height); } } diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/SolidColorBrushEditor.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/SolidColorBrushEditor.cs index fd5c01e..6f7d350 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/Custom/SolidColorBrushEditor.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/SolidColorBrushEditor.cs @@ -12,7 +12,7 @@ using Xamarin.PropertyEditing.ViewModels; namespace Xamarin.PropertyEditing.Mac { - abstract class ColorEditorView : NSControl, INotifyingListner<SolidBrushViewModel> + abstract class ColorEditorView : NSView, INotifyingListner<SolidBrushViewModel> { protected const float padding = 3; protected NotifyingViewAdaptor<SolidBrushViewModel> adaptor { get; } @@ -93,18 +93,26 @@ namespace Xamarin.PropertyEditing.Mac { public ColorEditorLayer () { - Actions = new NSDictionary ( - new NSString ("onOrderIn"), new NSNull (), - new NSString ("onOrderOut"), new NSNull (), - new NSString ("sublayers"), new NSNull (), - new NSString ("bounds"), new NSNull ()); } + + public ColorEditorLayer (IntPtr handle) : base (handle) + { + } + abstract public void UpdateFromModel (EditorInteraction viewModel); abstract public void UpdateFromLocation (EditorInteraction viewModel, CGPoint location); } class CommonGradientBrushLayer : CALayer { + public CommonGradientBrushLayer () + { + } + + public CommonGradientBrushLayer (IntPtr handle) : base () + { + } + CommonGradientBrush brush; public CommonGradientBrush Brush { @@ -248,6 +256,10 @@ namespace Xamarin.PropertyEditing.Mac AddSublayer (Clip); } + public HistoryLayer (IntPtr handle) : base (handle) + { + } + readonly CALayer Previous = new CALayer (); readonly CALayer Current = new CALayer (); readonly CALayer Clip = new CALayer () { @@ -315,6 +327,10 @@ namespace Xamarin.PropertyEditing.Mac }); } + public ShadeLayer (IntPtr handle) : base (handle) + { + } + CALayer Grip = new CALayer { BorderColor = new CGColor (1,1,1), BorderWidth = 1, @@ -406,6 +422,10 @@ namespace Xamarin.PropertyEditing.Mac AddSublayer (Grip); } + public HueLayer (IntPtr handle) : base (handle) + { + } + CAGradientLayer Colors = new CAGradientLayer { BorderColor = new CGColor (.5f, .5f, .5f, .5f), StartPoint = new CGPoint (0,1), @@ -493,7 +513,6 @@ namespace Xamarin.PropertyEditing.Mac public void Commit () { ViewModel.Color = Color; - ViewModel.CommitLastColor (); } } @@ -503,10 +522,11 @@ namespace Xamarin.PropertyEditing.Mac HueLayer Hue = new HueLayer (); HistoryLayer History = new HistoryLayer (); - CALayer Background = new CALayer { + readonly CALayer Background = new CALayer { CornerRadius = 3, BorderWidth = 1 }; + readonly CALayer componentBackground = new CALayer { CornerRadius = 3, BorderWidth = 1 @@ -562,9 +582,9 @@ namespace Xamarin.PropertyEditing.Mac location = ConvertPointToLayer (location); interaction = null; foreach (var layer in Layer.Sublayers) { - var hit = layer.HitTest (location); + var hit = layer.PresentationLayer.HitTest (location); - for (var c = hit; c != null; c = c.SuperLayer) { + for (var c = hit?.ModelLayer; c != null; c = c.SuperLayer) { var active = c as ColorEditorLayer; if (active != null) { interaction = new EditorInteraction (ViewModel, active); @@ -629,6 +649,9 @@ namespace Xamarin.PropertyEditing.Mac { base.Layout (); + if (Frame.IsEmpty || Frame.IsInfinite () || double.IsNaN (Frame.X) || double.IsInfinity (Frame.X)) + return; + var secondarySpan = 20; var primarySpan = Frame.Height - 2 * padding - secondarySpan; var firstBase = padding; @@ -638,18 +661,18 @@ namespace Xamarin.PropertyEditing.Mac Background.BorderColor = new CGColor (.5f, .5f, .5f, .5f); Background.BackgroundColor = NSColor.ControlBackground.CGColor; Background.Frame = new CGRect (0, 0, Frame.Height, Frame.Height); - Background.SetNeedsDisplay (); + //Background.SetNeedsDisplay (); componentBackground.BorderColor = new CGColor (.5f, .5f, .5f, .5f); componentBackground.BackgroundColor = NSColor.ControlBackground.CGColor; componentBackground.Frame = new CGRect (0, 0, Frame.Height, Frame.Height); - componentBackground.SetNeedsDisplay (); + //componentBackground.SetNeedsDisplay (); var x = Frame.Height + 4 * padding; componentBackground.Frame = new CGRect (Frame.Height + 4 * padding, 0, Frame.Width - x, Frame.Height); Hue.Frame = new CGRect (firstStop, secondBase, secondarySpan, primarySpan); Hue.GripColor = NSColor.Text.CGColor; - Hue.SetNeedsDisplay (); + //Hue.SetNeedsDisplay (); Shade.Frame = new CGRect (firstBase, secondBase, primarySpan, primarySpan); History.Frame = new CGRect (firstBase, firstBase, primarySpan, secondarySpan); var inter = interaction ?? new EditorInteraction (ViewModel, null); diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/SolidColorBrushEditorViewController.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/SolidColorBrushEditorViewController.cs index bec79e5..3c0cfa9 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/Custom/SolidColorBrushEditorViewController.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/SolidColorBrushEditorViewController.cs @@ -1,5 +1,6 @@ using System; using System.ComponentModel; +using CoreGraphics; using Xamarin.PropertyEditing.ViewModels; namespace Xamarin.PropertyEditing.Mac @@ -8,6 +9,11 @@ namespace Xamarin.PropertyEditing.Mac { SolidColorBrushEditor brushEditor; + public SolidColorBrushEditorViewController () + { + PreferredContentSize = new CGSize (300, 230); + } + public override void OnPropertyChanged (object sender, PropertyChangedEventArgs e) { switch (e.PropertyName) { @@ -31,7 +37,7 @@ namespace Xamarin.PropertyEditing.Mac public override void ViewDidLoad() { base.ViewDidLoad(); - //View.Appearance = PropertyEditorPanel.ThemeManager.CurrentAppearance; + if (ViewModel != null) brushEditor.ViewModel = ViewModel?.Solid; } @@ -39,7 +45,6 @@ namespace Xamarin.PropertyEditing.Mac public override void LoadView () { View = brushEditor = new SolidColorBrushEditor { - //Appearance = PropertyEditorPanel.ThemeManager.CurrentAppearance, ViewModel = ViewModel?.Solid }; } diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/UnfocusableTextField.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/UnfocusableTextField.cs index efce5be..5d56e65 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/Custom/UnfocusableTextField.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/UnfocusableTextField.cs @@ -31,6 +31,7 @@ namespace Xamarin.PropertyEditing.Mac AccessibilityElement = false; } + /* public override void DrawRect (CGRect dirtyRect) { CGPoint origin = new CGPoint (0.0f, 4.0f); @@ -38,5 +39,6 @@ namespace Xamarin.PropertyEditing.Mac this.AttributedStringValue.DrawInRect (rect); } + */ } }
\ No newline at end of file |