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:
authorEric Maupin <ermaup@microsoft.com>2019-01-03 22:44:37 +0300
committerEric Maupin <ermaup@microsoft.com>2019-01-11 23:19:25 +0300
commit71ad75860e1c5b6c33163d390988dbfbf409b4ac (patch)
tree80f6ed1ac0a1a0face888e3481f802f4d328a312 /Xamarin.PropertyEditing.Mac/Controls/Custom
parent104acbcc9c62e1a90e9e43cb7630583cb2b49ca4 (diff)
[mac] Revamp theming
This commit: - Drops outdated CG* editors - Drops ThemeManager - Introduces IHostResourceProvider - Moves all images to new API - Starts implementing colors
Diffstat (limited to 'Xamarin.PropertyEditing.Mac/Controls/Custom')
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/Custom/BasePopOverControl.cs14
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/Custom/BasePopOverViewModelControl.cs3
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/Custom/BrushTabViewController.cs9
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/Custom/ColorComponentEditor.cs53
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/Custom/ColorComponentTabViewController.cs8
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/Custom/ColorComponentViewController.cs16
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/Custom/CommonBrushLayer.cs20
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/Custom/CommonBrushView.cs19
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/Custom/ComponentSpinEditor.cs6
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/Custom/DrawingExtensions.cs24
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/Custom/HistoryLayer.cs15
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/Custom/MaterialBrushEditorViewController.cs39
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/Custom/NumericSpinEditor.cs61
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/Custom/PropertyButton.cs40
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/Custom/RatioEditor.cs3
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/Custom/ResourceBrushPropertyViewDelegate.cs8
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/Custom/ResourceBrushViewController.cs10
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/Custom/ResourceOutlineViewDelegate.cs19
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/Custom/SolidColorBrushEditor.cs30
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/Custom/SolidColorBrushEditorViewController.cs16
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/Custom/SpinnerButton.cs55
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/Custom/UnderlinedTabViewController.cs15
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/Custom/UnderlinedTextField.cs27
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/Custom/UnfocusableButton.cs19
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/Custom/UnfocusableTextField.cs26
25 files changed, 282 insertions, 273 deletions
diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/BasePopOverControl.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/BasePopOverControl.cs
index f8f3c54..76868b6 100644
--- a/Xamarin.PropertyEditing.Mac/Controls/Custom/BasePopOverControl.cs
+++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/BasePopOverControl.cs
@@ -8,18 +8,22 @@ namespace Xamarin.PropertyEditing.Mac
{
const int DefaultIconButtonSize = 32;
- public BasePopOverControl (string title, string imageNamed) : base ()
+ public BasePopOverControl (IHostResourceProvider hostResources, string title, string imageNamed) : base ()
{
if (title == null)
throw new ArgumentNullException (nameof (title));
if (imageNamed == null)
throw new ArgumentNullException (nameof (imageNamed));
+ if (hostResources == null)
+ throw new ArgumentNullException (nameof (hostResources));
TranslatesAutoresizingMaskIntoConstraints = false;
WantsLayer = true;
+ HostResources = hostResources;
+
var iconView = new NSImageView {
- Image = PropertyEditorPanel.ThemeManager.GetImageForTheme (imageNamed),
+ Image = hostResources.GetNamedImage (imageNamed),
ImageScaling = NSImageScale.None,
TranslatesAutoresizingMaskIntoConstraints = false,
};
@@ -46,8 +50,12 @@ namespace Xamarin.PropertyEditing.Mac
NSLayoutConstraint.Create (viewTitle, NSLayoutAttribute.Width, NSLayoutRelation.Equal, 1f, 120),
NSLayoutConstraint.Create (viewTitle, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, PropertyEditorControl.DefaultControlHeight),
});
+ }
- Appearance = PropertyEditorPanel.ThemeManager.CurrentAppearance;
+ protected IHostResourceProvider HostResources
+ {
+ get;
+ private set;
}
}
}
diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/BasePopOverViewModelControl.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/BasePopOverViewModelControl.cs
index 85352f5..0f1846a 100644
--- a/Xamarin.PropertyEditing.Mac/Controls/Custom/BasePopOverViewModelControl.cs
+++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/BasePopOverViewModelControl.cs
@@ -9,7 +9,8 @@ namespace Xamarin.PropertyEditing.Mac
{
internal PropertyViewModel ViewModel { get; }
- public BasePopOverViewModelControl (PropertyViewModel viewModel, string title, string imageNamed) : base (title, imageNamed)
+ public BasePopOverViewModelControl (IHostResourceProvider hostResources, PropertyViewModel viewModel, string title, string imageNamed)
+ : base (hostResources, title, imageNamed)
{
if (viewModel == null)
throw new ArgumentNullException (nameof (viewModel));
diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/BrushTabViewController.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/BrushTabViewController.cs
index 37b8e4a..52b9c31 100644
--- a/Xamarin.PropertyEditing.Mac/Controls/Custom/BrushTabViewController.cs
+++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/BrushTabViewController.cs
@@ -13,7 +13,8 @@ namespace Xamarin.PropertyEditing.Mac
internal class BrushTabViewController
: UnderlinedTabViewController<BrushPropertyViewModel>, IEditorView
{
- public BrushTabViewController ()
+ public BrushTabViewController (IHostResourceProvider hostResources)
+ : base (hostResources)
{
PreferredContentSize = new CGSize (430, 230);
TransitionOptions = NSViewControllerTransitionOptions.None;
@@ -86,7 +87,7 @@ namespace Xamarin.PropertyEditing.Mac
switch (kvp.Value) {
case CommonBrushType.Solid:
- var solid = new SolidColorBrushEditorViewController ();
+ var solid = new SolidColorBrushEditorViewController (HostResources);
solid.ViewModel = ViewModel;
item.ViewController = solid;
item.ToolTip = Properties.Resources.SolidBrush;
@@ -94,7 +95,7 @@ namespace Xamarin.PropertyEditing.Mac
break;
case CommonBrushType.MaterialDesign:
- var material = new MaterialBrushEditorViewController ();
+ var material = new MaterialBrushEditorViewController (HostResources);
material.ViewModel = ViewModel;
item.ViewController = material;
item.ToolTip = Properties.Resources.MaterialDesignColorBrush;
@@ -102,7 +103,7 @@ namespace Xamarin.PropertyEditing.Mac
break;
case CommonBrushType.Resource:
- this.resource = new ResourceBrushViewController ();
+ this.resource = new ResourceBrushViewController (HostResources);
this.resource.ViewModel = ViewModel;
item.ViewController = this.resource;
item.ToolTip = Properties.Resources.ResourceBrush;
diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/ColorComponentEditor.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/ColorComponentEditor.cs
index 9171e2b..8e9b9cb 100644
--- a/Xamarin.PropertyEditing.Mac/Controls/Custom/ColorComponentEditor.cs
+++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/ColorComponentEditor.cs
@@ -20,16 +20,17 @@ namespace Xamarin.PropertyEditing.Mac
public bool ClickableGradients { get; set; } = true;
- public ColorComponentEditor (ChannelEditorType editorType, CGRect frame) : base (frame)
+ public ColorComponentEditor (IHostResourceProvider hostResources, ChannelEditorType editorType, CGRect frame)
+ : base (frame)
{
EditorType = EditorType;
- Initialize ();
+ Initialize (hostResources);
}
- public ColorComponentEditor (ChannelEditorType editorType) : base ()
+ public ColorComponentEditor (IHostResourceProvider hostResources, ChannelEditorType editorType)
{
EditorType = editorType;
- Initialize ();
+ Initialize (hostResources);
}
private ChannelGroup [] Editors { get; set; }
@@ -43,7 +44,7 @@ namespace Xamarin.PropertyEditing.Mac
public CAGradientLayer Gradient { get; set; }
}
- private ChannelGroup CreateEditor (ChannelEditor editor)
+ private ChannelGroup CreateEditor (IHostResourceProvider hostResources, ChannelEditor editor)
{
var ce = new ChannelGroup {
Label = new UnfocusableTextField {
@@ -51,7 +52,7 @@ namespace Xamarin.PropertyEditing.Mac
Alignment = NSTextAlignment.Right,
ToolTip = editor.ToolTip
},
- Editor = new ComponentSpinEditor (editor) {
+ Editor = new ComponentSpinEditor (hostResources, editor) {
BackgroundColor = NSColor.Clear,
TranslatesAutoresizingMaskIntoConstraints = true
},
@@ -71,46 +72,46 @@ namespace Xamarin.PropertyEditing.Mac
return ce;
}
- private ChannelGroup [] CreateEditors (ChannelEditorType type)
+ private ChannelGroup [] CreateEditors (IHostResourceProvider hostResources, ChannelEditorType type)
{
switch (type) {
case ChannelEditorType.HSB:
return new [] {
- CreateEditor (new HsbHueChannelEditor ()),
- CreateEditor (new HsbSaturationChannelEditor ()),
- CreateEditor (new HsbBrightnessChannelEditor ()),
- CreateEditor (new HsbAlphaChannelEditor ())
+ CreateEditor (hostResources, new HsbHueChannelEditor ()),
+ CreateEditor (hostResources, new HsbSaturationChannelEditor ()),
+ CreateEditor (hostResources, new HsbBrightnessChannelEditor ()),
+ CreateEditor (hostResources, new HsbAlphaChannelEditor ())
};
case ChannelEditorType.HLS:
return new [] {
- CreateEditor (new HlsHueChannelEditor ()),
- CreateEditor (new HlsLightnessChannelEditor ()),
- CreateEditor (new HlsSaturationChannelEditor ()),
- CreateEditor (new HlsAlphaChannelEditor ())
+ CreateEditor (hostResources, new HlsHueChannelEditor ()),
+ CreateEditor (hostResources, new HlsLightnessChannelEditor ()),
+ CreateEditor (hostResources, new HlsSaturationChannelEditor ()),
+ CreateEditor (hostResources, new HlsAlphaChannelEditor ())
};
case ChannelEditorType.RGB:
return new [] {
- CreateEditor (new RedChannelEditor ()),
- CreateEditor (new GreenChannelEditor ()),
- CreateEditor (new BlueChannelEditor ()),
- CreateEditor (new AlphaChannelEditor ())
+ CreateEditor (hostResources, new RedChannelEditor ()),
+ CreateEditor (hostResources, new GreenChannelEditor ()),
+ CreateEditor (hostResources, new BlueChannelEditor ()),
+ CreateEditor (hostResources, new AlphaChannelEditor ())
};
default:
case ChannelEditorType.CMYK:
return new [] {
- CreateEditor (new CyanChannelEditor ()),
- CreateEditor (new MagentaChannelEditor ()),
- CreateEditor (new YellowChannelEditor ()),
- CreateEditor (new BlackChannelEditor ()),
- CreateEditor (new AlphaChannelEditor ())
+ CreateEditor (hostResources, new CyanChannelEditor ()),
+ CreateEditor (hostResources, new MagentaChannelEditor ()),
+ CreateEditor (hostResources, new YellowChannelEditor ()),
+ CreateEditor (hostResources, new BlackChannelEditor ()),
+ CreateEditor (hostResources, new AlphaChannelEditor ())
};
}
}
- private void Initialize ()
+ private void Initialize (IHostResourceProvider hostResources)
{
WantsLayer = true;
- Editors = CreateEditors (EditorType);
+ Editors = CreateEditors (hostResources, EditorType);
this.hexLabel = new UnfocusableTextField {
StringValue = "#:",
diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/ColorComponentTabViewController.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/ColorComponentTabViewController.cs
index 55c592c..7cb3b09 100644
--- a/Xamarin.PropertyEditing.Mac/Controls/Custom/ColorComponentTabViewController.cs
+++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/ColorComponentTabViewController.cs
@@ -6,16 +6,18 @@ using Xamarin.PropertyEditing.ViewModels;
namespace Xamarin.PropertyEditing.Mac
{
- internal class ColorComponentTabViewController : UnderlinedTabViewController<SolidBrushViewModel>
+ internal class ColorComponentTabViewController
+ : UnderlinedTabViewController<SolidBrushViewModel>
{
- public ColorComponentTabViewController ()
+ public ColorComponentTabViewController (IHostResourceProvider hostResources)
+ : base (hostResources)
{
foreach (var value in Enum.GetValues (typeof (ChannelEditorType))) {
var editorType = (ChannelEditorType)value;
AddTabViewItem (new NSTabViewItem {
Label = value.ToString (),
ToolTip = GetToolTip (editorType),
- ViewController = new ColorComponentViewController (editorType)
+ ViewController = new ColorComponentViewController (hostResources, editorType)
});
}
}
diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/ColorComponentViewController.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/ColorComponentViewController.cs
index 1b3e93b..67c5b86 100644
--- a/Xamarin.PropertyEditing.Mac/Controls/Custom/ColorComponentViewController.cs
+++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/ColorComponentViewController.cs
@@ -6,12 +6,15 @@ using Xamarin.PropertyEditing.ViewModels;
namespace Xamarin.PropertyEditing.Mac
{
- internal class ColorComponentViewController : NotifyingViewController<SolidBrushViewModel>
+ internal class ColorComponentViewController
+ : NotifyingViewController<SolidBrushViewModel>
{
- private ColorComponentEditor editor;
-
- public ColorComponentViewController (ChannelEditorType type) : base ()
+ public ColorComponentViewController (IHostResourceProvider hostResources, ChannelEditorType type)
{
+ if (hostResources == null)
+ throw new ArgumentNullException (nameof (hostResources));
+
+ this.hostResources = hostResources;
PreferredContentSize = new CGSize (100, 400);
EditorType = type;
}
@@ -38,7 +41,10 @@ namespace Xamarin.PropertyEditing.Mac
public override void LoadView ()
{
- View = this.editor = new ColorComponentEditor (this.EditorType);
+ View = this.editor = new ColorComponentEditor (this.hostResources, EditorType);
}
+
+ private readonly IHostResourceProvider hostResources;
+ private ColorComponentEditor editor;
}
}
diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/CommonBrushLayer.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/CommonBrushLayer.cs
index c12362c..12f16b1 100644
--- a/Xamarin.PropertyEditing.Mac/Controls/Custom/CommonBrushLayer.cs
+++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/CommonBrushLayer.cs
@@ -6,13 +6,19 @@ using Xamarin.PropertyEditing.Drawing;
namespace Xamarin.PropertyEditing.Mac
{
- internal class CommonBrushLayer : CALayer
+ internal class CommonBrushLayer
+ : CALayer
{
- public CommonBrushLayer ()
+ public CommonBrushLayer (IHostResourceProvider hostResources)
{
- this.CornerRadius = 3;
- this.BorderColor = new CGColor (.5f, .5f, .5f, .5f);
- this.BorderWidth = 1;
+ if (hostResources == null)
+ throw new ArgumentNullException (nameof (hostResources));
+
+ this.hostResources = hostResources;
+
+ CornerRadius = 3;
+ BorderColor = new CGColor (.5f, .5f, .5f, .5f);
+ BorderWidth = 1;
MasksToBounds = true;
}
@@ -63,7 +69,7 @@ namespace Xamarin.PropertyEditing.Mac
{
base.LayoutSublayers ();
BrushLayer.Frame = Bounds;
- Contents = DrawingExtensions.GenerateCheckerboard (Bounds);
+ Contents = DrawingExtensions.GenerateCheckerboard (Bounds, this.hostResources.GetNamedColor (NamedResources.Checkerboard0Color), this.hostResources.GetNamedColor (NamedResources.Checkerboard0Color));
}
public NSImage RenderPreview ()
@@ -84,5 +90,7 @@ namespace Xamarin.PropertyEditing.Mac
}
}
}
+
+ private readonly IHostResourceProvider hostResources;
}
}
diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/CommonBrushView.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/CommonBrushView.cs
index d637b6d..0201795 100644
--- a/Xamarin.PropertyEditing.Mac/Controls/Custom/CommonBrushView.cs
+++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/CommonBrushView.cs
@@ -15,18 +15,15 @@ namespace Xamarin.PropertyEditing.Mac
NSView IValueView.NativeView => this;
- public CommonBrushView ()
+ public CommonBrushView (IHostResourceProvider hostResources)
{
- Initialize ();
+ Initialize (hostResources);
}
- public CommonBrushView (CGRect frame) : base (frame)
- {
- Initialize ();
- }
-
- public CommonBrushView (IntPtr handle) : base (handle)
+ public CommonBrushView (IHostResourceProvider hostResources, CGRect frame)
+ : base (frame)
{
+ Initialize (hostResources);
}
void IValueView.SetValue (object value)
@@ -38,10 +35,10 @@ namespace Xamarin.PropertyEditing.Mac
Brush = brush;
}
- private void Initialize () {
+ private void Initialize (IHostResourceProvider hostResources)
+ {
WantsLayer = true;
- Layer = new CommonBrushLayer
- {
+ Layer = new CommonBrushLayer (hostResources) {
Brush = Brush
};
}
diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/ComponentSpinEditor.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/ComponentSpinEditor.cs
index da63dc8..bc305e7 100644
--- a/Xamarin.PropertyEditing.Mac/Controls/Custom/ComponentSpinEditor.cs
+++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/ComponentSpinEditor.cs
@@ -2,9 +2,11 @@
namespace Xamarin.PropertyEditing.Mac
{
- internal class ComponentSpinEditor : NumericSpinEditor
+ internal class ComponentSpinEditor
+ : NumericSpinEditor
{
- public ComponentSpinEditor (ChannelEditor component)
+ public ComponentSpinEditor (IHostResourceProvider hostResources, ChannelEditor component)
+ : base (hostResources)
{
ComponentEditor = component;
MinimumValue = component.MinimumValue;
diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/DrawingExtensions.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/DrawingExtensions.cs
index 6bb5c15..3b983bc 100644
--- a/Xamarin.PropertyEditing.Mac/Controls/Custom/DrawingExtensions.cs
+++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/DrawingExtensions.cs
@@ -8,31 +8,15 @@ namespace Xamarin.PropertyEditing.Mac
{
static class DrawingExtensions
{
- public static NSImage CreateSwatch (this CommonColor color, CGSize size)
- {
- bool dark = PropertyEditorPanel.ThemeManager.Theme == Themes.PropertyEditorTheme.Dark;
- byte c0c = (byte)(dark ? 0x26: 0xff);
- byte c1c = (byte)(dark ? 0x00 : 0xd9);
-
- var c0 = CIColor.FromCGColor (color.Blend (new CommonColor (c0c, c0c, c0c)).ToCGColor ());
- var c1 = CIColor.FromCGColor (color.Blend (new CommonColor (c1c, c1c, c1c)).ToCGColor ());
-
- return CreateSwatch (color, size, c0, c1);
- }
+ public static NSImage CreateSwatch (this CommonColor color, CGSize size, NSColor c0, NSColor c1)
+ => CreateSwatch (color, size, CIColor.FromCGColor (c0.CGColor), CIColor.FromCGColor (c1.CGColor));
public static NSImage CreateSwatch (this CommonColor color, CGSize size, CIColor c0, CIColor c1)
=> new NSImage (GenerateCheckerboard (new CGRect (0, 0, size.Width, size.Height), c0, c1), size);
- public static CGImage GenerateCheckerboard (CGRect frame)
+ public static CGImage GenerateCheckerboard (CGRect frame, NSColor c0, NSColor c1)
{
- bool dark = PropertyEditorPanel.ThemeManager.Theme == Themes.PropertyEditorTheme.Dark;
- float c1 = dark ? 0x26 / 255f : 1;
- float c2 = dark ? 0 : 0xd9 / 255f;
-
- return DrawingExtensions.GenerateCheckerboard (
- frame,
- CoreImage.CIColor.FromRgb (c1, c1, c1),
- CoreImage.CIColor.FromRgb (c2, c2, c2));
+ return GenerateCheckerboard (frame, CIColor.FromCGColor (c0.CGColor), CIColor.FromCGColor (c1.CGColor));
}
public static CGImage GenerateCheckerboard (CGRect frame, CIColor c0, CIColor c1)
diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/HistoryLayer.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/HistoryLayer.cs
index 84fcbcf..221f076 100644
--- a/Xamarin.PropertyEditing.Mac/Controls/Custom/HistoryLayer.cs
+++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/HistoryLayer.cs
@@ -1,4 +1,5 @@
using System;
+using AppKit;
using CoreAnimation;
using CoreGraphics;
@@ -9,8 +10,12 @@ namespace Xamarin.PropertyEditing.Mac
private const float Margin = 3;
private const float BorderRadius = 3;
- public HistoryLayer ()
+ public HistoryLayer (IHostResourceProvider hostResources)
{
+ if (hostResources == null)
+ throw new ArgumentNullException (nameof (hostResources));
+
+ this.hostResources = hostResources;
clip.AddSublayer (previous);
clip.AddSublayer (current);
AddSublayer (clip);
@@ -22,6 +27,7 @@ namespace Xamarin.PropertyEditing.Mac
{
}
+ private readonly IHostResourceProvider hostResources;
private readonly CALayer previous = new UnanimatedLayer ();
private readonly CALayer current = new UnanimatedLayer ();
private readonly CALayer last = new UnanimatedLayer ();
@@ -56,8 +62,11 @@ namespace Xamarin.PropertyEditing.Mac
Bounds.Width - Bounds.Height + Margin,
Bounds.Height).Inset (Margin, Margin);
- this.clip.Contents = DrawingExtensions.GenerateCheckerboard (this.clip.Bounds);
- this.lastClip.Contents = DrawingExtensions.GenerateCheckerboard (this.last.Bounds);
+ NSColor cc0 = this.hostResources.GetNamedColor (NamedResources.Checkerboard0Color);
+ NSColor cc1 = this.hostResources.GetNamedColor (NamedResources.Checkerboard1Color);
+
+ this.clip.Contents = DrawingExtensions.GenerateCheckerboard (this.clip.Bounds, cc0, cc1);
+ this.lastClip.Contents = DrawingExtensions.GenerateCheckerboard (this.last.Bounds, cc0, cc1);
this.last.Frame = this.lastClip.Bounds;
var width = clip.Frame.Width / 2;
diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/MaterialBrushEditorViewController.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/MaterialBrushEditorViewController.cs
index 4cf164f..5920c75 100644
--- a/Xamarin.PropertyEditing.Mac/Controls/Custom/MaterialBrushEditorViewController.cs
+++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/MaterialBrushEditorViewController.cs
@@ -7,17 +7,18 @@ using Xamarin.PropertyEditing.ViewModels;
namespace Xamarin.PropertyEditing.Mac
{
- class MaterialBrushEditorViewController : NotifyingViewController<BrushPropertyViewModel>
+ internal class MaterialBrushEditorViewController
+ : NotifyingViewController<BrushPropertyViewModel>
{
- public MaterialBrushEditorViewController ()
+ public MaterialBrushEditorViewController (IHostResourceProvider hostResources)
{
+ if (hostResources == null)
+ throw new ArgumentNullException (nameof (hostResources));
+
+ this.hostResources = hostResources;
PreferredContentSize = new CGSize (430, 230);
}
- private MaterialView materialEditor;
- private AlphaChannelEditor alphaChannelEditor;
- private ComponentSpinEditor alphaSpinEditor;
-
public override void OnPropertyChanged (object sender, PropertyChangedEventArgs e)
{
switch (e.PropertyName) {
@@ -37,15 +38,6 @@ namespace Xamarin.PropertyEditing.Mac
this.materialEditor.ViewModel = ViewModel?.MaterialDesign;
}
- void UpdateComponent (object sender, EventArgs args)
- {
- if (ViewModel == null)
- return;
-
- var editor = sender as NumericSpinEditor;
- ViewModel.MaterialDesign.Alpha = (byte)editor.Value;
- }
-
public override void LoadView ()
{
var stack = new NSStackView () {
@@ -57,7 +49,7 @@ namespace Xamarin.PropertyEditing.Mac
};
this.alphaChannelEditor = new AlphaChannelEditor ();
- this.alphaSpinEditor = new ComponentSpinEditor (this.alphaChannelEditor) {
+ this.alphaSpinEditor = new ComponentSpinEditor (this.hostResources, this.alphaChannelEditor) {
BackgroundColor = NSColor.Clear
};
this.alphaSpinEditor.ValueChanged += UpdateComponent;
@@ -80,5 +72,20 @@ namespace Xamarin.PropertyEditing.Mac
View = stack;
}
+
+ private readonly IHostResourceProvider hostResources;
+
+ private MaterialView materialEditor;
+ private AlphaChannelEditor alphaChannelEditor;
+ private ComponentSpinEditor alphaSpinEditor;
+
+ private void UpdateComponent (object sender, EventArgs args)
+ {
+ if (ViewModel == null)
+ return;
+
+ var editor = sender as NumericSpinEditor;
+ ViewModel.MaterialDesign.Alpha = (byte)editor.Value;
+ }
}
}
diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/NumericSpinEditor.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/NumericSpinEditor.cs
index a3c68fd..b5034da 100644
--- a/Xamarin.PropertyEditing.Mac/Controls/Custom/NumericSpinEditor.cs
+++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/NumericSpinEditor.cs
@@ -1,17 +1,22 @@
using System;
+
using AppKit;
using CoreGraphics;
using Foundation;
-using Xamarin.PropertyEditing.Drawing;
-using Xamarin.PropertyEditing.Themes;
namespace Xamarin.PropertyEditing.Mac
{
- internal class NumericSpinEditor<T> : NumericSpinEditor
+ internal class NumericSpinEditor<T>
+ : NumericSpinEditor
{
+ public NumericSpinEditor (IHostResourceProvider hostResources)
+ : base (hostResources)
+ {
+ }
}
- internal class NumericSpinEditor : NSView, INSAccessibilityGroup
+ internal class NumericSpinEditor
+ : NSView, INSAccessibilityGroup
{
const int stepperSpace = 2;
const int stepperWidth = 11;
@@ -24,13 +29,13 @@ namespace Xamarin.PropertyEditing.Mac
get { return this.numericEditor; }
}
- private UpSpinnerButton incrementButton;
- public UpSpinnerButton IncrementButton {
+ private SpinnerButton incrementButton;
+ public SpinnerButton IncrementButton {
get { return this.incrementButton; }
}
- private DownSpinnerButton decrementButton;
- public DownSpinnerButton DecrementButton {
+ private SpinnerButton decrementButton;
+ public SpinnerButton DecrementButton {
get { return this.decrementButton; }
}
@@ -166,16 +171,19 @@ namespace Xamarin.PropertyEditing.Mac
{
}
- public NumericSpinEditor ()
+ public NumericSpinEditor (IHostResourceProvider hostResources)
{
+ if (hostResources == null)
+ throw new ArgumentNullException (nameof (hostResources));
+
+ this.hostResources = hostResources;
TranslatesAutoresizingMaskIntoConstraints = false;
- var controlSize = NSControlSize.Small;
- incrementButton = new UpSpinnerButton {
+ this.incrementButton = new SpinnerButton (this.hostResources, isUp: true) {
TranslatesAutoresizingMaskIntoConstraints = false
};
- decrementButton = new DownSpinnerButton {
+ this.decrementButton = new SpinnerButton (this.hostResources, isUp: false) {
TranslatesAutoresizingMaskIntoConstraints = false
};
@@ -188,13 +196,15 @@ namespace Xamarin.PropertyEditing.Mac
NumberStyle = NSNumberFormatterStyle.Decimal,
UsesGroupingSeparator = false
};
- if (DisplayFormat != null) this.formatter.PositiveFormat = DisplayFormat;
+
+ if (DisplayFormat != null)
+ this.formatter.PositiveFormat = DisplayFormat;
this.numericEditor = new NumericTextField {
Alignment = NSTextAlignment.Right,
TranslatesAutoresizingMaskIntoConstraints = false,
Font = NSFont.FromFontName (PropertyEditorControl.DefaultFontName, PropertyEditorControl.DefaultFontSize),
- ControlSize = controlSize,
+ ControlSize = NSControlSize.Small,
Formatter = this.formatter
};
@@ -224,27 +234,6 @@ namespace Xamarin.PropertyEditing.Mac
NSLayoutConstraint.Create (this.decrementButton, NSLayoutAttribute.Width, NSLayoutRelation.Equal, 1f, stepperWidth),
NSLayoutConstraint.Create (this.decrementButton, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, stepperBotHeight),
});
-
- PropertyEditorPanel.ThemeManager.ThemeChanged += ThemeManager_ThemeChanged;
-
- UpdateTheme ();
- }
-
- protected override void Dispose (bool disposing)
- {
- if (disposing) {
- PropertyEditorPanel.ThemeManager.ThemeChanged -= ThemeManager_ThemeChanged;
- }
- }
-
- void ThemeManager_ThemeChanged (object sender, EventArgs e)
- {
- UpdateTheme ();
- }
-
- protected void UpdateTheme ()
- {
- Appearance = PropertyEditorPanel.ThemeManager.CurrentAppearance;
}
virtual protected void OnEditingEnded (object sender, EventArgs e)
@@ -306,5 +295,7 @@ namespace Xamarin.PropertyEditing.Mac
{
return (double)Decimal.Round ((decimal)(value < MinimumValue ? MinimumValue : value > MaximumValue ? MaximumValue : value), Digits);
}
+
+ private readonly IHostResourceProvider hostResources;
}
}
diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/PropertyButton.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/PropertyButton.cs
index a990d02..ef7e464 100644
--- a/Xamarin.PropertyEditing.Mac/Controls/Custom/PropertyButton.cs
+++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/PropertyButton.cs
@@ -1,15 +1,13 @@
using System;
-using System.Collections;
-using System.ComponentModel;
using AppKit;
using CoreGraphics;
using Xamarin.PropertyEditing.Mac.Resources;
-using Xamarin.PropertyEditing.Themes;
using Xamarin.PropertyEditing.ViewModels;
namespace Xamarin.PropertyEditing.Mac
{
- public class PropertyButton : UnfocusableButton
+ public class PropertyButton
+ : UnfocusableButton
{
public const int DefaultSize = 20;
@@ -31,12 +29,17 @@ namespace Xamarin.PropertyEditing.Mac
}
}
- public PropertyButton ()
+ public PropertyButton (IHostResourceProvider hostResources)
{
+ if (hostResources == null)
+ throw new ArgumentNullException (nameof (hostResources));
+
+ this.hostResources = hostResources;
+
AccessibilityTitle = LocalizationResources.AccessibilityPropertiesButton;
AccessibilityHelp = LocalizationResources.AccessibilityPropertiesButtonDescription;
Enabled = true;
- Image = PropertyEditorPanel.ThemeManager.GetImageForTheme ("property-button-default-mac-10");
+ Image = this.hostResources.GetNamedImage ("property-button-default-mac-10");
ImageScaling = NSImageScale.None;
ToolTip = Properties.Resources.Default;
@@ -107,40 +110,41 @@ namespace Xamarin.PropertyEditing.Mac
NSMenu.PopUpContextMenu (popUpContextMenu, popupMenuEvent, this);
}
- protected override void UpdateTheme ()
+ public override void ViewDidChangeEffectiveAppearance ()
{
- base.UpdateTheme ();
-
+ base.ViewDidChangeEffectiveAppearance ();
ToggleFocusImage ();
}
+ private readonly IHostResourceProvider hostResources;
+
private void ToggleFocusImage (bool focused = false)
{
if (viewModel != null) {
switch (viewModel.ValueSource) {
case ValueSource.Binding:
- Image = focused ? PropertyEditorPanel.ThemeManager.GetImageForTheme ("property-button-bound-mac-active-10") : PropertyEditorPanel.ThemeManager.GetImageForTheme ("property-button-bound-mac-10");
+ Image = focused ? this.hostResources.GetNamedImage ("property-button-bound-mac-active-10") : this.hostResources.GetNamedImage ("property-button-bound-mac-10");
break;
case ValueSource.Default:
- Image = focused ? PropertyEditorPanel.ThemeManager.GetImageForTheme ("property-button-default-mac-active-10") : PropertyEditorPanel.ThemeManager.GetImageForTheme ("property-button-default-mac-10");
+ Image = focused ? this.hostResources.GetNamedImage ("property-button-default-mac-active-10") : this.hostResources.GetNamedImage ("property-button-default-mac-10");
break;
case ValueSource.Local:
- Image = focused ? PropertyEditorPanel.ThemeManager.GetImageForTheme ("property-button-local-mac-active-10") : PropertyEditorPanel.ThemeManager.GetImageForTheme ("property-button-local-mac-10");
+ Image = focused ? this.hostResources.GetNamedImage ("property-button-local-mac-active-10") : this.hostResources.GetNamedImage ("property-button-local-mac-10");
break;
case ValueSource.Inherited:
- Image = focused ? PropertyEditorPanel.ThemeManager.GetImageForTheme ("property-button-inherited-mac-active-10") : PropertyEditorPanel.ThemeManager.GetImageForTheme ("property-button-inherited-mac-10");
+ Image = focused ? this.hostResources.GetNamedImage ("property-button-inherited-mac-active-10") : this.hostResources.GetNamedImage ("property-button-inherited-mac-10");
break;
case ValueSource.Resource:
- Image = focused ? PropertyEditorPanel.ThemeManager.GetImageForTheme ("property-button-inherited-mac-active-10") : PropertyEditorPanel.ThemeManager.GetImageForTheme ("property-button-inherited-mac-10");
+ Image = focused ? this.hostResources.GetNamedImage ("property-button-inherited-mac-active-10") : this.hostResources.GetNamedImage ("property-button-inherited-mac-10");
break;
case ValueSource.Unset:
- Image = focused ? PropertyEditorPanel.ThemeManager.GetImageForTheme ("property-button-default-mac-active-10") : PropertyEditorPanel.ThemeManager.GetImageForTheme ("property-button-default-mac-10");
+ Image = focused ? this.hostResources.GetNamedImage ("property-button-default-mac-active-10") : this.hostResources.GetNamedImage ("property-button-default-mac-10");
break;
default:
@@ -183,8 +187,6 @@ namespace Xamarin.PropertyEditing.Mac
ToolTip = string.Empty;
break;
}
-
- UpdateTheme ();
}
private void OnPropertyChanged (object sender, System.ComponentModel.PropertyChangedEventArgs e)
@@ -196,7 +198,7 @@ namespace Xamarin.PropertyEditing.Mac
private void OnCustomExpression (object sender, EventArgs e)
{
- var customExpressionView = new CustomExpressionView (viewModel);
+ var customExpressionView = new CustomExpressionView (this.hostResources, viewModel);
var customExpressionPopOver = new AutoClosePopOver {
ContentViewController = new NSViewController (null, null) { View = customExpressionView },
@@ -207,7 +209,7 @@ namespace Xamarin.PropertyEditing.Mac
private void OnResourceRequested (object sender, EventArgs e)
{
- var requestResourceView = new RequestResourceView (this.viewModel);
+ var requestResourceView = new RequestResourceView (this.hostResources, this.viewModel);
var resourceSelectorPopOver = new AutoClosePopOver {
ContentViewController = new NSViewController (null, null) { View = requestResourceView },
diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/RatioEditor.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/RatioEditor.cs
index 8ba4df5..212c159 100644
--- a/Xamarin.PropertyEditing.Mac/Controls/Custom/RatioEditor.cs
+++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/RatioEditor.cs
@@ -10,7 +10,8 @@ namespace Xamarin.PropertyEditing.Mac
{
private bool fullSelection;
- public RatioEditor ()
+ public RatioEditor (IHostResourceProvider hostResources)
+ : base (hostResources)
{
AllowNegativeValues = false;
AllowRatios = true;
diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/ResourceBrushPropertyViewDelegate.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/ResourceBrushPropertyViewDelegate.cs
index 84f35dd..25dcee1 100644
--- a/Xamarin.PropertyEditing.Mac/Controls/Custom/ResourceBrushPropertyViewDelegate.cs
+++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/ResourceBrushPropertyViewDelegate.cs
@@ -4,8 +4,14 @@ using Xamarin.PropertyEditing.ViewModels;
namespace Xamarin.PropertyEditing.Mac
{
- internal class ResourceBrushPropertyViewDelegate : ResourceOutlineViewDelegate
+ internal class ResourceBrushPropertyViewDelegate
+ : ResourceOutlineViewDelegate
{
+ public ResourceBrushPropertyViewDelegate (IHostResourceProvider hostResources)
+ : base (hostResources)
+ {
+ }
+
public BrushPropertyViewModel ViewModel
{
get;
diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/ResourceBrushViewController.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/ResourceBrushViewController.cs
index a212024..82c0256 100644
--- a/Xamarin.PropertyEditing.Mac/Controls/Custom/ResourceBrushViewController.cs
+++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/ResourceBrushViewController.cs
@@ -1,11 +1,7 @@
using System;
-using System.Collections.Generic;
using System.ComponentModel;
using AppKit;
using CoreGraphics;
-using Foundation;
-using Xamarin.PropertyEditing.Drawing;
-using Xamarin.PropertyEditing.Mac.Resources;
using Xamarin.PropertyEditing.ViewModels;
namespace Xamarin.PropertyEditing.Mac
@@ -13,12 +9,12 @@ namespace Xamarin.PropertyEditing.Mac
internal class ResourceBrushViewController : NotifyingViewController<BrushPropertyViewModel>
{
private ResourceOutlineView resourceSelector;
- private ResourceBrushPropertyViewDelegate viewDelegate;
+ private readonly ResourceBrushPropertyViewDelegate viewDelegate;
- public ResourceBrushViewController ()
+ public ResourceBrushViewController (IHostResourceProvider hostResources)
{
PreferredContentSize = new CGSize (430, 230);
- viewDelegate = new ResourceBrushPropertyViewDelegate ();
+ this.viewDelegate = new ResourceBrushPropertyViewDelegate (hostResources);
}
private Resource resource;
diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/ResourceOutlineViewDelegate.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/ResourceOutlineViewDelegate.cs
index 4df996b..2777c78 100644
--- a/Xamarin.PropertyEditing.Mac/Controls/Custom/ResourceOutlineViewDelegate.cs
+++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/ResourceOutlineViewDelegate.cs
@@ -7,10 +7,16 @@ using Xamarin.PropertyEditing.ViewModels;
namespace Xamarin.PropertyEditing.Mac
{
- internal class ResourceOutlineViewDelegate : NSOutlineViewDelegate
+ internal class ResourceOutlineViewDelegate
+ : NSOutlineViewDelegate
{
- private const string labelIdentifier = "label";
- private const string resourceIdentifier = "resource";
+ public ResourceOutlineViewDelegate (IHostResourceProvider hostResource)
+ {
+ if (hostResource == null)
+ throw new ArgumentNullException (nameof (hostResource));
+
+ this.hostResources = hostResource;
+ }
public override NSView GetView (NSOutlineView outlineView, NSTableColumn tableColumn, NSObject item)
{
@@ -20,7 +26,7 @@ namespace Xamarin.PropertyEditing.Mac
case ResourceOutlineView.ResourcePreviewColId:
var cbv = (CommonBrushView)outlineView.MakeView (resourceIdentifier, this);
if (cbv == null) {
- cbv = new CommonBrushView {
+ cbv = new CommonBrushView (this.hostResources) {
Identifier = resourceIdentifier,
Frame = new CGRect (0, 0, 30, 10),
};
@@ -50,5 +56,10 @@ namespace Xamarin.PropertyEditing.Mac
{
return PropertyEditorControl.DefaultControlHeight;
}
+
+ private const string labelIdentifier = "label";
+ private const string resourceIdentifier = "resource";
+
+ private readonly IHostResourceProvider hostResources;
}
}
diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/SolidColorBrushEditor.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/SolidColorBrushEditor.cs
index 7813f5f..ddec36b 100644
--- a/Xamarin.PropertyEditing.Mac/Controls/Custom/SolidColorBrushEditor.cs
+++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/SolidColorBrushEditor.cs
@@ -37,24 +37,29 @@ namespace Xamarin.PropertyEditing.Mac
}
}
- internal class SolidColorBrushEditor : ColorEditorView
+ internal class SolidColorBrushEditor
+ : ColorEditorView
{
- public SolidColorBrushEditor (IntPtr handle) : base (handle)
- {
- }
- public SolidColorBrushEditor (CGRect frame) : base (frame)
+ public SolidColorBrushEditor (IHostResourceProvider hostResources, CGRect frame)
+ : base (frame)
{
- Initialize ();
+ Initialize (hostResources);
}
- public SolidColorBrushEditor () : base ()
+ public SolidColorBrushEditor (IHostResourceProvider hostResources)
{
- Initialize ();
+ Initialize (hostResources);
}
- private void Initialize ()
+ private void Initialize (IHostResourceProvider hostResources)
{
+ this.historyLayer = new HistoryLayer (hostResources);
+
+ this.componentTabs = new ColorComponentTabViewController (hostResources) {
+ EditorType = ChannelEditorType.RGB
+ };
+
Layer = new CALayer ();
Layer.AddSublayer (background);
Layer.AddSublayer (shadeLayer);
@@ -65,15 +70,12 @@ namespace Xamarin.PropertyEditing.Mac
AddSubview (componentTabs.View);
}
- private readonly ColorComponentTabViewController componentTabs = new ColorComponentTabViewController () {
- EditorType = ChannelEditorType.RGB
- };
-
public override bool AcceptsFirstResponder () => true;
private readonly ShadeLayer shadeLayer = new ShadeLayer ();
private readonly HueLayer hueLayer = new HueLayer ();
- private readonly HistoryLayer historyLayer = new HistoryLayer ();
+ private HistoryLayer historyLayer;
+ private ColorComponentTabViewController componentTabs;
private readonly CALayer background = new CALayer {
CornerRadius = 3,
diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/SolidColorBrushEditorViewController.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/SolidColorBrushEditorViewController.cs
index a024dcc..dee1962 100644
--- a/Xamarin.PropertyEditing.Mac/Controls/Custom/SolidColorBrushEditorViewController.cs
+++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/SolidColorBrushEditorViewController.cs
@@ -5,12 +5,15 @@ using Xamarin.PropertyEditing.ViewModels;
namespace Xamarin.PropertyEditing.Mac
{
- class SolidColorBrushEditorViewController : NotifyingViewController<BrushPropertyViewModel>
+ internal class SolidColorBrushEditorViewController
+ : NotifyingViewController<BrushPropertyViewModel>
{
- private SolidColorBrushEditor brushEditor;
-
- public SolidColorBrushEditorViewController ()
+ public SolidColorBrushEditorViewController (IHostResourceProvider hostResources)
{
+ if (hostResources == null)
+ throw new ArgumentNullException (nameof (hostResources));
+
+ this.hostResources = hostResources;
PreferredContentSize = new CGSize (430, 230);
}
@@ -44,9 +47,12 @@ namespace Xamarin.PropertyEditing.Mac
public override void LoadView ()
{
- View = this.brushEditor = new SolidColorBrushEditor {
+ View = this.brushEditor = new SolidColorBrushEditor (this.hostResources) {
ViewModel = ViewModel?.Solid
};
}
+
+ private readonly IHostResourceProvider hostResources;
+ private SolidColorBrushEditor brushEditor;
}
}
diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/SpinnerButton.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/SpinnerButton.cs
index 0ba72dc..027296c 100644
--- a/Xamarin.PropertyEditing.Mac/Controls/Custom/SpinnerButton.cs
+++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/SpinnerButton.cs
@@ -1,49 +1,52 @@
using System;
using AppKit;
using ObjCRuntime;
-using Xamarin.PropertyEditing.Themes;
namespace Xamarin.PropertyEditing.Mac
{
- public class UpSpinnerButton : UnfocusableButton
+ internal class SpinnerButton
+ : UnfocusableButton
{
- public UpSpinnerButton ()
+ public SpinnerButton (IHostResourceProvider hostResource, bool isUp)
{
- OnMouseEntered += (sender, e) => {
- Image = PropertyEditorPanel.ThemeManager.GetImageForTheme ("stepper-up-focus-blue");
- };
+ if (hostResource == null)
+ throw new ArgumentNullException (nameof (hostResource));
- OnMouseExited += (sender, e) => {
- Image = PropertyEditorPanel.ThemeManager.GetImageForTheme ("stepper-up");
- };
+ this.hostResources = hostResource;
+ this.imageBase += (isUp) ? "up" : "down";
}
- protected override void UpdateTheme ()
+ public override void MouseExited (NSEvent theEvent)
{
- base.UpdateTheme ();
+ this.isMouseOver = false;
+ UpdateImage ();
+ }
- Image = PropertyEditorPanel.ThemeManager.GetImageForTheme ("stepper-up");
+ public override void MouseEntered (NSEvent theEvent)
+ {
+ this.isMouseOver = true;
+ UpdateImage ();
}
- }
- public class DownSpinnerButton : UnfocusableButton
- {
- public DownSpinnerButton ()
+ public override void ViewDidChangeEffectiveAppearance ()
{
- OnMouseEntered += (sender, e) => {
- Image = PropertyEditorPanel.ThemeManager.GetImageForTheme ("stepper-down-focus-blue");
- };
+ base.ViewDidChangeEffectiveAppearance ();
+ this.image = this.hostResources.GetNamedImage (this.imageBase);
+ this.mouseOverImage = this.hostResources.GetNamedImage (this.imageBase + "-focus-blue");
- OnMouseExited += (sender, e) => {
- Image = PropertyEditorPanel.ThemeManager.GetImageForTheme ("stepper-down");
- };
+ UpdateImage ();
}
- protected override void UpdateTheme ()
- {
- base.UpdateTheme ();
+ private readonly IHostResourceProvider hostResources;
+ private bool isMouseOver;
+ private string imageBase = "stepper-";
+
+ private NSImage image;
+ private NSImage mouseOverImage;
- Image = PropertyEditorPanel.ThemeManager.GetImageForTheme ("stepper-down");
+ private void UpdateImage ()
+ {
+ Image = (this.isMouseOver) ? this.mouseOverImage : Image;
}
}
}
diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/UnderlinedTabViewController.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/UnderlinedTabViewController.cs
index 4cff17e..0a32a71 100644
--- a/Xamarin.PropertyEditing.Mac/Controls/Custom/UnderlinedTabViewController.cs
+++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/UnderlinedTabViewController.cs
@@ -9,6 +9,14 @@ namespace Xamarin.PropertyEditing.Mac
: NotifyingTabViewController<TViewModel>
where TViewModel : NotifyingObject
{
+ public UnderlinedTabViewController (IHostResourceProvider hostResources)
+ {
+ if (hostResources == null)
+ throw new ArgumentNullException (nameof (hostResources));
+
+ HostResources = hostResources;
+ }
+
public override void InsertTabViewItem (NSTabViewItem tabViewItem, nint index)
{
this.tabStack.InsertView (GetView (tabViewItem), (nuint)index, NSStackViewGravity.Leading);
@@ -84,6 +92,11 @@ namespace Xamarin.PropertyEditing.Mac
View = this.outerStack;
}
+ protected IHostResourceProvider HostResources
+ {
+ get;
+ }
+
private IUnderliningTabView selected;
private NSStackView outerStack;
private NSStackView innerStack;
@@ -110,7 +123,7 @@ namespace Xamarin.PropertyEditing.Mac
{
NSView tabView;
if (item.Identifier != null) {
- tabView = new UnderlinedImageView ((item.Identifier as NSString).ToString()) {
+ tabView = new UnderlinedImageView (HostResources, ((NSString)item.Identifier).ToString()) {
Selected = this.tabStack.Views.Length == SelectedTabViewItemIndex,
ToolTip = item.ToolTip
};
diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/UnderlinedTextField.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/UnderlinedTextField.cs
index 0c5f921..af60712 100644
--- a/Xamarin.PropertyEditing.Mac/Controls/Custom/UnderlinedTextField.cs
+++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/UnderlinedTextField.cs
@@ -1,4 +1,5 @@
-using AppKit;
+using System;
+using AppKit;
using CoreGraphics;
namespace Xamarin.PropertyEditing.Mac
@@ -10,13 +11,15 @@ namespace Xamarin.PropertyEditing.Mac
internal class UnderlinedImageView : NSImageView, IUnderliningTabView
{
- public UnderlinedImageView (string name)
+ public UnderlinedImageView (IHostResourceProvider hostResources, string name)
{
+ if (hostResources == null)
+ throw new ArgumentNullException (nameof (hostResources));
+
+ this.hostResources = hostResources;
this.name = name;
}
- private string name;
-
private bool selected;
public bool Selected
{
@@ -43,18 +46,9 @@ namespace Xamarin.PropertyEditing.Mac
}
}
-
- private string VersionName {
- get {
- return PropertyEditorPanel.ThemeManager.GetImageNameForTheme (this.name, this.selected);
- }
- }
-
public override void DrawRect (CGRect dirtyRect)
{
- if (Image?.Name != VersionName) {
- Image = PropertyEditorPanel.ThemeManager.GetImageForTheme (this.name, this.selected);
- }
+ Image = this.hostResources.GetNamedImage (this.name + ((Selected) ? "~sel" : String.Empty));
base.DrawRect (dirtyRect);
if (!Selected)
@@ -62,7 +56,7 @@ namespace Xamarin.PropertyEditing.Mac
NSBezierPath path = new NSBezierPath ();
path.AppendPathWithRect (new CGRect (Bounds.X, Bounds.Top + this.lineWidth, Bounds.Width, this.lineWidth));
- (selected? NSColor.Text: NSColor.DisabledControlText).Set ();
+ (Selected ? NSColor.Text: NSColor.DisabledControlText).Set ();
path.Fill ();
}
@@ -73,6 +67,9 @@ namespace Xamarin.PropertyEditing.Mac
return new CGSize (size.Width + this.lineWidth + 10, size.Height + this.lineWidth + 10);
}
}
+
+ private readonly IHostResourceProvider hostResources;
+ private readonly string name;
}
internal class UnderlinedTextField : NSTextField, IUnderliningTabView
diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/UnfocusableButton.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/UnfocusableButton.cs
index 27c4496..e00482d 100644
--- a/Xamarin.PropertyEditing.Mac/Controls/Custom/UnfocusableButton.cs
+++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/UnfocusableButton.cs
@@ -16,19 +16,9 @@ namespace Xamarin.PropertyEditing.Mac
{
Enabled = true;
ImageScaling = NSImageScale.AxesIndependently;
-
- PropertyEditorPanel.ThemeManager.ThemeChanged += ThemeManager_ThemeChanged;
-
- UpdateTheme ();
}
#region Overridden Methods
- protected override void Dispose (bool disposing)
- {
- if (disposing) {
- PropertyEditorPanel.ThemeManager.ThemeChanged -= ThemeManager_ThemeChanged;
- }
- }
public override void MouseDown (NSEvent theEvent)
{
@@ -96,15 +86,6 @@ namespace Xamarin.PropertyEditing.Mac
OnMouseRightDown?.Invoke (this, EventArgs.Empty);
}
- void ThemeManager_ThemeChanged (object sender, EventArgs e)
- {
- UpdateTheme ();
- }
-
- protected virtual void UpdateTheme ()
- {
- this.Appearance = PropertyEditorPanel.ThemeManager.CurrentAppearance;
- }
#endregion
}
}
diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/UnfocusableTextField.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/UnfocusableTextField.cs
index d3abc2a..cafad65 100644
--- a/Xamarin.PropertyEditing.Mac/Controls/Custom/UnfocusableTextField.cs
+++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/UnfocusableTextField.cs
@@ -41,24 +41,15 @@ namespace Xamarin.PropertyEditing.Mac
public UnfocusableTextField ()
{
SetDefaultTextProperties ();
- SetTheming ();
}
public UnfocusableTextField (CGRect frameRect, string text) : base (frameRect)
{
SetDefaultTextProperties ();
- SetTheming ();
StringValue = text;
}
- protected override void Dispose (bool disposing)
- {
- if (disposing) {
- PropertyEditorPanel.ThemeManager.ThemeChanged -= ThemeManager_ThemeChanged;
- }
- }
-
private void SetDefaultTextProperties ()
{
this.label = new NSTextField {
@@ -84,22 +75,5 @@ namespace Xamarin.PropertyEditing.Mac
NSLayoutConstraint.Create (this, NSLayoutAttribute.Trailing, NSLayoutRelation.Equal, this.label, NSLayoutAttribute.Trailing, 1f, 0f)
});
}
-
- private void SetTheming ()
- {
- PropertyEditorPanel.ThemeManager.ThemeChanged += ThemeManager_ThemeChanged;
-
- UpdateTheme ();
- }
-
- private void ThemeManager_ThemeChanged (object sender, EventArgs e)
- {
- UpdateTheme ();
- }
-
- protected void UpdateTheme ()
- {
- Appearance = PropertyEditorPanel.ThemeManager.CurrentAppearance;
- }
}
} \ No newline at end of file