diff options
Diffstat (limited to 'Xamarin.PropertyEditing.Mac')
4 files changed, 71 insertions, 16 deletions
diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/BrushTabViewController.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/BrushTabViewController.cs index 68cdce3..64c97b1 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/Custom/BrushTabViewController.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/BrushTabViewController.cs @@ -5,6 +5,7 @@ using System.Linq; using AppKit; using CoreAnimation; using CoreGraphics; +using Foundation; using Xamarin.PropertyEditing.Drawing; using Xamarin.PropertyEditing.ViewModels; @@ -22,11 +23,9 @@ namespace Xamarin.PropertyEditing.Mac protected override void OnPropertyChanged (object sender, PropertyChangedEventArgs e) { switch (e.PropertyName) { - case nameof (BrushPropertyViewModel.Solid): - if (materialEditor != null) - materialEditor.ViewModel = ViewModel; + case nameof (BrushPropertyViewModel.MaterialDesign): + materialEditor.ViewModel = ViewModel; break; - } } @@ -38,18 +37,15 @@ namespace Xamarin.PropertyEditing.Mac public class MaterialView : NSView { + public override bool IsFlipped => true; + public MaterialView () : base () { - + Initialize (); } void Initialize () { WantsLayer = true; - Layer = new CALayer { - CornerRadius = 3, - BorderColor = NSColor.SystemGrayColor.CGColor, - BorderWidth = 1 - }; } BrushPropertyViewModel viewModel; @@ -68,16 +64,69 @@ namespace Xamarin.PropertyEditing.Mac public override void Layout () { - if (ViewModel.MaterialDesign != null) { - Layer.BackgroundColor = (MaterialDesign?.AccentColor ?? CommonColor.White).ToCGColor (); - } base.Layout (); + if (Layer.Sublayers != null) + foreach (var l in Layer.Sublayers) + l.RemoveFromSuperLayer (); + + if (MaterialDesign != null) { + var colors = MaterialDesign.Palettes.Select (p => new { p.Name, p.MainColor }).ToArray (); + int col = 0; + nfloat x = 0; + nfloat y = 0; + var width = Bounds.Width / 10; + var height = Bounds.Height / 5; + + foreach (var p in colors) { + var layer = new CALayer { + BackgroundColor = p.MainColor.ToCGColor (), + CornerRadius = 3, + Frame = new CGRect (x, y, width, height) + }; + Layer.AddSublayer (layer); + x += width; + col++; + if (col >= 10) { + x = 0; + y += height; + col = 0; + } + } + + y += 30; + x = 0; + width = Bounds.Width / MaterialDesign.NormalColorScale.Count (); + foreach (var n in MaterialDesign.NormalColorScale) { + var layer = new CALayer { + BackgroundColor = n.Value.ToCGColor (), + CornerRadius = 3, + Frame = new CGRect (x, y, width, height) + }; + Layer.AddSublayer (layer); + x += width; + } + + y += height; + x = 0; + width = Bounds.Width / MaterialDesign.AccentColorScale.Count (); + foreach (var n in MaterialDesign.AccentColorScale) { + var layer = new CALayer { + BackgroundColor = n.Value.ToCGColor (), + CornerRadius = 3, + Frame = new CGRect (x, y, width, height) + }; + Layer.AddSublayer (layer); + x += width; + } + } } } public override void LoadView () { - View = materialEditor = new MaterialView (); + View = materialEditor = new MaterialView { + ViewModel = ViewModel + }; } } diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/ResourceBrushViewController.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/ResourceBrushViewController.cs index 266975b..caee3dc 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/Custom/ResourceBrushViewController.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/ResourceBrushViewController.cs @@ -123,14 +123,12 @@ namespace Xamarin.PropertyEditing.Mac // Called when created from unmanaged code public ResourceOutlineView (IntPtr handle) : base (handle) { - Initialize (); } // Called when created directly from a XIB file [Export ("initWithCoder:")] public ResourceOutlineView (NSCoder coder) : base (coder) { - Initialize (); } public void Initialize () @@ -200,6 +198,7 @@ namespace Xamarin.PropertyEditing.Mac if (ViewModel.Resource != null && source.TryGetFacade (ViewModel?.Resource, out var facade)) { index = resourceSelector.RowForItem (facade); } + if (index < 0) resourceSelector.DeselectAll (null); else @@ -214,6 +213,11 @@ namespace Xamarin.PropertyEditing.Mac } } + public new ResourceOutlineView View { + get => base.View as ResourceOutlineView; + set => base.View = (value as ResourceOutlineView); + } + public override void LoadView () { viewDelegate.ViewModel = ViewModel; diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/SolidColorBrushEditor.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/SolidColorBrushEditor.cs index 38fa322..1a1365f 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/Custom/SolidColorBrushEditor.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/SolidColorBrushEditor.cs @@ -150,6 +150,7 @@ namespace Xamarin.PropertyEditing.Mac set { brush = value; BrushLayer = CreateBrushLayer (brush); + Opacity = brush == null ? 0 : 1; } } diff --git a/Xamarin.PropertyEditing.Mac/PropertyEditorPanel.cs b/Xamarin.PropertyEditing.Mac/PropertyEditorPanel.cs index f4cd8b6..3281d6a 100644 --- a/Xamarin.PropertyEditing.Mac/PropertyEditorPanel.cs +++ b/Xamarin.PropertyEditing.Mac/PropertyEditorPanel.cs @@ -6,6 +6,7 @@ using Foundation; using AppKit; using Xamarin.PropertyEditing.ViewModels; using Xamarin.PropertyEditing.Mac.Resources; +using Xamarin.PropertyEditing.Drawing; namespace Xamarin.PropertyEditing.Mac { |