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

Commit 3b6b044

Browse files
Dominique LouisCartBlanche
Dominique Louis
authored andcommittedOct 7, 2019
[Mac] Initial Variations Implementation
1 parent bf4235a commit 3b6b044

6 files changed

+15
-15
lines changed
 

‎Xamarin.PropertyEditing.Mac/Controls/BasePointEditorControl.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ internal abstract class BasePointEditorControl<T> : PropertyEditorControl<Proper
1616
public override NSView FirstKeyView => XEditor;
1717
public override NSView LastKeyView => YEditor.DecrementButton;
1818

19-
protected override nint BaseHeight => 33;
19+
protected override nint BaseHeight => 36;
2020

2121
protected BasePointEditorControl (IHostResourceProvider hostResources)
2222
: base (hostResources)

‎Xamarin.PropertyEditing.Mac/Controls/BaseRectangleEditorControl.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ internal abstract class BaseRectangleEditorControl<T> : PropertyEditorControl<Pr
2222
public override NSView FirstKeyView => XEditor;
2323
public override NSView LastKeyView => HeightEditor.DecrementButton;
2424

25-
protected override nint BaseHeight => 66;
25+
protected override nint BaseHeight => 68;
2626

2727
protected BaseRectangleEditorControl (IHostResourceProvider hostResources)
2828
: base (hostResources)

‎Xamarin.PropertyEditing.Mac/Controls/EditorContainer.cs

+11-6
Original file line numberDiff line numberDiff line change
@@ -151,21 +151,24 @@ private void UpdateVariations ()
151151

152152
// Hook into the delete button's frame change, so we can fire off some drawing. If there's a better way, let me know.
153153
this.deleteVariantButton.AddObserver (this, new NSString (FrameChangedObservableProperty), NSKeyValueObservingOptions.New, IntPtr.Zero);
154-
}
154+
}
155+
156+
// Cache these before the loop
157+
var variationBgColour = HostResources.GetNamedColor (NamedResources.FrameBoxButtonBackgroundColor);
155158

156159
NSView previousControl = this.deleteVariantButton;
157160
foreach (PropertyVariationOption item in this.viewModelAsPropertyViewModel.Variation) {
158-
var selectedVariationTextField = new UnfocusableTextField {
159-
BackgroundColor = HostResources.GetNamedColor (NamedResources.FrameBoxButtonBackgroundColor),
161+
var selectedVariationTextField = new UnfocusableTextField {
162+
BackgroundColor = variationBgColour,
160163
Bordered = false,
161-
Font = NSFont.SystemFontOfSize (NSFont.SystemFontSizeForControlSize (NSControlSize.Small) - 1f),
164+
Font = VariationOptionFont,
162165
TranslatesAutoresizingMaskIntoConstraints = false,
163166
StringValue = string.Format (" {0}: {1} ", item.Category, item.Name),
164167
};
165168

166169
AddSubview (selectedVariationTextField);
167-
AddConstraints (new[] {
168-
NSLayoutConstraint.Create (selectedVariationTextField, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 5f),
170+
AddConstraints (new[] {
171+
NSLayoutConstraint.Create (selectedVariationTextField, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, VariationBorderOffset),
169172
NSLayoutConstraint.Create (selectedVariationTextField, NSLayoutAttribute.Left, NSLayoutRelation.Equal, previousControl, NSLayoutAttribute.Right, 1f, 6f),
170173
NSLayoutConstraint.Create (selectedVariationTextField, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 16f),
171174
});
@@ -315,6 +318,8 @@ public NSColor LabelTextColor {
315318
private VariationButton addVariantButton;
316319
private const float treeLineLeftEdge = 14f;
317320
private const float treeLineLeafIndent = 4f;
321+
internal const float VariationBorderOffset = 5f;
322+
internal static NSFont VariationOptionFont = NSFont.SystemFontOfSize (NSFont.SystemFontSizeForControlSize (NSControlSize.Small) - 1f);
318323
private nfloat ViewVariationChildVerticalDrawPoint => this.deleteVariantButton.Frame.Top + 5;
319324
private nfloat ViewVariationParentVerticalDrawPoint => this.addVariantButton.Frame.Top - 2;
320325
private PropertyViewModel viewModelAsPropertyViewModel;

‎Xamarin.PropertyEditing.Mac/Controls/PointEditorControl.cs

-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ namespace Xamarin.PropertyEditing.Mac
1010
{
1111
internal abstract class PointEditorControl<T> : BasePointEditorControl<T>
1212
{
13-
protected override float HeightScaleFactor => 1.8f;
14-
1513
public PointEditorControl (IHostResourceProvider hostResources)
1614
: base (hostResources)
1715
{

‎Xamarin.PropertyEditing.Mac/Controls/PropertyEditorControl.cs

+2-3
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,12 @@ public IHostResourceProvider HostResources
3737
public virtual bool IsDynamicallySized => false;
3838
public const float BottomOffset = -2f;
3939
protected virtual nint BaseHeight => 24;
40-
protected virtual float HeightScaleFactor => 2.0f;
4140

4241
PropertyViewModel viewModel;
4342
public PropertyViewModel ViewModel {
4443
get { return this.viewModel; }
4544
set {
46-
if (this.ViewModel == value)
45+
if (this.viewModel == value)
4746
return;
4847

4948
PropertyViewModel oldModel = this.viewModel;
@@ -110,7 +109,7 @@ public void UpdateKeyViews ()
110109
public virtual nint GetHeight (EditorViewModel vm)
111110
{
112111
if (vm is PropertyViewModel realVm && realVm.IsVariant) {
113-
return (nint)(BaseHeight * HeightScaleFactor);
112+
return (nint)(BaseHeight + EditorContainer.VariationOptionFont.BoundingRectForFont.Height + (EditorContainer.VariationBorderOffset * 2)); // * 2 for upper and lower borders
114113
}
115114

116115
return BaseHeight;

‎Xamarin.PropertyEditing.Mac/Controls/RectangleEditorControl.cs

-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ namespace Xamarin.PropertyEditing.Mac
1111
internal abstract class RectangleEditorControl<T>
1212
: BaseRectangleEditorControl<T>
1313
{
14-
protected override float HeightScaleFactor => 1.4f;
15-
1614
protected RectangleEditorControl (IHostResourceProvider hostResources)
1715
: base (hostResources)
1816
{

0 commit comments

Comments
 (0)