blob: 7a6aeddbbed017c7014355da06c87cf029ec1b5d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
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;
AppearanceChanged ();
}
}
public string FillColorName
{
get => this.fillColor;
set
{
this.fillColor = value;
if (value == null)
FillColor = NSColor.Clear;
AppearanceChanged ();
}
}
public string BorderColorName
{
get => this.borderColor;
set
{
this.borderColor = value;
if (value == null)
BorderColor = NSColor.Clear;
AppearanceChanged ();
}
}
public sealed override void ViewDidChangeEffectiveAppearance ()
{
base.ViewDidChangeEffectiveAppearance ();
AppearanceChanged ();
}
private IHostResourceProvider hostResources;
private string fillColor, borderColor;
private void AppearanceChanged ()
{
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;
}
}
}
}
|