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 Oct 8, 2019
1 parent bf4235a commit db2d949
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal abstract class BasePointEditorControl<T> : PropertyEditorControl<Proper
public override NSView FirstKeyView => XEditor;
public override NSView LastKeyView => YEditor.DecrementButton;

protected override nint BaseHeight => 33;
protected override nint BaseHeight => 36;

protected BasePointEditorControl (IHostResourceProvider hostResources)
: base (hostResources)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal abstract class BaseRectangleEditorControl<T> : PropertyEditorControl<Pr
public override NSView FirstKeyView => XEditor;
public override NSView LastKeyView => HeightEditor.DecrementButton;

protected override nint BaseHeight => 66;
protected override nint BaseHeight => 68;

protected BaseRectangleEditorControl (IHostResourceProvider hostResources)
: base (hostResources)
Expand Down
84 changes: 46 additions & 38 deletions Xamarin.PropertyEditing.Mac/Controls/EditorContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public EditorContainer (IHostResourceProvider hostResources, IEditorView editorV
}

private const string FrameChangedObservableProperty = "frame";
private readonly NSString observerKeyPath = new NSString (FrameChangedObservableProperty);

public IEditorView EditorView => (IEditorView)NativeContainer;

Expand Down Expand Up @@ -131,62 +132,63 @@ private void UpdateVariations ()
if (this.viewModelAsPropertyViewModel.HasVariations) {

if (this.viewModelAsPropertyViewModel.IsVariant) {
this.deleteVariantButton = new VariationButton (HostResources, "pe-variation-delete-button-active-mac-10", "pe-variation-delete-button-mac-10") {
AccessibilityEnabled = true,
AccessibilityTitle = Properties.Resources.AccessibilityDeleteVariationButton,
Command = this.viewModelAsPropertyViewModel.RemoveVariationCommand,
ToolTip = Properties.Resources.RemoveVariant,
TranslatesAutoresizingMaskIntoConstraints = false,
};

if (this.deleteVariantButton == null) {
this.deleteVariantButton = new VariationButton (HostResources, "pe-variation-delete-button-active-mac-10", "pe-variation-delete-button-mac-10") {
AccessibilityEnabled = true,
AccessibilityTitle = Properties.Resources.AccessibilityDeleteVariationButton,
Command = this.viewModelAsPropertyViewModel.RemoveVariationCommand,
ToolTip = Properties.Resources.RemoveVariant,
TranslatesAutoresizingMaskIntoConstraints = false,
};
AddSubview (this.deleteVariantButton);
AddConstraints (new[] {
NSLayoutConstraint.Create (this.deleteVariantButton, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 8f),
NSLayoutConstraint.Create (this.deleteVariantButton, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, 20f),
});

AddSubview (this.deleteVariantButton);
AddConstraints (new[] {
NSLayoutConstraint.Create (this.deleteVariantButton, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 8f),
NSLayoutConstraint.Create (this.deleteVariantButton, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, 20f),
});
this.variationControlsList.Add (this.deleteVariantButton);

this.variationControlsList.Add (this.deleteVariantButton);
// Hook into the delete button's frame change, so we can fire off some drawing. If there's a better way, let me know.
this.deleteVariantButton.AddObserver (this, this.observerKeyPath, NSKeyValueObservingOptions.New, IntPtr.Zero);

// Hook into the delete button's frame change, so we can fire off some drawing. If there's a better way, let me know.
this.deleteVariantButton.AddObserver (this, new NSString (FrameChangedObservableProperty), NSKeyValueObservingOptions.New, IntPtr.Zero);
}
NextKeyView = this.deleteVariantButton;

// Cache these before the loop
var variationBgColour = HostResources.GetNamedColor (NamedResources.FrameBoxButtonBackgroundColor);

NSView previousControl = this.deleteVariantButton;
foreach (PropertyVariationOption item in this.viewModelAsPropertyViewModel.Variation) {
var selectedVariationTextField = new UnfocusableTextField {
BackgroundColor = HostResources.GetNamedColor (NamedResources.FrameBoxButtonBackgroundColor),
var selectedVariationTextField = new UnfocusableTextField {
BackgroundColor = variationBgColour,
Bordered = false,
Font = NSFont.SystemFontOfSize (NSFont.SystemFontSizeForControlSize (NSControlSize.Small) - 1f),
Font = VariationOptionFont,
TranslatesAutoresizingMaskIntoConstraints = false,
StringValue = string.Format (" {0}: {1} ", item.Category, item.Name),
};

AddSubview (selectedVariationTextField);
AddConstraints (new[] {
NSLayoutConstraint.Create (selectedVariationTextField, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 5f),
AddConstraints (new[] {
NSLayoutConstraint.Create (selectedVariationTextField, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, VariationBorderOffset),
NSLayoutConstraint.Create (selectedVariationTextField, NSLayoutAttribute.Left, NSLayoutRelation.Equal, previousControl, NSLayoutAttribute.Right, 1f, 6f),
NSLayoutConstraint.Create (selectedVariationTextField, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 16f),
});

previousControl = selectedVariationTextField;
this.variationControlsList.Add (selectedVariationTextField);
}
} else {
if (this.addVariantButton == null) {
this.addVariantButton = new VariationButton (HostResources, "pe-variation-add-button-active-mac-10", "pe-variation-add-button-mac-10") {
AccessibilityEnabled = true,
AccessibilityTitle = Properties.Resources.AccessibilityAddVariationButton,
Command = this.viewModelAsPropertyViewModel.RequestCreateVariantCommand,
ToolTip = Properties.Resources.AddVariant,
TranslatesAutoresizingMaskIntoConstraints = false,
};

LeftEdgeView = this.addVariantButton;

this.variationControlsList.Add (this.addVariantButton);
}
} else {
this.addVariantButton = new VariationButton (HostResources, "pe-variation-add-button-active-mac-10", "pe-variation-add-button-mac-10") {
AccessibilityEnabled = true,
AccessibilityTitle = Properties.Resources.AccessibilityAddVariationButton,
Command = this.viewModelAsPropertyViewModel.RequestCreateVariantCommand,
ToolTip = Properties.Resources.AddVariant,
TranslatesAutoresizingMaskIntoConstraints = false,
};

LeftEdgeView = this.addVariantButton;
NextKeyView = this.addVariantButton;

this.variationControlsList.Add (this.addVariantButton);
}
}
}
Expand All @@ -201,7 +203,11 @@ private void ClearSubViews ()
this.variationControlsList.Clear ();

this.addVariantButton = null;
this.deleteVariantButton = null;

if (this.deleteVariantButton != null) {
this.deleteVariantButton.RemoveObserver (this, this.observerKeyPath);
this.deleteVariantButton = null;
}
}

private void ClearChildLayers ()
Expand Down Expand Up @@ -315,8 +321,10 @@ public NSColor LabelTextColor {
private VariationButton addVariantButton;
private const float treeLineLeftEdge = 14f;
private const float treeLineLeafIndent = 4f;
internal const float VariationBorderOffset = 5f;
internal static NSFont VariationOptionFont = NSFont.SystemFontOfSize (NSFont.SystemFontSizeForControlSize (NSControlSize.Small) - 1f);
private nfloat ViewVariationChildVerticalDrawPoint => this.deleteVariantButton.Frame.Top + 5;
private nfloat ViewVariationParentVerticalDrawPoint => this.addVariantButton.Frame.Top - 2;
private PropertyViewModel viewModelAsPropertyViewModel;
}
}
}
2 changes: 0 additions & 2 deletions Xamarin.PropertyEditing.Mac/Controls/PointEditorControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ namespace Xamarin.PropertyEditing.Mac
{
internal abstract class PointEditorControl<T> : BasePointEditorControl<T>
{
protected override float HeightScaleFactor => 1.8f;

public PointEditorControl (IHostResourceProvider hostResources)
: base (hostResources)
{
Expand Down
15 changes: 7 additions & 8 deletions Xamarin.PropertyEditing.Mac/Controls/PropertyEditorControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,12 @@ public IHostResourceProvider HostResources
public virtual bool IsDynamicallySized => false;
public const float BottomOffset = -2f;
protected virtual nint BaseHeight => 24;
protected virtual float HeightScaleFactor => 2.0f;

PropertyViewModel viewModel;
public PropertyViewModel ViewModel {
get { return this.viewModel; }
set {
if (this.ViewModel == value)
if (this.viewModel == value)
return;

PropertyViewModel oldModel = this.viewModel;
Expand Down Expand Up @@ -93,11 +92,11 @@ public void UpdateKeyViews ()
} while (row > 0 && ctrl == null);

if (ctrl != null) {
VariationButton vb = Superview.Subviews.OfType<VariationButton> ().FirstOrDefault ();
if (vb != null) {
vb.NextKeyView = FirstKeyView;
ctrl.LastKeyView.NextKeyView = vb;
} else {
if (Superview is EditorContainer editorContainer && editorContainer.NextKeyView != null) {
editorContainer.NextKeyView.NextKeyView = FirstKeyView;
ctrl.LastKeyView.NextKeyView = editorContainer.NextKeyView;
}
else {
ctrl.LastKeyView.NextKeyView = FirstKeyView;
}
ctrl.UpdateKeyViews ();
Expand All @@ -110,7 +109,7 @@ public void UpdateKeyViews ()
public virtual nint GetHeight (EditorViewModel vm)
{
if (vm is PropertyViewModel realVm && realVm.IsVariant) {
return (nint)(BaseHeight * HeightScaleFactor);
return (nint)(BaseHeight + EditorContainer.VariationOptionFont.BoundingRectForFont.Height + (EditorContainer.VariationBorderOffset * 2)); // * 2 for upper and lower borders
}

return BaseHeight;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ namespace Xamarin.PropertyEditing.Mac
internal abstract class RectangleEditorControl<T>
: BaseRectangleEditorControl<T>
{
protected override float HeightScaleFactor => 1.4f;

protected RectangleEditorControl (IHostResourceProvider hostResources)
: base (hostResources)
{
Expand Down

0 comments on commit db2d949

Please sign in to comment.