Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/xamarin/Xamarin.PropertyEditing.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Bucyk <anbucyk@microsoft.com>2019-03-14 03:05:30 +0300
committerAnthony Bucyk <anbucyk@microsoft.com>2019-03-14 03:05:30 +0300
commitea760be0d8ae25673245c031e7c0d7d8cede8df2 (patch)
treee9767d4689551f8a22a8cbd47fa71b3a9057b170
parentd68a4792d0d34a70232478a14453da1a6e556ca3 (diff)
WIP converting color swatch to NSView. I'm not super familiar with AppKit or CoreAnimation yet, so this is mostly just me messing around and seeing what works.anbucyk-fix-mac-material-tooltips
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/Custom/MaterialColorLayer.cs49
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/Custom/MaterialView.cs6
2 files changed, 34 insertions, 21 deletions
diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/MaterialColorLayer.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/MaterialColorLayer.cs
index 418b5ca..0057f39 100644
--- a/Xamarin.PropertyEditing.Mac/Controls/Custom/MaterialColorLayer.cs
+++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/MaterialColorLayer.cs
@@ -1,3 +1,5 @@
+using System;
+using AppKit;
using CoreAnimation;
using CoreGraphics;
using Xamarin.PropertyEditing.Drawing;
@@ -11,34 +13,46 @@ namespace Xamarin.PropertyEditing.Mac
Accent
}
- class MaterialColorLayer : CATextLayer
+ class MaterialColorLayer : NSView
{
public MaterialColorLayer ()
+ {
+ Initialize ();
+ }
+
+ private void Initialize ()
{
- AddSublayer (this.selection);
+ WantsLayer = true;
}
private readonly CATextLayer selection = new CATextLayer () {
CornerRadius = 3
};
- public MaterialColorType ColorType { get; set; } = MaterialColorType.Palette;
+ public MaterialColorType ColorType { get; set; } = MaterialColorType.Palette;
+
+ public CommonColor BackgroundColor { get; set; }
+
+ public CGColor ForegroundColor { get; set; }
+
+ public CGColor BorderColor { get; set; }
+
+ public int FontSize { get; set; }
+
+ public int CornerRadius { get; set; }
+
+ public bool MasksToBounds { get; set; }
+
+ public nfloat ContentsScale { get; set; }
+
+ public CATextLayerAlignmentMode TextAlignmentMode { get; set; }
private string text;
public string Text {
get => this.text;
set {
this.text = value;
- SetNeedsLayout ();
- }
- }
-
- private CommonColor backgroundColor;
- public new CommonColor BackgroundColor {
- get => this.backgroundColor;
- set {
- this.backgroundColor = value;
- base.BackgroundColor = this.backgroundColor.ToCGColor ();
+ NeedsLayout = true;
}
}
@@ -49,17 +63,16 @@ namespace Xamarin.PropertyEditing.Mac
if (this.isSelected == value)
return;
this.isSelected = value;
- SetNeedsLayout ();
+ NeedsLayout = true;
}
}
- public override void LayoutSublayers ()
+ public override void Layout ()
{
- base.LayoutSublayers ();
-
this.selection.String = this.text;
this.selection.Frame = Bounds.Inset (3, 3);
- this.selection.BorderWidth = this.isSelected ? 2 : 0;
+ this.selection.BorderWidth = this.isSelected ? 2 : 0;
+ this.selection.BackgroundColor = BackgroundColor.ToCGColor ();
this.selection.BorderColor = ForegroundColor;
this.selection.ForegroundColor = ForegroundColor;
this.selection.FontSize = FontSize;
diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/MaterialView.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/MaterialView.cs
index 09f90b9..550dd8e 100644
--- a/Xamarin.PropertyEditing.Mac/Controls/Custom/MaterialView.cs
+++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/MaterialView.cs
@@ -86,7 +86,7 @@ namespace Xamarin.PropertyEditing.Mac
l.BorderColor = new CGColor (.5f, .5f, .5f, .5f);
l.Frame = new CGRect (x, y, width, height);
- Layer.AddSublayer (l);
+ Layer.AddSublayer (l.Layer);
x += width + 6;
col++;
if (col >= 10) {
@@ -120,7 +120,7 @@ namespace Xamarin.PropertyEditing.Mac
l.ColorType = MaterialColorType.Normal;
l.IsSelected = color.Value == ViewModel.NormalColor || color.Value == ViewModel.Color;
l.Frame = new CGRect (x, 0, width, height);
- normal.AddSublayer (l);
+ normal.AddSublayer (l.Layer);
x += width;
}
@@ -144,7 +144,7 @@ namespace Xamarin.PropertyEditing.Mac
l.ColorType = MaterialColorType.Accent;
l.IsSelected = color.Value == ViewModel.AccentColor || color.Value == ViewModel.Color;
l.Frame = new CGRect (x, 0, width, height);
- accent.AddSublayer (l);
+ accent.AddSublayer (l.Layer);
x += width;
}
}