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

Commit 2eda0b6

Browse files
author
Eric Maupin
committed
[mac] Overhaul some layout
DefaultControlHeight had ended up everywhere with no real meaning attached to it, used in some places with manual offsets. It was never clear whether it was the row size or a control size. Given the design doesn't always have matching heights for controls, we should just do away with this illusion. Additionally each editor had a manual offset trying to account for the property button and associated spacing on the right and wasn't consistent between 32 or 33. We do away with all that by moving the property button into the EditorContainer with a new flag on IEditorView denoting whether we should have a property button or not. Now all editors should not concern themselves with right inset and match width fully. Unfortunately the design sometimes has inconsistent top/bottom insets that vary from 3/3 to 3.5/3.5. I'd like to make them consistent, so we can set them at the EditorContainer level but for now the best thing that can be done is inset on a per editor basis. This also attempts to address labels and sometimes the property button not being vertically centered on the first editors. Now, the label is CenterY on the FirstKeyView which should center it vertically against the topmost input. The property button is now also CenterYd to the label, so it similarlly should auto center against the first row of input. If this proves to be not flexible enough we can revisit. This also makes more controls consistent with a control size of Small and uses the system provided mechanism for making sure the font matches so it fits correctly. These new guidelines should be used: - Rows have a height of 24 - Editors should match width - Single-row editors should CenterY on the parent, match width -6 - Multi-row editors should inset appropriately at -3/-3 - We should avoid so many manually calculated offsets going forward
1 parent b6687a4 commit 2eda0b6

29 files changed

+212
-255
lines changed

Xamarin.PropertyEditing.Mac/Controls/BaseEditorControl.cs

Lines changed: 0 additions & 104 deletions
This file was deleted.

Xamarin.PropertyEditing.Mac/Controls/BasePointEditorControl.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,23 @@ protected BasePointEditorControl (IHostResourceProvider hostResources)
4747
AddSubview (YLabel);
4848
AddSubview (YEditor);
4949

50+
const float editorHeight = 18;
5051
this.AddConstraints (new[] {
51-
NSLayoutConstraint.Create (XEditor, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 0f),
52+
NSLayoutConstraint.Create (XEditor, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 3f),
5253
NSLayoutConstraint.Create (XEditor, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, 0f),
5354
NSLayoutConstraint.Create (XEditor, NSLayoutAttribute.Right, NSLayoutRelation.Equal, YEditor, NSLayoutAttribute.Left, 1f, -10f),
54-
NSLayoutConstraint.Create (XEditor, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, DefaultControlHeight),
55+
NSLayoutConstraint.Create (XEditor, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, editorHeight),
5556

5657
NSLayoutConstraint.Create (XLabel, NSLayoutAttribute.Top, NSLayoutRelation.Equal, XEditor, NSLayoutAttribute.Bottom, 1f, -4f),
57-
NSLayoutConstraint.Create (XLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, DefaultControlHeight),
58+
NSLayoutConstraint.Create (XLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, editorHeight),
5859

59-
NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 0f),
60-
NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this, NSLayoutAttribute.Right, 1f, -32f),
60+
NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 3f),
61+
NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this, NSLayoutAttribute.Right, 1f, 0),
6162
NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Width, NSLayoutRelation.Equal, XEditor, NSLayoutAttribute.Width, 1f, 0f),
62-
NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, DefaultControlHeight),
63+
NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, editorHeight),
6364

6465
NSLayoutConstraint.Create (YLabel, NSLayoutAttribute.Top, NSLayoutRelation.Equal, XLabel, NSLayoutAttribute.Top, 1f, 0f),
65-
NSLayoutConstraint.Create (YLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, DefaultControlHeight),
66+
NSLayoutConstraint.Create (YLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, editorHeight),
6667

6768
NSLayoutConstraint.Create (XLabel, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, XEditor.Subviews[0], NSLayoutAttribute.CenterX, 1f, 0),
6869
NSLayoutConstraint.Create (YLabel, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, YEditor.Subviews[0], NSLayoutAttribute.CenterX, 1f, 0),

Xamarin.PropertyEditing.Mac/Controls/BaseRectangleEditorControl.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,37 +76,37 @@ protected BaseRectangleEditorControl (IHostResourceProvider hostResources)
7676
AddSubview (HeightEditor);
7777

7878
this.AddConstraints (new[] {
79-
NSLayoutConstraint.Create (XEditor, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 0f),
79+
NSLayoutConstraint.Create (XEditor, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 3f),
8080
NSLayoutConstraint.Create (XEditor, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, 0f),
8181
NSLayoutConstraint.Create (XEditor, NSLayoutAttribute.Right, NSLayoutRelation.Equal, YEditor, NSLayoutAttribute.Left, 1f, -10f),
82-
NSLayoutConstraint.Create (XEditor, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, DefaultControlHeight),
82+
NSLayoutConstraint.Create (XEditor, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 18),
8383

8484
NSLayoutConstraint.Create (XLabel, NSLayoutAttribute.Top, NSLayoutRelation.Equal, XEditor, NSLayoutAttribute.Bottom, 1f, -4f),
85-
NSLayoutConstraint.Create (XLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, DefaultControlHeight),
85+
NSLayoutConstraint.Create (XLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 18),
8686

87-
NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 0f),
88-
NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this, NSLayoutAttribute.Right, 1f, -32f),
87+
NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 3f),
88+
NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this, NSLayoutAttribute.Right, 1f, 0),
8989
NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Width, NSLayoutRelation.Equal, XEditor, NSLayoutAttribute.Width, 1f, 0f),
90-
NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, DefaultControlHeight),
90+
NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 18),
9191

9292
NSLayoutConstraint.Create (YLabel, NSLayoutAttribute.Top, NSLayoutRelation.Equal, XLabel, NSLayoutAttribute.Top, 1f, 0f),
93-
NSLayoutConstraint.Create (YLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, DefaultControlHeight),
93+
NSLayoutConstraint.Create (YLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 18),
9494

9595
NSLayoutConstraint.Create (WidthEditor, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 33f),
9696
NSLayoutConstraint.Create (WidthEditor, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, 0f),
9797
NSLayoutConstraint.Create (WidthEditor, NSLayoutAttribute.Right, NSLayoutRelation.Equal, HeightEditor, NSLayoutAttribute.Left, 1f, -10f),
98-
NSLayoutConstraint.Create (WidthEditor, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, DefaultControlHeight),
98+
NSLayoutConstraint.Create (WidthEditor, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 18),
9999

100100
NSLayoutConstraint.Create (WidthLabel, NSLayoutAttribute.Top, NSLayoutRelation.Equal, WidthEditor, NSLayoutAttribute.Bottom, 1f, -4f),
101-
NSLayoutConstraint.Create (WidthLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, DefaultControlHeight),
101+
NSLayoutConstraint.Create (WidthLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 18),
102102

103103
NSLayoutConstraint.Create (HeightEditor, NSLayoutAttribute.Top, NSLayoutRelation.Equal, WidthEditor, NSLayoutAttribute.Top, 1f, 0f),
104-
NSLayoutConstraint.Create (HeightEditor, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this, NSLayoutAttribute.Right, 1f, -32f),
104+
NSLayoutConstraint.Create (HeightEditor, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this, NSLayoutAttribute.Right, 1f, 0),
105105
NSLayoutConstraint.Create (HeightEditor, NSLayoutAttribute.Width, NSLayoutRelation.Equal, WidthEditor, NSLayoutAttribute.Width, 1f, 0f),
106-
NSLayoutConstraint.Create (HeightEditor, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, DefaultControlHeight),
106+
NSLayoutConstraint.Create (HeightEditor, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 18),
107107

108108
NSLayoutConstraint.Create (HeightLabel, NSLayoutAttribute.Top, NSLayoutRelation.Equal, WidthLabel, NSLayoutAttribute.Top, 1f, 0f),
109-
NSLayoutConstraint.Create (HeightLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, DefaultControlHeight),
109+
NSLayoutConstraint.Create (HeightLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 18),
110110

111111

112112
NSLayoutConstraint.Create (XLabel, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, XEditor.Subviews[0], NSLayoutAttribute.CenterX, 1f, 0),

Xamarin.PropertyEditing.Mac/Controls/BooleanEditorControl.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ public BooleanEditorControl (IHostResourceProvider hostResource)
3131
AddSubview (BooleanEditor);
3232

3333
this.AddConstraints (new[] {
34-
NSLayoutConstraint.Create (BooleanEditor, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 6f),
35-
NSLayoutConstraint.Create (BooleanEditor, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, -50f),
34+
NSLayoutConstraint.Create (BooleanEditor, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1f, 0f),
35+
NSLayoutConstraint.Create (BooleanEditor, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, 0f),
3636
});
3737
}
3838

Xamarin.PropertyEditing.Mac/Controls/BrushEditorControl.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ public BrushEditorControl (IHostResourceProvider hostResources)
5454
};
5555

5656
this.popUpButton = new ColorPopUpButton {
57-
Font = NSFont.FromFontName (DefaultFontName, DefaultFontSize),
57+
ControlSize = NSControlSize.Small,
58+
Font = NSFont.SystemFontOfSize (NSFont.SystemFontSizeForControlSize (NSControlSize.Small)),
5859
TranslatesAutoresizingMaskIntoConstraints = false,
5960
};
6061

@@ -64,9 +65,9 @@ public BrushEditorControl (IHostResourceProvider hostResources)
6465
AddSubview (this.popUpButton);
6566

6667
this.AddConstraints (new[] {
67-
NSLayoutConstraint.Create (this.popUpButton, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 2f),
68-
NSLayoutConstraint.Create (this.popUpButton, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, -32f),
69-
NSLayoutConstraint.Create (this.popUpButton, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, DefaultControlHeight - 3),
68+
NSLayoutConstraint.Create (this.popUpButton, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, 0),
69+
NSLayoutConstraint.Create (this.popUpButton, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 16),
70+
NSLayoutConstraint.Create (this.popUpButton, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1f, 0),
7071
});
7172

7273
ViewDidChangeEffectiveAppearance ();

Xamarin.PropertyEditing.Mac/Controls/CombinablePropertyEditor.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public CombinablePropertyEditor (IHostResourceProvider hostResources)
3131
public override nint GetHeight (EditorViewModel vm)
3232
{
3333
var realVm = (CombinablePropertyViewModel<T>)vm;
34-
return DefaultControlHeight * realVm.Choices.Count;
34+
return subrowHeight * realVm.Choices.Count + 6;
3535
}
3636

3737
protected override void HandleErrorsChanged (object sender, DataErrorsChangedEventArgs e)
@@ -63,7 +63,7 @@ protected override void OnViewModelChanged (PropertyViewModel oldModel)
6363
if (ViewModel == null)
6464
return;
6565

66-
float top = 0;
66+
float top = 3;
6767

6868
while (this.combinableList.Count > ViewModel.Choices.Count) {
6969
var child = this.combinableList.KeyAt (ViewModel.Choices.Count);
@@ -78,16 +78,15 @@ protected override void OnViewModelChanged (PropertyViewModel oldModel)
7878
NSButton checkbox;
7979
if (i >= this.combinableList.Count) {
8080
checkbox = new FocusableBooleanButton ();
81-
8281
checkbox.Activated += SelectionChanged;
8382

8483
AddSubview (checkbox);
8584

8685
this.AddConstraints (new[] {
8786
NSLayoutConstraint.Create (checkbox, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, top),
8887
NSLayoutConstraint.Create (checkbox, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, 0f),
89-
NSLayoutConstraint.Create (checkbox, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, -33f),
90-
NSLayoutConstraint.Create (checkbox, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, DefaultControlHeight),
88+
NSLayoutConstraint.Create (checkbox, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, 0),
89+
NSLayoutConstraint.Create (checkbox, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, subrowHeight),
9190
});
9291
} else {
9392
checkbox = this.combinableList.KeyAt (i);
@@ -96,7 +95,7 @@ protected override void OnViewModelChanged (PropertyViewModel oldModel)
9695
checkbox.Title = choice.Name;
9796

9897
this.combinableList[checkbox] = choice;
99-
top += DefaultControlHeight;
98+
top += subrowHeight;
10099
}
101100

102101
// Set our tabable order
@@ -127,6 +126,7 @@ protected override void UpdateAccessibilityValues ()
127126
}
128127
}
129128

129+
private const int subrowHeight = 20;
130130
private readonly OrderedDictionary<NSButton, FlaggableChoiceViewModel<T>> combinableList = new OrderedDictionary<NSButton, FlaggableChoiceViewModel<T>> ();
131131
private NSView firstKeyView;
132132
private NSView lastKeyView;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public BasePopOverControl (IHostResourceProvider hostResources, string title, st
4848
NSLayoutConstraint.Create (viewTitle, NSLayoutAttribute.Left, NSLayoutRelation.Equal, iconView, NSLayoutAttribute.Right, 1f, 5f),
4949
//NSLayoutConstraint.Create (viewTitle, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, 38f),
5050
NSLayoutConstraint.Create (viewTitle, NSLayoutAttribute.Width, NSLayoutRelation.Equal, 1f, 120),
51-
NSLayoutConstraint.Create (viewTitle, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, PropertyEditorControl.DefaultControlHeight),
51+
NSLayoutConstraint.Create (viewTitle, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 24),
5252
});
5353
}
5454

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public BrushTabViewController (IHostResourceProvider hostResources)
2525

2626
this.filterResource = new NSSearchField {
2727
ControlSize = NSControlSize.Mini,
28-
Font = NSFont.FromFontName (PropertyEditorControl.DefaultFontName, PropertyEditorControl.DefaultFontSize),
28+
Font = NSFont.SystemFontOfSize (NSFont.SystemFontSizeForControlSize (NSControlSize.Mini)),
2929
PlaceholderString = Properties.Resources.SearchResourcesTitle,
3030
};
3131

@@ -46,7 +46,8 @@ EditorViewModel IEditorView.ViewModel {
4646

4747
NSView IEditorView.NativeView => View;
4848

49-
public bool IsDynamicallySized => false;
49+
public bool IsDynamicallySized => false;
50+
public bool NeedsPropertyButton => false;
5051

5152
public nint GetHeight (EditorViewModel viewModel)
5253
{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public FocusableBooleanButton ()
1414
Cell.LineBreakMode = NSLineBreakMode.TruncatingTail;
1515
Cell.UsesSingleLineMode = true;
1616
ControlSize = NSControlSize.Small;
17-
Font = NSFont.FromFontName (PropertyEditorControl.DefaultFontName, PropertyEditorControl.DefaultFontSize);
17+
Font = NSFont.SystemFontOfSize (NSFont.SystemFontSizeForControlSize (NSControlSize.Small));
1818
Title = string.Empty;
1919
TranslatesAutoresizingMaskIntoConstraints = false;
2020

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public FocusableButton ()
1414
Cell.LineBreakMode = NSLineBreakMode.TruncatingTail;
1515
Cell.UsesSingleLineMode = true;
1616
ControlSize = NSControlSize.Small;
17-
Font = NSFont.FromFontName (PropertyEditorControl.DefaultFontName, PropertyEditorControl.DefaultFontSize);
17+
Font = NSFont.SystemFontOfSize (NSFont.SystemFontSizeForControlSize (NSControlSize.Small));
1818
Title = string.Empty;
1919
TranslatesAutoresizingMaskIntoConstraints = false;
2020
}

0 commit comments

Comments
 (0)