diff options
author | Larry Ewing <lewing@xamarin.com> | 2018-04-12 04:24:43 +0300 |
---|---|---|
committer | Larry Ewing <lewing@microsoft.com> | 2018-07-16 22:05:48 +0300 |
commit | 3c2338b916d6f650291245e918963c7c660fa6b5 (patch) | |
tree | 74368b045be94d0313feccd3c80c1fde130a5d58 /Xamarin.PropertyEditing.Mac/Controls/Custom/BrushTabViewController.cs | |
parent | 6bb4a87cfdfdb1237d2b7749e63650fa976113e8 (diff) |
Start adding MaterialDesign support
Diffstat (limited to 'Xamarin.PropertyEditing.Mac/Controls/Custom/BrushTabViewController.cs')
-rw-r--r-- | Xamarin.PropertyEditing.Mac/Controls/Custom/BrushTabViewController.cs | 77 |
1 files changed, 63 insertions, 14 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 + }; } } |