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
95
96
97
98
99
100
101
102
103
104
|
using System;
using System.Collections;
using System.Diagnostics;
using AppKit;
using Xamarin.PropertyEditing.ViewModels;
namespace Xamarin.PropertyEditing.Mac
{
internal abstract class BasePointEditorControl<T> : PropertyEditorControl<PropertyViewModel<T>>
{
internal UnfocusableTextField XLabel { get; set; }
internal NumericSpinEditor<T> XEditor { get; set; }
internal UnfocusableTextField YLabel { get; set; }
internal NumericSpinEditor<T> YEditor { get; set; }
public override NSView FirstKeyView => XEditor;
public override NSView LastKeyView => YEditor.DecrementButton;
protected BasePointEditorControl (IHostResourceProvider hostResources)
: base (hostResources)
{
XLabel = new UnfocusableTextField {
Font = NSFont.FromFontName (DefaultFontName, DefaultDescriptionLabelFontSize),
TranslatesAutoresizingMaskIntoConstraints = false,
};
XEditor = new NumericSpinEditor<T> (hostResources) {
BackgroundColor = NSColor.Clear,
Value = 0.0f
};
XEditor.ProxyResponder = new ProxyResponder (this, ProxyRowType.FirstView);
XEditor.ValueChanged += OnInputUpdated;
YLabel = new UnfocusableTextField {
Font = NSFont.FromFontName (DefaultFontName, DefaultDescriptionLabelFontSize),
TranslatesAutoresizingMaskIntoConstraints = false,
};
YEditor = new NumericSpinEditor<T> (hostResources) {
BackgroundColor = NSColor.Clear,
Value = 0.0f
};
YEditor.ProxyResponder = new ProxyResponder (this, ProxyRowType.LastView);
YEditor.ValueChanged += OnInputUpdated;
AddSubview (XLabel);
AddSubview (XEditor);
AddSubview (YLabel);
AddSubview (YEditor);
const float editorHeight = 18;
this.AddConstraints (new[] {
NSLayoutConstraint.Create (XEditor, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 3f),
NSLayoutConstraint.Create (XEditor, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, 0f),
NSLayoutConstraint.Create (XEditor, NSLayoutAttribute.Right, NSLayoutRelation.Equal, YEditor, NSLayoutAttribute.Left, 1f, -10f),
NSLayoutConstraint.Create (XEditor, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, editorHeight),
NSLayoutConstraint.Create (XLabel, NSLayoutAttribute.Top, NSLayoutRelation.Equal, XEditor, NSLayoutAttribute.Bottom, 1f, -4f),
NSLayoutConstraint.Create (XLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, editorHeight),
NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 3f),
NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this, NSLayoutAttribute.Right, 1f, 0),
NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Width, NSLayoutRelation.Equal, XEditor, NSLayoutAttribute.Width, 1f, 0f),
NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, editorHeight),
NSLayoutConstraint.Create (YLabel, NSLayoutAttribute.Top, NSLayoutRelation.Equal, XLabel, NSLayoutAttribute.Top, 1f, 0f),
NSLayoutConstraint.Create (YLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, editorHeight),
NSLayoutConstraint.Create (XLabel, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, XEditor.Subviews[0], NSLayoutAttribute.CenterX, 1f, 0),
NSLayoutConstraint.Create (YLabel, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, YEditor.Subviews[0], NSLayoutAttribute.CenterX, 1f, 0),
});
AppearanceChanged ();
}
protected override void SetEnabled ()
{
XEditor.Enabled = ViewModel.Property.CanWrite;
YEditor.Enabled = ViewModel.Property.CanWrite;
}
protected override void UpdateAccessibilityValues ()
{
XEditor.AccessibilityEnabled = XEditor.Enabled;
XEditor.AccessibilityTitle = string.Format (Properties.Resources.AccessibilityXEditor, ViewModel.Property.Name);
YEditor.AccessibilityEnabled = YEditor.Enabled;
YEditor.AccessibilityTitle = string.Format (Properties.Resources.AccessibilityYEditor, ViewModel.Property.Name);
}
protected virtual void OnInputUpdated (object sender, EventArgs e)
{
ViewModel.Value = (T)Activator.CreateInstance (typeof (T), XEditor.Value, YEditor.Value);
}
protected override void AppearanceChanged ()
{
base.AppearanceChanged ();
XLabel.TextColor = HostResources.GetNamedColor (NamedResources.DescriptionLabelColor);
YLabel.TextColor = HostResources.GetNamedColor (NamedResources.DescriptionLabelColor);
}
}
}
|