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 Dec 12, 2019
1 parent e619ba4 commit 38f7796
Show file tree
Hide file tree
Showing 64 changed files with 1,019 additions and 196 deletions.
10 changes: 6 additions & 4 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 @@ -72,9 +75,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 Expand Up @@ -113,7 +115,7 @@ protected override void SetEnabled ()
{
this.currentTextField.Enabled =
this.browsePathButton.Enabled =
this.revealPathButton.Enabled = ViewModel.Property.CanWrite;
this.revealPathButton.Enabled = ViewModel.IsInputEnabled;
}

protected override void Dispose (bool disposing)
Expand Down
24 changes: 12 additions & 12 deletions Xamarin.PropertyEditing.Mac/Controls/BasePointEditorControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ internal abstract class BasePointEditorControl<T> : PropertyEditorControl<Proper
public override NSView FirstKeyView => XEditor;
public override NSView LastKeyView => YEditor.DecrementButton;

protected override nint BaseHeight => 36;

protected BasePointEditorControl (IHostResourceProvider hostResources)
: base (hostResources)
{
Expand Down Expand Up @@ -46,23 +48,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 All @@ -73,8 +73,8 @@ protected BasePointEditorControl (IHostResourceProvider hostResources)

protected override void SetEnabled ()
{
XEditor.Enabled = ViewModel.Property.CanWrite;
YEditor.Enabled = ViewModel.Property.CanWrite;
XEditor.Enabled =
YEditor.Enabled = ViewModel.IsInputEnabled;
}

protected override void UpdateAccessibilityValues ()
Expand Down
59 changes: 29 additions & 30 deletions Xamarin.PropertyEditing.Mac/Controls/BaseRectangleEditorControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ internal abstract class BaseRectangleEditorControl<T> : PropertyEditorControl<Pr
public override NSView FirstKeyView => XEditor;
public override NSView LastKeyView => HeightEditor.DecrementButton;

protected override nint BaseHeight => 68;

protected BaseRectangleEditorControl (IHostResourceProvider hostResources)
: base (hostResources)
{
Expand Down Expand Up @@ -74,44 +76,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 All @@ -124,10 +123,10 @@ protected virtual void OnInputUpdated (object sender, EventArgs e)

protected override void SetEnabled ()
{
XEditor.Enabled = ViewModel.Property.CanWrite;
YEditor.Enabled = ViewModel.Property.CanWrite;
WidthEditor.Enabled = ViewModel.Property.CanWrite;
HeightEditor.Enabled = ViewModel.Property.CanWrite;
XEditor.Enabled =
YEditor.Enabled =
WidthEditor.Enabled =
HeightEditor.Enabled = ViewModel.IsInputEnabled;
}

protected override void UpdateAccessibilityValues ()
Expand Down
8 changes: 3 additions & 5 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 Expand Up @@ -60,7 +58,7 @@ protected override void UpdateValue ()

protected override void SetEnabled ()
{
BooleanEditor.Enabled = ViewModel.Property.CanWrite;
BooleanEditor.Enabled = ViewModel.IsInputEnabled;
}

protected override void UpdateAccessibilityValues ()
Expand Down
6 changes: 3 additions & 3 deletions Xamarin.PropertyEditing.Mac/Controls/BrushEditorControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public BrushEditorControl (IHostResourceProvider hostResources)

AddSubview (this.popUpButton);

this.AddConstraints (new[] {
AddConstraints (new[] {
NSLayoutConstraint.Create (this.popUpButton, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, 0),
NSLayoutConstraint.Create (this.popUpButton, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 16),
NSLayoutConstraint.Create (this.popUpButton, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1f, 0),
Expand All @@ -84,7 +84,7 @@ public BrushEditorControl (IHostResourceProvider hostResources)

protected override void SetEnabled ()
{
this.popUpButton.Enabled = this.ViewModel?.Property.CanWrite ?? false;
this.popUpButton.Enabled = ViewModel?.IsInputEnabled ?? false;
}

string GetTitle ()
Expand All @@ -109,7 +109,7 @@ string GetTitle ()
protected override void UpdateValue ()
{
this.brushTabViewController.ViewModel = ViewModel;
this.popUpButton.Popover = (ViewModel?.Property.CanWrite ?? false) ? this.popover : null;
this.popUpButton.Popover = (ViewModel?.IsInputEnabled ?? false) ? this.popover : null;

if (ViewModel.Solid != null) {
var title = GetTitle ();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public CollectionInlineEditorControl (IHostResourceProvider hostResources)
protected override void SetEnabled ()
{
base.SetEnabled ();
this.openCollection.Enabled = ViewModel?.Property.CanWrite ?? false;
this.openCollection.Enabled = ViewModel?.IsInputEnabled ?? false;
}

protected override void UpdateAccessibilityValues ()
Expand Down
11 changes: 8 additions & 3 deletions Xamarin.PropertyEditing.Mac/Controls/CombinablePropertyEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,18 @@ 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 ()
{
foreach (var item in this.combinableList) {
item.Key.Enabled = ViewModel.Property.CanWrite;
item.Key.Enabled = ViewModel.IsInputEnabled;
}
}

Expand Down Expand Up @@ -66,7 +71,7 @@ protected override void OnViewModelChanged (PropertyViewModel oldModel)

AddSubview (checkbox);

this.AddConstraints (new[] {
AddConstraints (new[] {
NSLayoutConstraint.Create (checkbox, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, top),
NSLayoutConstraint.Create (checkbox, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, 0f),
NSLayoutConstraint.Create (checkbox, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, 0),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public BasePopOverControl (IHostResourceProvider hostResources, string title, st

AddSubview (this.viewTitle);

this.AddConstraints (new[] {
AddConstraints (new[] {
NSLayoutConstraint.Create (iconView, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 5f),
NSLayoutConstraint.Create (iconView, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, 5f),
NSLayoutConstraint.Create (iconView, NSLayoutAttribute.Width, NSLayoutRelation.Equal, 1f, DefaultIconButtonSize),
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
Loading

0 comments on commit 38f7796

Please sign in to comment.