Skip to content
This repository was archived by the owner on Sep 25, 2024. It is now read-only.

Commit 1f9c340

Browse files
Dominique LouisCartBlanche
Dominique Louis
authored andcommitted
[Mac] Initial Variations Implementation
1 parent 0525c4d commit 1f9c340

File tree

57 files changed

+1096
-200
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1096
-200
lines changed

Xamarin.PropertyEditing.Mac/Controls/BasePathEditorControl.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ internal abstract class BasePathEditorControl<T> : PropertyEditorControl<Propert
2626
protected BasePathEditorControl (IHostResourceProvider hostResource)
2727
: base (hostResource)
2828
{
29-
this.currentTextField = new TextFieldSmallButtonContainer ();
29+
this.currentTextField = new TextFieldSmallButtonContainer {
30+
ControlSize = NSControlSize.Small,
31+
Font = NSFont.SystemFontOfSize (NSFont.SystemFontSizeForControlSize (NSControlSize.Small)),
32+
};
3033
this.currentTextField.Changed += CurrentTextField_Changed;
3134
AddSubview (this.currentTextField);
3235

@@ -78,9 +81,8 @@ protected BasePathEditorControl (IHostResourceProvider hostResource)
7881

7982
AddConstraints (new[] {
8083
NSLayoutConstraint.Create (this.currentTextField, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1, 0f),
81-
NSLayoutConstraint.Create (this.currentTextField, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1, 0f),
84+
NSLayoutConstraint.Create (this.currentTextField, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, this, NSLayoutAttribute.Bottom, 1, -2f),
8285
NSLayoutConstraint.Create (this.currentTextField, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1, 0f),
83-
NSLayoutConstraint.Create (this.currentTextField, NSLayoutAttribute.Height, NSLayoutRelation.Equal, this, NSLayoutAttribute.Height, 1, -6f),
8486
});
8587
}
8688

Xamarin.PropertyEditing.Mac/Controls/BasePointEditorControl.cs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,23 +46,21 @@ protected BasePointEditorControl (IHostResourceProvider hostResources)
4646
AddSubview (YLabel);
4747
AddSubview (YEditor);
4848

49-
const float editorHeight = 18;
50-
this.AddConstraints (new[] {
51-
NSLayoutConstraint.Create (XEditor, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 3f),
49+
nfloat labelHeight = NSFont.SystemFontSizeForControlSize (NSControlSize.Small);
50+
AddConstraints (new[] {
51+
NSLayoutConstraint.Create (XLabel, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, this, NSLayoutAttribute.Bottom, 1f, BottomOffset + 1),
52+
NSLayoutConstraint.Create (XLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, labelHeight),
53+
54+
NSLayoutConstraint.Create (XEditor, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, XLabel, NSLayoutAttribute.Top, 1f, -1f),
5255
NSLayoutConstraint.Create (XEditor, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, 0f),
5356
NSLayoutConstraint.Create (XEditor, NSLayoutAttribute.Right, NSLayoutRelation.Equal, YEditor, NSLayoutAttribute.Left, 1f, -10f),
54-
NSLayoutConstraint.Create (XEditor, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, editorHeight),
55-
56-
NSLayoutConstraint.Create (XLabel, NSLayoutAttribute.Top, NSLayoutRelation.Equal, XEditor, NSLayoutAttribute.Bottom, 1f, -4f),
57-
NSLayoutConstraint.Create (XLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, editorHeight),
5857

59-
NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 3f),
58+
NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, YLabel, NSLayoutAttribute.Top, 1f, -1f),
6059
NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this, NSLayoutAttribute.Right, 1f, 0),
6160
NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Width, NSLayoutRelation.Equal, XEditor, NSLayoutAttribute.Width, 1f, 0f),
62-
NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, editorHeight),
6361

6462
NSLayoutConstraint.Create (YLabel, NSLayoutAttribute.Top, NSLayoutRelation.Equal, XLabel, NSLayoutAttribute.Top, 1f, 0f),
65-
NSLayoutConstraint.Create (YLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, editorHeight),
63+
NSLayoutConstraint.Create (YLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, labelHeight),
6664

6765
NSLayoutConstraint.Create (XLabel, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, XEditor.Subviews[0], NSLayoutAttribute.CenterX, 1f, 0),
6866
NSLayoutConstraint.Create (YLabel, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, YEditor.Subviews[0], NSLayoutAttribute.CenterX, 1f, 0),
@@ -98,5 +96,10 @@ protected override void AppearanceChanged ()
9896
XLabel.TextColor = HostResources.GetNamedColor (NamedResources.DescriptionLabelColor);
9997
YLabel.TextColor = HostResources.GetNamedColor (NamedResources.DescriptionLabelColor);
10098
}
99+
100+
public override nint GetHeight (EditorViewModel vm)
101+
{
102+
return 33;
103+
}
101104
}
102105
}

Xamarin.PropertyEditing.Mac/Controls/BaseRectangleEditorControl.cs

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -74,44 +74,41 @@ protected BaseRectangleEditorControl (IHostResourceProvider hostResources)
7474
AddSubview (HeightLabel);
7575
AddSubview (HeightEditor);
7676

77-
this.AddConstraints (new[] {
78-
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),
80-
NSLayoutConstraint.Create (XEditor, NSLayoutAttribute.Right, NSLayoutRelation.Equal, YEditor, NSLayoutAttribute.Left, 1f, -10f),
81-
NSLayoutConstraint.Create (XEditor, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 18),
82-
83-
NSLayoutConstraint.Create (XLabel, NSLayoutAttribute.Top, NSLayoutRelation.Equal, XEditor, NSLayoutAttribute.Bottom, 1f, -4f),
84-
NSLayoutConstraint.Create (XLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 18),
85-
86-
NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 3f),
87-
NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this, NSLayoutAttribute.Right, 1f, 0),
88-
NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Width, NSLayoutRelation.Equal, XEditor, NSLayoutAttribute.Width, 1f, 0f),
89-
NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 18),
90-
91-
NSLayoutConstraint.Create (YLabel, NSLayoutAttribute.Top, NSLayoutRelation.Equal, XLabel, NSLayoutAttribute.Top, 1f, 0f),
92-
NSLayoutConstraint.Create (YLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 18),
77+
nfloat labelHeight = NSFont.SystemFontSizeForControlSize (NSControlSize.Small);
78+
AddConstraints (new[] {
79+
NSLayoutConstraint.Create (WidthLabel, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, this, NSLayoutAttribute.Bottom, 1f, BottomOffset + 1),
80+
NSLayoutConstraint.Create (WidthLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, labelHeight),
9381

94-
NSLayoutConstraint.Create (WidthEditor, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 33f),
82+
NSLayoutConstraint.Create (WidthEditor, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, WidthLabel, NSLayoutAttribute.Top, 1f, -1f),
9583
NSLayoutConstraint.Create (WidthEditor, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, 0f),
9684
NSLayoutConstraint.Create (WidthEditor, NSLayoutAttribute.Right, NSLayoutRelation.Equal, HeightEditor, NSLayoutAttribute.Left, 1f, -10f),
97-
NSLayoutConstraint.Create (WidthEditor, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 18),
9885

99-
NSLayoutConstraint.Create (WidthLabel, NSLayoutAttribute.Top, NSLayoutRelation.Equal, WidthEditor, NSLayoutAttribute.Bottom, 1f, -4f),
100-
NSLayoutConstraint.Create (WidthLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 18),
101-
102-
NSLayoutConstraint.Create (HeightEditor, NSLayoutAttribute.Top, NSLayoutRelation.Equal, WidthEditor, NSLayoutAttribute.Top, 1f, 0f),
86+
NSLayoutConstraint.Create (HeightEditor, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, HeightLabel, NSLayoutAttribute.Top, 1f, -1f),
10387
NSLayoutConstraint.Create (HeightEditor, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this, NSLayoutAttribute.Right, 1f, 0),
10488
NSLayoutConstraint.Create (HeightEditor, NSLayoutAttribute.Width, NSLayoutRelation.Equal, WidthEditor, NSLayoutAttribute.Width, 1f, 0f),
105-
NSLayoutConstraint.Create (HeightEditor, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 18),
10689

10790
NSLayoutConstraint.Create (HeightLabel, NSLayoutAttribute.Top, NSLayoutRelation.Equal, WidthLabel, NSLayoutAttribute.Top, 1f, 0f),
108-
NSLayoutConstraint.Create (HeightLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 18),
91+
NSLayoutConstraint.Create (HeightLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, labelHeight),
10992

93+
NSLayoutConstraint.Create (WidthLabel, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, WidthEditor.Subviews[0], NSLayoutAttribute.CenterX, 1f, 0),
94+
NSLayoutConstraint.Create (HeightLabel, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, HeightEditor.Subviews[0], NSLayoutAttribute.CenterX, 1f, 0),
95+
96+
NSLayoutConstraint.Create (XLabel, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, WidthEditor, NSLayoutAttribute.Top, 1f, 0f),
97+
NSLayoutConstraint.Create (XLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, labelHeight),
98+
99+
NSLayoutConstraint.Create (XEditor, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, XLabel, NSLayoutAttribute.Top, 1f, -1f),
100+
NSLayoutConstraint.Create (XEditor, NSLayoutAttribute.Left, NSLayoutRelation.Equal, WidthEditor, NSLayoutAttribute.Left, 1f, 0f),
101+
NSLayoutConstraint.Create (XEditor, NSLayoutAttribute.Right, NSLayoutRelation.Equal, YEditor, NSLayoutAttribute.Left, 1f, -10f),
102+
103+
NSLayoutConstraint.Create (YLabel, NSLayoutAttribute.Top, NSLayoutRelation.Equal, XLabel, NSLayoutAttribute.Top, 1f, 0f),
104+
NSLayoutConstraint.Create (YLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, labelHeight),
105+
106+
NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Top, NSLayoutRelation.Equal, XEditor, NSLayoutAttribute.Top, 1f, 0f),
107+
NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Right, NSLayoutRelation.Equal, HeightEditor, NSLayoutAttribute.Right, 1f, 0),
108+
NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Width, NSLayoutRelation.Equal, XEditor, NSLayoutAttribute.Width, 1f, 0f),
110109

111110
NSLayoutConstraint.Create (XLabel, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, XEditor.Subviews[0], NSLayoutAttribute.CenterX, 1f, 0),
112111
NSLayoutConstraint.Create (YLabel, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, YEditor.Subviews[0], NSLayoutAttribute.CenterX, 1f, 0),
113-
NSLayoutConstraint.Create (WidthLabel, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, WidthEditor.Subviews[0], NSLayoutAttribute.CenterX, 1f, 0),
114-
NSLayoutConstraint.Create (HeightLabel, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, HeightEditor.Subviews[0], NSLayoutAttribute.CenterX, 1f, 0),
115112
});
116113

117114
AppearanceChanged ();
@@ -154,5 +151,10 @@ protected override void AppearanceChanged ()
154151
WidthLabel.TextColor = HostResources.GetNamedColor (NamedResources.DescriptionLabelColor);
155152
HeightLabel.TextColor = HostResources.GetNamedColor (NamedResources.DescriptionLabelColor);
156153
}
154+
155+
public override nint GetHeight (EditorViewModel vm)
156+
{
157+
return 66;
158+
}
157159
}
158160
}

Xamarin.PropertyEditing.Mac/Controls/BooleanEditorControl.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ namespace Xamarin.PropertyEditing.Mac
88
internal class BooleanEditorControl
99
: PropertyEditorControl<PropertyViewModel<bool?>>
1010
{
11-
const string setBezelColorSelector = "setBezelColor:";
12-
1311
public BooleanEditorControl (IHostResourceProvider hostResource)
1412
: base (hostResource)
1513
{
@@ -29,8 +27,8 @@ public BooleanEditorControl (IHostResourceProvider hostResource)
2927

3028
AddSubview (BooleanEditor);
3129

32-
this.AddConstraints (new[] {
33-
NSLayoutConstraint.Create (BooleanEditor, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1f, 0f),
30+
AddConstraints (new[] {
31+
NSLayoutConstraint.Create (BooleanEditor, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, this, NSLayoutAttribute.Bottom, 1f, -4f),
3432
NSLayoutConstraint.Create (BooleanEditor, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, 0f),
3533
});
3634
}

Xamarin.PropertyEditing.Mac/Controls/CollectionInlineEditorControl.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,11 @@ public CollectionInlineEditorControl (IHostResourceProvider hostResources)
3333

3434
AddConstraints (new[] {
3535
NSLayoutConstraint.Create (this.label, NSLayoutAttribute.Leading, NSLayoutRelation.Equal, this, NSLayoutAttribute.Leading, 1, 0),
36-
NSLayoutConstraint.Create (this.label, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1, 0),
36+
NSLayoutConstraint.Create (this.label, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this.openCollection, NSLayoutAttribute.CenterY, 1, 0),
3737
NSLayoutConstraint.Create (this.label, NSLayoutAttribute.Height, NSLayoutRelation.Equal, this, NSLayoutAttribute.Height, 1, 0),
3838
NSLayoutConstraint.Create (this.openCollection, NSLayoutAttribute.Leading, NSLayoutRelation.Equal, this.label, NSLayoutAttribute.Trailing, 1, 12),
39-
NSLayoutConstraint.Create (this.openCollection, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1, 0),
39+
NSLayoutConstraint.Create (this.openCollection, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, this, NSLayoutAttribute.Bottom, 1, -2),
4040
NSLayoutConstraint.Create (this.openCollection, NSLayoutAttribute.Width, NSLayoutRelation.GreaterThanOrEqual, 1, 70),
41-
NSLayoutConstraint.Create (this.openCollection, NSLayoutAttribute.Height, NSLayoutRelation.Equal, this, NSLayoutAttribute.Height, 1, -6)
4241
});
4342

4443
AppearanceChanged ();

Xamarin.PropertyEditing.Mac/Controls/CombinablePropertyEditor.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@ public CombinablePropertyEditor (IHostResourceProvider hostResources)
3030
public override nint GetHeight (EditorViewModel vm)
3131
{
3232
var realVm = (CombinablePropertyViewModel<T>)vm;
33-
return subrowHeight * realVm.Choices.Count + 6;
33+
nint baseHeight = subrowHeight * realVm.Choices.Count + 6;
34+
if (realVm != null && realVm.IsVariant) {
35+
return (baseHeight * 2);
36+
}
37+
38+
return baseHeight;
3439
}
3540

3641
protected override void SetEnabled ()

Xamarin.PropertyEditing.Mac/Controls/Custom/BasePopOverViewModelControl.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4+
using AppKit;
45
using Xamarin.PropertyEditing.ViewModels;
56

67
namespace Xamarin.PropertyEditing.Mac
@@ -9,6 +10,8 @@ internal class BasePopOverViewModelControl : BasePopOverControl
910
{
1011
internal PropertyViewModel ViewModel { get; }
1112

13+
public AutoClosePopOver PopOver { get; internal set; }
14+
1215
public BasePopOverViewModelControl (IHostResourceProvider hostResources, PropertyViewModel viewModel, string title, string imageNamed)
1316
: base (hostResources, title, imageNamed)
1417
{

Xamarin.PropertyEditing.Mac/Controls/Custom/CommandButton.cs

Lines changed: 119 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ internal class CommandButton : NSButton
88
{
99
private ICommand command;
1010

11+
public event EventHandler OnMouseEntered;
12+
public event EventHandler OnMouseExited;
13+
public event EventHandler OnMouseLeftDown;
14+
public event EventHandler OnMouseRightDown;
15+
16+
private NSTrackingArea trackingArea;
17+
private bool commandFired;
18+
1119
public ICommand Command
1220
{
1321
get { return this.command; }
@@ -24,16 +32,122 @@ public ICommand Command
2432

2533
public CommandButton ()
2634
{
27-
Activated += (object sender, EventArgs e) => {
28-
var button = (CommandButton)sender;
29-
button.command?.Execute (null);
30-
};
35+
Activated += ExecuteCommand;
36+
}
37+
38+
private void ExecuteCommand (object sender, EventArgs e)
39+
{
40+
if (Enabled && !this.commandFired) {
41+
this.command?.Execute (null);
42+
return;
43+
}
44+
this.commandFired = false;
45+
}
46+
47+
#region Overridden Methods
48+
49+
public override void MouseDown (NSEvent theEvent)
50+
{
51+
if (Enabled) {
52+
switch (theEvent.Type) {
53+
case NSEventType.LeftMouseDown:
54+
NotifyMouseLeftDown ();
55+
break;
56+
57+
case NSEventType.RightMouseDown:
58+
NotifyMouseRightDown ();
59+
break;
60+
}
61+
base.MouseDown (theEvent);
62+
}
63+
}
64+
65+
public override void MouseEntered (NSEvent theEvent)
66+
{
67+
if (Enabled) {
68+
NotifyMouseEntered ();
69+
base.MouseEntered (theEvent);
70+
}
71+
}
72+
73+
public override void MouseExited (NSEvent theEvent)
74+
{
75+
if (Enabled) {
76+
NotifyMouseExited ();
77+
base.MouseExited (theEvent);
78+
}
79+
}
80+
81+
public override void UpdateTrackingAreas ()
82+
{
83+
base.UpdateTrackingAreas ();
84+
85+
// Add tracking so our MouseEntered and MouseExited get called.
86+
if (this.trackingArea == null) {
87+
NSTrackingAreaOptions options = NSTrackingAreaOptions.MouseEnteredAndExited | NSTrackingAreaOptions.ActiveAlways;
88+
89+
this.trackingArea = new NSTrackingArea (Bounds, options, this, null);
90+
91+
AddTrackingArea (this.trackingArea);
92+
}
3193
}
94+
#endregion
3295

96+
97+
#region Local Methods
3398
private void CanExecuteChanged (object sender, EventArgs e)
3499
{
35100
if (sender is ICommand cmd)
36-
this.Enabled = cmd.CanExecute (null);
101+
Enabled = cmd.CanExecute (null);
102+
}
103+
104+
private void NotifyMouseEntered ()
105+
{
106+
OnMouseEntered?.Invoke (this, EventArgs.Empty);
107+
}
108+
109+
private void NotifyMouseExited ()
110+
{
111+
OnMouseExited?.Invoke (this, EventArgs.Empty);
112+
}
113+
114+
private void NotifyMouseLeftDown ()
115+
{
116+
ExecuteCommand (this, EventArgs.Empty);
117+
OnMouseLeftDown?.Invoke (this, EventArgs.Empty);
118+
this.commandFired = true;
119+
}
120+
121+
private void NotifyMouseRightDown ()
122+
{
123+
OnMouseRightDown?.Invoke (this, EventArgs.Empty);
124+
}
125+
#endregion
126+
}
127+
128+
internal class FocusableCommandButton : CommandButton
129+
{
130+
public override bool CanBecomeKeyView { get { return Enabled; } }
131+
132+
public FocusableCommandButton ()
133+
{
134+
AllowsExpansionToolTips = true;
135+
AllowsMixedState = true;
136+
Cell.LineBreakMode = NSLineBreakMode.TruncatingTail;
137+
Cell.UsesSingleLineMode = true;
138+
ControlSize = NSControlSize.Small;
139+
Font = NSFont.SystemFontOfSize (NSFont.SystemFontSizeForControlSize (NSControlSize.Small));
140+
Title = string.Empty;
141+
TranslatesAutoresizingMaskIntoConstraints = false;
142+
}
143+
144+
public override bool BecomeFirstResponder ()
145+
{
146+
var willBecomeFirstResponder = base.BecomeFirstResponder ();
147+
if (willBecomeFirstResponder) {
148+
ScrollRectToVisible (Bounds);
149+
}
150+
return willBecomeFirstResponder;
37151
}
38152
}
39153
}

Xamarin.PropertyEditing.Mac/Controls/Custom/DrawingExtensions.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,5 +116,33 @@ public static CommonColor UpdateCMYK (
116116
k: k ?? color.K,
117117
alpha: alpha ?? color.A);
118118
}
119+
120+
public static CGPath ToCGPath (this NSBezierPath nsPath)
121+
{
122+
var cgPath = new CGPath ();
123+
for (var i = 0; i < nsPath.ElementCount; i++) {
124+
NSBezierPathElement type = nsPath.ElementAt (i, out CGPoint[] points);
125+
126+
switch (type) {
127+
case NSBezierPathElement.ClosePath:
128+
cgPath.CloseSubpath ();
129+
break;
130+
131+
case NSBezierPathElement.CurveTo:
132+
cgPath.AddCurveToPoint (points[0], points[1], points[2]);
133+
break;
134+
135+
case NSBezierPathElement.LineTo:
136+
cgPath.AddLineToPoint (points[0]);
137+
break;
138+
139+
case NSBezierPathElement.MoveTo:
140+
cgPath.MoveToPoint (points[0]);
141+
break;
142+
}
143+
}
144+
145+
return cgPath;
146+
}
119147
}
120148
}

0 commit comments

Comments
 (0)