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
|
using System;
using System.Collections;
using System.ComponentModel;
using AppKit;
using Xamarin.PropertyEditing.ViewModels;
namespace Xamarin.PropertyEditing.Mac
{
internal class RatioEditorControl<T> : PropertyEditorControl<RatioViewModel>
{
private RatioEditor<T> ratioEditor;
public RatioEditorControl (IHostResourceProvider hostResources)
: base (hostResources)
{
base.TranslatesAutoresizingMaskIntoConstraints = false;
this.ratioEditor = new RatioEditor<T> (hostResources) {
AllowNegativeValues = false,
AllowRatios = true,
BackgroundColor = NSColor.Clear,
StringValue = string.Empty,
TranslatesAutoresizingMaskIntoConstraints = false,
};
// update the value on keypress
this.ratioEditor.ValueChanged += (sender, e) => {
if (e is RatioEditor<T>.RatioEventArgs ratioEventArgs) {
ViewModel.ValueChanged (this.ratioEditor.StringValue, ratioEventArgs.CaretPosition, ratioEventArgs.SelectionLength, ratioEventArgs.IncrementValue);
}
};
AddSubview (this.ratioEditor);
this.AddConstraints (new[] {
NSLayoutConstraint.Create (this.ratioEditor, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1f, 0),
NSLayoutConstraint.Create (this.ratioEditor, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, 0),
NSLayoutConstraint.Create (this.ratioEditor, NSLayoutAttribute.Height, NSLayoutRelation.Equal, this, NSLayoutAttribute.Height, 1, -6),
});
}
public override NSView FirstKeyView => ratioEditor.NumericEditor;
public override NSView LastKeyView => ratioEditor.DecrementButton;
protected override void SetEnabled ()
{
this.ratioEditor.Enabled = ViewModel.Property.CanWrite;
}
protected override void UpdateAccessibilityValues ()
{
this.ratioEditor.AccessibilityEnabled = this.ratioEditor.Enabled;
this.ratioEditor.AccessibilityTitle = string.Format (Properties.Resources.AccessibilityNumeric, ViewModel.Property.Name);
}
protected override void UpdateValue ()
{
this.ratioEditor.StringValue = ViewModel.ValueString;
}
}
}
|