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

Commit

Permalink
[Mac] Initial Variations Implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominique Louis authored and CartBlanche committed Sep 26, 2019
1 parent 0525c4d commit 1f9c340
Show file tree
Hide file tree
Showing 57 changed files with 1,096 additions and 200 deletions.
8 changes: 5 additions & 3 deletions Xamarin.PropertyEditing.Mac/Controls/BasePathEditorControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ internal abstract class BasePathEditorControl<T> : PropertyEditorControl<Propert
protected BasePathEditorControl (IHostResourceProvider hostResource)
: base (hostResource)
{
this.currentTextField = new TextFieldSmallButtonContainer ();
this.currentTextField = new TextFieldSmallButtonContainer {
ControlSize = NSControlSize.Small,
Font = NSFont.SystemFontOfSize (NSFont.SystemFontSizeForControlSize (NSControlSize.Small)),
};
this.currentTextField.Changed += CurrentTextField_Changed;
AddSubview (this.currentTextField);

Expand Down Expand Up @@ -78,9 +81,8 @@ protected BasePathEditorControl (IHostResourceProvider hostResource)

AddConstraints (new[] {
NSLayoutConstraint.Create (this.currentTextField, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1, 0f),
NSLayoutConstraint.Create (this.currentTextField, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1, 0f),
NSLayoutConstraint.Create (this.currentTextField, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, this, NSLayoutAttribute.Bottom, 1, -2f),
NSLayoutConstraint.Create (this.currentTextField, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1, 0f),
NSLayoutConstraint.Create (this.currentTextField, NSLayoutAttribute.Height, NSLayoutRelation.Equal, this, NSLayoutAttribute.Height, 1, -6f),
});
}

Expand Down
23 changes: 13 additions & 10 deletions Xamarin.PropertyEditing.Mac/Controls/BasePointEditorControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,21 @@ protected BasePointEditorControl (IHostResourceProvider hostResources)
AddSubview (YLabel);
AddSubview (YEditor);

const float editorHeight = 18;
this.AddConstraints (new[] {
NSLayoutConstraint.Create (XEditor, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 3f),
nfloat labelHeight = NSFont.SystemFontSizeForControlSize (NSControlSize.Small);
AddConstraints (new[] {
NSLayoutConstraint.Create (XLabel, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, this, NSLayoutAttribute.Bottom, 1f, BottomOffset + 1),
NSLayoutConstraint.Create (XLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, labelHeight),

NSLayoutConstraint.Create (XEditor, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, XLabel, NSLayoutAttribute.Top, 1f, -1f),
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.Bottom, NSLayoutRelation.Equal, YLabel, NSLayoutAttribute.Top, 1f, -1f),
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 (YLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, labelHeight),

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),
Expand Down Expand Up @@ -98,5 +96,10 @@ protected override void AppearanceChanged ()
XLabel.TextColor = HostResources.GetNamedColor (NamedResources.DescriptionLabelColor);
YLabel.TextColor = HostResources.GetNamedColor (NamedResources.DescriptionLabelColor);
}

public override nint GetHeight (EditorViewModel vm)
{
return 33;
}
}
}
54 changes: 28 additions & 26 deletions Xamarin.PropertyEditing.Mac/Controls/BaseRectangleEditorControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,44 +74,41 @@ protected BaseRectangleEditorControl (IHostResourceProvider hostResources)
AddSubview (HeightLabel);
AddSubview (HeightEditor);

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, 18),

NSLayoutConstraint.Create (XLabel, NSLayoutAttribute.Top, NSLayoutRelation.Equal, XEditor, NSLayoutAttribute.Bottom, 1f, -4f),
NSLayoutConstraint.Create (XLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 18),

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, 18),

NSLayoutConstraint.Create (YLabel, NSLayoutAttribute.Top, NSLayoutRelation.Equal, XLabel, NSLayoutAttribute.Top, 1f, 0f),
NSLayoutConstraint.Create (YLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 18),
nfloat labelHeight = NSFont.SystemFontSizeForControlSize (NSControlSize.Small);
AddConstraints (new[] {
NSLayoutConstraint.Create (WidthLabel, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, this, NSLayoutAttribute.Bottom, 1f, BottomOffset + 1),
NSLayoutConstraint.Create (WidthLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, labelHeight),

NSLayoutConstraint.Create (WidthEditor, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 33f),
NSLayoutConstraint.Create (WidthEditor, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, WidthLabel, NSLayoutAttribute.Top, 1f, -1f),
NSLayoutConstraint.Create (WidthEditor, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, 0f),
NSLayoutConstraint.Create (WidthEditor, NSLayoutAttribute.Right, NSLayoutRelation.Equal, HeightEditor, NSLayoutAttribute.Left, 1f, -10f),
NSLayoutConstraint.Create (WidthEditor, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 18),

NSLayoutConstraint.Create (WidthLabel, NSLayoutAttribute.Top, NSLayoutRelation.Equal, WidthEditor, NSLayoutAttribute.Bottom, 1f, -4f),
NSLayoutConstraint.Create (WidthLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 18),

NSLayoutConstraint.Create (HeightEditor, NSLayoutAttribute.Top, NSLayoutRelation.Equal, WidthEditor, NSLayoutAttribute.Top, 1f, 0f),
NSLayoutConstraint.Create (HeightEditor, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, HeightLabel, NSLayoutAttribute.Top, 1f, -1f),
NSLayoutConstraint.Create (HeightEditor, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this, NSLayoutAttribute.Right, 1f, 0),
NSLayoutConstraint.Create (HeightEditor, NSLayoutAttribute.Width, NSLayoutRelation.Equal, WidthEditor, NSLayoutAttribute.Width, 1f, 0f),
NSLayoutConstraint.Create (HeightEditor, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 18),

NSLayoutConstraint.Create (HeightLabel, NSLayoutAttribute.Top, NSLayoutRelation.Equal, WidthLabel, NSLayoutAttribute.Top, 1f, 0f),
NSLayoutConstraint.Create (HeightLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 18),
NSLayoutConstraint.Create (HeightLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, labelHeight),

NSLayoutConstraint.Create (WidthLabel, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, WidthEditor.Subviews[0], NSLayoutAttribute.CenterX, 1f, 0),
NSLayoutConstraint.Create (HeightLabel, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, HeightEditor.Subviews[0], NSLayoutAttribute.CenterX, 1f, 0),

NSLayoutConstraint.Create (XLabel, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, WidthEditor, NSLayoutAttribute.Top, 1f, 0f),
NSLayoutConstraint.Create (XLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, labelHeight),

NSLayoutConstraint.Create (XEditor, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, XLabel, NSLayoutAttribute.Top, 1f, -1f),
NSLayoutConstraint.Create (XEditor, NSLayoutAttribute.Left, NSLayoutRelation.Equal, WidthEditor, NSLayoutAttribute.Left, 1f, 0f),
NSLayoutConstraint.Create (XEditor, NSLayoutAttribute.Right, NSLayoutRelation.Equal, YEditor, NSLayoutAttribute.Left, 1f, -10f),

NSLayoutConstraint.Create (YLabel, NSLayoutAttribute.Top, NSLayoutRelation.Equal, XLabel, NSLayoutAttribute.Top, 1f, 0f),
NSLayoutConstraint.Create (YLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, labelHeight),

NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Top, NSLayoutRelation.Equal, XEditor, NSLayoutAttribute.Top, 1f, 0f),
NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Right, NSLayoutRelation.Equal, HeightEditor, NSLayoutAttribute.Right, 1f, 0),
NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Width, NSLayoutRelation.Equal, XEditor, NSLayoutAttribute.Width, 1f, 0f),

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),
NSLayoutConstraint.Create (WidthLabel, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, WidthEditor.Subviews[0], NSLayoutAttribute.CenterX, 1f, 0),
NSLayoutConstraint.Create (HeightLabel, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, HeightEditor.Subviews[0], NSLayoutAttribute.CenterX, 1f, 0),
});

AppearanceChanged ();
Expand Down Expand Up @@ -154,5 +151,10 @@ protected override void AppearanceChanged ()
WidthLabel.TextColor = HostResources.GetNamedColor (NamedResources.DescriptionLabelColor);
HeightLabel.TextColor = HostResources.GetNamedColor (NamedResources.DescriptionLabelColor);
}

public override nint GetHeight (EditorViewModel vm)
{
return 66;
}
}
}
6 changes: 2 additions & 4 deletions Xamarin.PropertyEditing.Mac/Controls/BooleanEditorControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ namespace Xamarin.PropertyEditing.Mac
internal class BooleanEditorControl
: PropertyEditorControl<PropertyViewModel<bool?>>
{
const string setBezelColorSelector = "setBezelColor:";

public BooleanEditorControl (IHostResourceProvider hostResource)
: base (hostResource)
{
Expand All @@ -29,8 +27,8 @@ public BooleanEditorControl (IHostResourceProvider hostResource)

AddSubview (BooleanEditor);

this.AddConstraints (new[] {
NSLayoutConstraint.Create (BooleanEditor, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1f, 0f),
AddConstraints (new[] {
NSLayoutConstraint.Create (BooleanEditor, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, this, NSLayoutAttribute.Bottom, 1f, -4f),
NSLayoutConstraint.Create (BooleanEditor, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, 0f),
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,11 @@ public CollectionInlineEditorControl (IHostResourceProvider hostResources)

AddConstraints (new[] {
NSLayoutConstraint.Create (this.label, NSLayoutAttribute.Leading, NSLayoutRelation.Equal, this, NSLayoutAttribute.Leading, 1, 0),
NSLayoutConstraint.Create (this.label, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1, 0),
NSLayoutConstraint.Create (this.label, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this.openCollection, NSLayoutAttribute.CenterY, 1, 0),
NSLayoutConstraint.Create (this.label, NSLayoutAttribute.Height, NSLayoutRelation.Equal, this, NSLayoutAttribute.Height, 1, 0),
NSLayoutConstraint.Create (this.openCollection, NSLayoutAttribute.Leading, NSLayoutRelation.Equal, this.label, NSLayoutAttribute.Trailing, 1, 12),
NSLayoutConstraint.Create (this.openCollection, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1, 0),
NSLayoutConstraint.Create (this.openCollection, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, this, NSLayoutAttribute.Bottom, 1, -2),
NSLayoutConstraint.Create (this.openCollection, NSLayoutAttribute.Width, NSLayoutRelation.GreaterThanOrEqual, 1, 70),
NSLayoutConstraint.Create (this.openCollection, NSLayoutAttribute.Height, NSLayoutRelation.Equal, this, NSLayoutAttribute.Height, 1, -6)
});

AppearanceChanged ();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ public CombinablePropertyEditor (IHostResourceProvider hostResources)
public override nint GetHeight (EditorViewModel vm)
{
var realVm = (CombinablePropertyViewModel<T>)vm;
return subrowHeight * realVm.Choices.Count + 6;
nint baseHeight = subrowHeight * realVm.Choices.Count + 6;
if (realVm != null && realVm.IsVariant) {
return (baseHeight * 2);
}

return baseHeight;
}

protected override void SetEnabled ()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using AppKit;
using Xamarin.PropertyEditing.ViewModels;

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

public AutoClosePopOver PopOver { get; internal set; }

public BasePopOverViewModelControl (IHostResourceProvider hostResources, PropertyViewModel viewModel, string title, string imageNamed)
: base (hostResources, title, imageNamed)
{
Expand Down
124 changes: 119 additions & 5 deletions Xamarin.PropertyEditing.Mac/Controls/Custom/CommandButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ internal class CommandButton : NSButton
{
private ICommand command;

public event EventHandler OnMouseEntered;
public event EventHandler OnMouseExited;
public event EventHandler OnMouseLeftDown;
public event EventHandler OnMouseRightDown;

private NSTrackingArea trackingArea;
private bool commandFired;

public ICommand Command
{
get { return this.command; }
Expand All @@ -24,16 +32,122 @@ public ICommand Command

public CommandButton ()
{
Activated += (object sender, EventArgs e) => {
var button = (CommandButton)sender;
button.command?.Execute (null);
};
Activated += ExecuteCommand;
}

private void ExecuteCommand (object sender, EventArgs e)
{
if (Enabled && !this.commandFired) {
this.command?.Execute (null);
return;
}
this.commandFired = false;
}

#region Overridden Methods

public override void MouseDown (NSEvent theEvent)
{
if (Enabled) {
switch (theEvent.Type) {
case NSEventType.LeftMouseDown:
NotifyMouseLeftDown ();
break;

case NSEventType.RightMouseDown:
NotifyMouseRightDown ();
break;
}
base.MouseDown (theEvent);
}
}

public override void MouseEntered (NSEvent theEvent)
{
if (Enabled) {
NotifyMouseEntered ();
base.MouseEntered (theEvent);
}
}

public override void MouseExited (NSEvent theEvent)
{
if (Enabled) {
NotifyMouseExited ();
base.MouseExited (theEvent);
}
}

public override void UpdateTrackingAreas ()
{
base.UpdateTrackingAreas ();

// Add tracking so our MouseEntered and MouseExited get called.
if (this.trackingArea == null) {
NSTrackingAreaOptions options = NSTrackingAreaOptions.MouseEnteredAndExited | NSTrackingAreaOptions.ActiveAlways;

this.trackingArea = new NSTrackingArea (Bounds, options, this, null);

AddTrackingArea (this.trackingArea);
}
}
#endregion


#region Local Methods
private void CanExecuteChanged (object sender, EventArgs e)
{
if (sender is ICommand cmd)
this.Enabled = cmd.CanExecute (null);
Enabled = cmd.CanExecute (null);
}

private void NotifyMouseEntered ()
{
OnMouseEntered?.Invoke (this, EventArgs.Empty);
}

private void NotifyMouseExited ()
{
OnMouseExited?.Invoke (this, EventArgs.Empty);
}

private void NotifyMouseLeftDown ()
{
ExecuteCommand (this, EventArgs.Empty);
OnMouseLeftDown?.Invoke (this, EventArgs.Empty);
this.commandFired = true;
}

private void NotifyMouseRightDown ()
{
OnMouseRightDown?.Invoke (this, EventArgs.Empty);
}
#endregion
}

internal class FocusableCommandButton : CommandButton
{
public override bool CanBecomeKeyView { get { return Enabled; } }

public FocusableCommandButton ()
{
AllowsExpansionToolTips = true;
AllowsMixedState = true;
Cell.LineBreakMode = NSLineBreakMode.TruncatingTail;
Cell.UsesSingleLineMode = true;
ControlSize = NSControlSize.Small;
Font = NSFont.SystemFontOfSize (NSFont.SystemFontSizeForControlSize (NSControlSize.Small));
Title = string.Empty;
TranslatesAutoresizingMaskIntoConstraints = false;
}

public override bool BecomeFirstResponder ()
{
var willBecomeFirstResponder = base.BecomeFirstResponder ();
if (willBecomeFirstResponder) {
ScrollRectToVisible (Bounds);
}
return willBecomeFirstResponder;
}
}
}
28 changes: 28 additions & 0 deletions Xamarin.PropertyEditing.Mac/Controls/Custom/DrawingExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,33 @@ public static CommonColor UpdateCMYK (
k: k ?? color.K,
alpha: alpha ?? color.A);
}

public static CGPath ToCGPath (this NSBezierPath nsPath)
{
var cgPath = new CGPath ();
for (var i = 0; i < nsPath.ElementCount; i++) {
NSBezierPathElement type = nsPath.ElementAt (i, out CGPoint[] points);

switch (type) {
case NSBezierPathElement.ClosePath:
cgPath.CloseSubpath ();
break;

case NSBezierPathElement.CurveTo:
cgPath.AddCurveToPoint (points[0], points[1], points[2]);
break;

case NSBezierPathElement.LineTo:
cgPath.AddLineToPoint (points[0]);
break;

case NSBezierPathElement.MoveTo:
cgPath.MoveToPoint (points[0]);
break;
}
}

return cgPath;
}
}
}
Loading

0 comments on commit 1f9c340

Please sign in to comment.