blob: d21b2d11b1b5162253405ac7096bb84ae256c758 (
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
using System;
using System.Collections;
using System.Diagnostics;
using System.Drawing;
using AppKit;
using CoreGraphics;
using Xamarin.PropertyEditing.ViewModels;
namespace Xamarin.PropertyEditing.Mac
{
internal abstract class BaseRectangleEditorControl<T> : PropertyEditorControl
where T : struct
{
protected UnfocusableTextField XLabel { get; set; }
protected NSTextField XEditor { get; set; }
protected UnfocusableTextField YLabel { get; set; }
protected NSTextField YEditor { get; set; }
protected UnfocusableTextField WidthLabel { get; set; }
protected NSTextField WidthEditor { get; set; }
protected UnfocusableTextField HeightLabel { get; set; }
protected NSTextField HeightEditor { get; set; }
public override NSView FirstKeyView => XEditor;
public override NSView LastKeyView => HeightEditor;
internal new PropertyViewModel<T> ViewModel {
get { return (PropertyViewModel<T>)base.ViewModel; }
set { base.ViewModel = value; }
}
public BaseRectangleEditorControl ()
{
XLabel = new UnfocusableTextField ();
XEditor = new NSTextField ();
XEditor.BackgroundColor = NSColor.Clear;
XEditor.StringValue = string.Empty;
XEditor.Activated += OnInputUpdated;
XEditor.EditingEnded += OnInputUpdated;
YLabel = new UnfocusableTextField ();
YEditor = new NSTextField ();
YEditor.BackgroundColor = NSColor.Clear;
YEditor.StringValue = string.Empty;
YEditor.Activated += OnInputUpdated;
YEditor.EditingEnded += OnInputUpdated;
WidthLabel = new UnfocusableTextField ();
WidthEditor = new NSTextField ();
WidthEditor.BackgroundColor = NSColor.Clear;
WidthEditor.StringValue = string.Empty;
WidthEditor.Activated += OnInputUpdated;
WidthEditor.EditingEnded += OnInputUpdated;
HeightLabel = new UnfocusableTextField ();
HeightEditor = new NSTextField ();
HeightEditor.BackgroundColor = NSColor.Clear;
HeightEditor.StringValue = string.Empty;
HeightEditor.Activated += OnInputUpdated;
HeightEditor.EditingEnded += OnInputUpdated;
AddSubview (XLabel);
AddSubview (XEditor);
AddSubview (YLabel);
AddSubview (YEditor);
AddSubview (WidthLabel);
AddSubview (WidthEditor);
AddSubview (HeightLabel);
AddSubview (HeightEditor);
}
protected virtual void OnInputUpdated (object sender, EventArgs e)
{
ViewModel.Value = (T)Activator.CreateInstance (typeof(T), XEditor.FloatValue, YEditor.FloatValue, WidthEditor.FloatValue, HeightEditor.FloatValue);
}
protected override void HandleErrorsChanged (object sender, System.ComponentModel.DataErrorsChangedEventArgs e)
{
UpdateErrorsDisplayed (ViewModel.GetErrors (ViewModel.Property.Name));
}
protected override void UpdateErrorsDisplayed (IEnumerable errors)
{
if (ViewModel.HasErrors) {
XEditor.BackgroundColor = NSColor.Red;
YEditor.BackgroundColor = NSColor.Red;
WidthEditor.BackgroundColor = NSColor.Red;
HeightEditor.BackgroundColor = NSColor.Red;
Debug.WriteLine ("Your input triggered an error:");
foreach (var error in errors) {
Debug.WriteLine (error.ToString () + "\n");
}
}
else {
XEditor.BackgroundColor = NSColor.Clear;
YEditor.BackgroundColor = NSColor.Clear;
WidthEditor.BackgroundColor = NSColor.Clear;
HeightEditor.BackgroundColor = NSColor.Clear;
SetEnabled ();
}
}
protected override void SetEnabled ()
{
XEditor.Editable = ViewModel.Property.CanWrite;
YEditor.Editable = ViewModel.Property.CanWrite;
WidthEditor.Editable = ViewModel.Property.CanWrite;
HeightEditor.Editable = ViewModel.Property.CanWrite;
}
}
}
|