diff options
Diffstat (limited to 'Xamarin.PropertyEditing.Mac/Controls/Custom')
3 files changed, 90 insertions, 65 deletions
diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/DynamicBox.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/DynamicBox.cs new file mode 100644 index 0000000..a3483a1 --- /dev/null +++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/DynamicBox.cs @@ -0,0 +1,87 @@ +using System; +using AppKit; + +namespace Xamarin.PropertyEditing.Mac +{ + internal class DynamicBox + : NSBox + { + public DynamicBox (IHostResourceProvider hostResources, string fillName = null, string borderName = null) + { + if (hostResources == null) + throw new ArgumentNullException (nameof (hostResources)); + + BorderWidth = 0; + BoxType = NSBoxType.NSBoxCustom; + TranslatesAutoresizingMaskIntoConstraints = false; + + this.fillColor = fillName; + if (fillName == null) + FillColor = NSColor.Clear; + + this.borderColor = borderName; + if (borderName == null) + BorderColor = NSColor.Clear; + + HostResourceProvider = hostResources; + } + + public IHostResourceProvider HostResourceProvider + { + get { return this.hostResources; } + set + { + this.hostResources = value; + ViewDidChangeEffectiveAppearance (); + } + } + + public string FillColorName + { + get => this.fillColor; + set + { + this.fillColor = value; + if (value == null) + FillColor = NSColor.Clear; + + ViewDidChangeEffectiveAppearance (); + } + } + + public string BorderColorName + { + get => this.borderColor; + set + { + this.borderColor = value; + if (value == null) + BorderColor = NSColor.Clear; + + ViewDidChangeEffectiveAppearance (); + } + } + + public override void ViewDidChangeEffectiveAppearance () + { + if (this.fillColor != null) { + NSColor color = this.hostResources.GetNamedColor (this.fillColor); + if (color == null) + return; + + FillColor = color; + } + + if (this.borderColor != null) { + NSColor color = this.hostResources.GetNamedColor (this.borderColor); + if (color == null) + return; + + BorderColor = color; + } + } + + private IHostResourceProvider hostResources; + private string fillColor, borderColor; + } +} diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/DynamicFillBox.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/DynamicFillBox.cs deleted file mode 100644 index a542b5d..0000000 --- a/Xamarin.PropertyEditing.Mac/Controls/Custom/DynamicFillBox.cs +++ /dev/null @@ -1,62 +0,0 @@ -using System; -using AppKit; - -namespace Xamarin.PropertyEditing.Mac -{ - internal class DynamicFillBox - : NSBox - { - public DynamicFillBox (IHostResourceProvider hostResources, string colorName) - { - if (hostResources == null) - throw new ArgumentNullException (nameof (hostResources)); - - BorderWidth = 0; - BoxType = NSBoxType.NSBoxCustom; - TranslatesAutoresizingMaskIntoConstraints = false; - this.colorName = colorName; - if (colorName == null) - FillColor = NSColor.Clear; - - HostResourceProvider = hostResources; - } - - public IHostResourceProvider HostResourceProvider - { - get { return this.hostResources; } - set - { - this.hostResources = value; - ViewDidChangeEffectiveAppearance (); - } - } - - public string FillColorName - { - get => this.colorName; - set - { - this.colorName = value; - if (value == null) - FillColor = NSColor.Clear; - - ViewDidChangeEffectiveAppearance (); - } - } - - public override void ViewDidChangeEffectiveAppearance () - { - if (this.colorName == null) - return; - - NSColor color = this.hostResources.GetNamedColor (this.colorName); - if (color == null) - return; - - FillColor = color; - } - - private IHostResourceProvider hostResources; - private string colorName; - } -} diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/UnderlinedTabViewController.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/UnderlinedTabViewController.cs index fa2e4d9..4911171 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/Custom/UnderlinedTabViewController.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/UnderlinedTabViewController.cs @@ -104,7 +104,7 @@ namespace Xamarin.PropertyEditing.Mac NSView tabs = this.tabStack; if (TabBackgroundColor != null) { - this.tabContainer = new DynamicFillBox (HostResources, TabBackgroundColor) { + this.tabContainer = new DynamicBox (HostResources, TabBackgroundColor) { ContentView = this.tabStack }; @@ -114,7 +114,7 @@ namespace Xamarin.PropertyEditing.Mac this.innerStack.AddView (tabs, NSStackViewGravity.Top); if (TabBorderColor != null) {
- this.border = new DynamicFillBox (HostResources, TabBorderColor) { + this.border = new DynamicBox (HostResources, TabBorderColor) { Frame = new CGRect (0, 0, 1, 1), AutoresizingMask = NSViewResizingMask.WidthSizable }; @@ -144,7 +144,7 @@ namespace Xamarin.PropertyEditing.Mac private string tabBackground, tabBorder;
private IUnderliningTabView selected; - private DynamicFillBox tabContainer, border;
+ private DynamicBox tabContainer, border;
private NSStackView innerStack;
private readonly NSStackView tabStack = new NSStackView () {
Spacing = 1f,
|