4
4
using System . Drawing ;
5
5
using AppKit ;
6
6
using CoreGraphics ;
7
+ using Xamarin . PropertyEditing . Drawing ;
7
8
using Xamarin . PropertyEditing . ViewModels ;
8
9
9
10
namespace Xamarin . PropertyEditing . Mac
@@ -19,9 +20,15 @@ internal abstract class BaseRectangleEditorControl<T> : PropertyEditorControl<Pr
19
20
protected UnfocusableTextField HeightLabel { get ; set ; }
20
21
protected NumericSpinEditor < T > HeightEditor { get ; set ; }
21
22
22
- public override NSView FirstKeyView => XEditor ;
23
+ public override NSView FirstKeyView => this . firstKeyView ;
23
24
public override NSView LastKeyView => HeightEditor . DecrementButton ;
24
25
26
+ public NSLayoutConstraint LeftXEditorEdgeConstraint { get ; }
27
+ private OriginControl originView ;
28
+ private NSLayoutConstraint originViewConstraint ;
29
+ private CommonOrigin lastOrigin = CommonOrigin . TopLeft ;
30
+ private NSView firstKeyView ;
31
+
25
32
protected BaseRectangleEditorControl ( IHostResourceProvider hostResources )
26
33
: base ( hostResources )
27
34
{
@@ -35,7 +42,7 @@ protected BaseRectangleEditorControl (IHostResourceProvider hostResources)
35
42
} ;
36
43
XEditor . ValueChanged += OnInputUpdated ;
37
44
38
- YLabel = new UnfocusableTextField {
45
+ YLabel = new UnfocusableTextField {
39
46
Font = NSFont . FromFontName ( DefaultFontName , DefaultDescriptionLabelFontSize ) ,
40
47
TranslatesAutoresizingMaskIntoConstraints = false ,
41
48
} ;
@@ -55,7 +62,7 @@ protected BaseRectangleEditorControl (IHostResourceProvider hostResources)
55
62
} ;
56
63
WidthEditor . ValueChanged += OnInputUpdated ;
57
64
58
- HeightLabel = new UnfocusableTextField {
65
+ HeightLabel = new UnfocusableTextField {
59
66
Font = NSFont . FromFontName ( DefaultFontName , DefaultDescriptionLabelFontSize ) ,
60
67
TranslatesAutoresizingMaskIntoConstraints = false ,
61
68
} ;
@@ -74,9 +81,11 @@ protected BaseRectangleEditorControl (IHostResourceProvider hostResources)
74
81
AddSubview ( HeightLabel ) ;
75
82
AddSubview ( HeightEditor ) ;
76
83
77
- this . AddConstraints ( new [ ] {
84
+ LeftXEditorEdgeConstraint = NSLayoutConstraint . Create ( XEditor , NSLayoutAttribute . Left , NSLayoutRelation . Equal , this , NSLayoutAttribute . Left , 1f , 0 ) ;
85
+
86
+ AddConstraints ( new [ ] {
78
87
NSLayoutConstraint . Create ( XEditor , NSLayoutAttribute . Top , NSLayoutRelation . Equal , this , NSLayoutAttribute . Top , 1f , 3f ) ,
79
- NSLayoutConstraint . Create ( XEditor , NSLayoutAttribute . Left , NSLayoutRelation . Equal , this , NSLayoutAttribute . Left , 1f , 0f ) ,
88
+ LeftXEditorEdgeConstraint ,
80
89
NSLayoutConstraint . Create ( XEditor , NSLayoutAttribute . Right , NSLayoutRelation . Equal , YEditor , NSLayoutAttribute . Left , 1f , - 10f ) ,
81
90
NSLayoutConstraint . Create ( XEditor , NSLayoutAttribute . Height , NSLayoutRelation . Equal , 1f , 18 ) ,
82
91
@@ -92,7 +101,7 @@ protected BaseRectangleEditorControl (IHostResourceProvider hostResources)
92
101
NSLayoutConstraint . Create ( YLabel , NSLayoutAttribute . Height , NSLayoutRelation . Equal , 1f , 18 ) ,
93
102
94
103
NSLayoutConstraint . Create ( WidthEditor , NSLayoutAttribute . Top , NSLayoutRelation . Equal , this , NSLayoutAttribute . Top , 1f , 33f ) ,
95
- NSLayoutConstraint . Create ( WidthEditor , NSLayoutAttribute . Left , NSLayoutRelation . Equal , this , NSLayoutAttribute . Left , 1f , 0f ) ,
104
+ NSLayoutConstraint . Create ( WidthEditor , NSLayoutAttribute . Left , NSLayoutRelation . Equal , XEditor , NSLayoutAttribute . Left , 1f , 0f ) ,
96
105
NSLayoutConstraint . Create ( WidthEditor , NSLayoutAttribute . Right , NSLayoutRelation . Equal , HeightEditor , NSLayoutAttribute . Left , 1f , - 10f ) ,
97
106
NSLayoutConstraint . Create ( WidthEditor , NSLayoutAttribute . Height , NSLayoutRelation . Equal , 1f , 18 ) ,
98
107
@@ -114,12 +123,14 @@ protected BaseRectangleEditorControl (IHostResourceProvider hostResources)
114
123
NSLayoutConstraint . Create ( HeightLabel , NSLayoutAttribute . CenterX , NSLayoutRelation . Equal , HeightEditor . Subviews [ 0 ] , NSLayoutAttribute . CenterX , 1f , 0 ) ,
115
124
} ) ;
116
125
126
+ this . firstKeyView = XEditor ;
127
+
117
128
AppearanceChanged ( ) ;
118
129
}
119
130
120
131
protected virtual void OnInputUpdated ( object sender , EventArgs e )
121
132
{
122
- ViewModel . Value = ( T ) Activator . CreateInstance ( typeof ( T ) , XEditor . Value , YEditor . Value , WidthEditor . Value , HeightEditor . Value ) ;
133
+ ViewModel . Value = ( T ) Activator . CreateInstance ( typeof ( T ) , XEditor . Value , YEditor . Value , WidthEditor . Value , HeightEditor . Value ) ;
123
134
}
124
135
125
136
protected override void SetEnabled ( )
@@ -128,6 +139,10 @@ protected override void SetEnabled ()
128
139
YEditor . Enabled = ViewModel . Property . CanWrite ;
129
140
WidthEditor . Enabled = ViewModel . Property . CanWrite ;
130
141
HeightEditor . Enabled = ViewModel . Property . CanWrite ;
142
+
143
+ if ( this . originView != null ) {
144
+ this . originView . Enabled = ViewModel . Property . CanWrite ;
145
+ }
131
146
}
132
147
133
148
protected override void UpdateAccessibilityValues ( )
@@ -154,5 +169,54 @@ protected override void AppearanceChanged ()
154
169
WidthLabel . TextColor = HostResources . GetNamedColor ( NamedResources . DescriptionLabelColor ) ;
155
170
HeightLabel . TextColor = HostResources . GetNamedColor ( NamedResources . DescriptionLabelColor ) ;
156
171
}
172
+
173
+ protected override void OnViewModelChanged ( PropertyViewModel oldModel )
174
+ {
175
+ base . OnViewModelChanged ( oldModel ) ;
176
+
177
+ if ( ViewModel == null )
178
+ return ;
179
+
180
+ LeftXEditorEdgeConstraint . Active = true ;
181
+
182
+ if ( ViewModel is RectanglePropertyViewModel rpvm && rpvm . HasOrigin ) {
183
+ LeftXEditorEdgeConstraint . Active = false ;
184
+ if ( this . originView == null ) {
185
+ this . originView = new OriginControl ( HostResources ) {
186
+ AccessibilityEnabled = ViewModel . Property . CanWrite ,
187
+ AccessibilityTitle = string . Format ( Properties . Resources . AccessibilityOriginEditor , ViewModel . Property . Name ) ,
188
+ Enabled = rpvm . Property . CanWrite ,
189
+ //TODO Origin = rpvm.Origin,
190
+ TranslatesAutoresizingMaskIntoConstraints = false ,
191
+ } ;
192
+
193
+ // TODO this.lastOrigin = rpvm.Origin;
194
+
195
+ this . originView . OriginChanged += ( s , e ) => {
196
+ this . lastOrigin = this . originView . Origin ;
197
+ /* TODO MetricsPropertyEntryHelper.HandleOriginChanged (this, this.originView.Origin, v => {
198
+ if (XEditor.Value != v)
199
+ XEditor.Value = v;
200
+ }, v => {
201
+ if (YEditor.Value != v)
202
+ YEditor.Value = v;
203
+ });*/
204
+ } ;
205
+
206
+ AddSubview ( this . originView ) ;
207
+
208
+ this . originViewConstraint = NSLayoutConstraint . Create ( this . originView , NSLayoutAttribute . Right , NSLayoutRelation . Equal , XEditor , NSLayoutAttribute . Left , 1 , - 4 ) ;
209
+
210
+ AddConstraints ( new [ ] {
211
+ NSLayoutConstraint . Create ( this . originView , NSLayoutAttribute . Top , NSLayoutRelation . Equal , XEditor , NSLayoutAttribute . Top , 1f , 0 ) ,
212
+ NSLayoutConstraint . Create ( this . originView , NSLayoutAttribute . Left , NSLayoutRelation . Equal , this , NSLayoutAttribute . Left , 1f , 0 ) ,
213
+ this . originViewConstraint ,
214
+ NSLayoutConstraint . Create ( this . originView , NSLayoutAttribute . Bottom , NSLayoutRelation . Equal , this , NSLayoutAttribute . Bottom , 1 , - 2f ) ,
215
+ } ) ;
216
+
217
+ this . firstKeyView = this . originView ;
218
+ }
219
+ }
220
+ }
157
221
}
158
222
}
0 commit comments