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

Commit

Permalink
Merge pull request #546 from xamarin/ermau-mac-theming-issues
Browse files Browse the repository at this point in the history
Overhaul Mac layout
  • Loading branch information
ermau authored Mar 6, 2019
2 parents 1976b12 + 5d2c8e1 commit f2f3549
Show file tree
Hide file tree
Showing 41 changed files with 390 additions and 581 deletions.
104 changes: 0 additions & 104 deletions Xamarin.PropertyEditing.Mac/Controls/BaseEditorControl.cs

This file was deleted.

30 changes: 8 additions & 22 deletions Xamarin.PropertyEditing.Mac/Controls/BasePointEditorControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,23 @@ 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, 0f),
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, DefaultControlHeight),
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, DefaultControlHeight),
NSLayoutConstraint.Create (XLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, editorHeight),

NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 0f),
NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this, NSLayoutAttribute.Right, 1f, -32f),
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, DefaultControlHeight),
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, DefaultControlHeight),
NSLayoutConstraint.Create (YLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, editorHeight),

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 @@ -77,21 +78,6 @@ public override void ViewDidChangeEffectiveAppearance ()
YLabel.TextColor = HostResources.GetNamedColor (NamedResources.DescriptionLabelColor);
}

protected override void HandleErrorsChanged (object sender, System.ComponentModel.DataErrorsChangedEventArgs e)
{
UpdateErrorsDisplayed (ViewModel.GetErrors (ViewModel.Property.Name));
}

protected override void UpdateErrorsDisplayed (IEnumerable errors)
{
if (ViewModel.HasErrors) {
SetErrors (errors);
} else {
SetErrors (null);
SetEnabled ();
}
}

protected override void SetEnabled ()
{
XEditor.Enabled = ViewModel.Property.CanWrite;
Expand Down
39 changes: 12 additions & 27 deletions Xamarin.PropertyEditing.Mac/Controls/BaseRectangleEditorControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,37 +76,37 @@ protected BaseRectangleEditorControl (IHostResourceProvider hostResources)
AddSubview (HeightEditor);

this.AddConstraints (new[] {
NSLayoutConstraint.Create (XEditor, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 0f),
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, DefaultControlHeight),
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, DefaultControlHeight),
NSLayoutConstraint.Create (XLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 18),

NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 0f),
NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this, NSLayoutAttribute.Right, 1f, -32f),
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, DefaultControlHeight),
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, DefaultControlHeight),
NSLayoutConstraint.Create (YLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 18),

NSLayoutConstraint.Create (WidthEditor, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 33f),
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, DefaultControlHeight),
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, DefaultControlHeight),
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.Right, NSLayoutRelation.Equal, this, NSLayoutAttribute.Right, 1f, -32f),
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, DefaultControlHeight),
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, DefaultControlHeight),
NSLayoutConstraint.Create (HeightLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 18),


NSLayoutConstraint.Create (XLabel, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, XEditor.Subviews[0], NSLayoutAttribute.CenterX, 1f, 0),
Expand All @@ -133,21 +133,6 @@ protected virtual void OnInputUpdated (object sender, EventArgs e)
ViewModel.Value = (T)Activator.CreateInstance (typeof(T), XEditor.Value, YEditor.Value, WidthEditor.Value, HeightEditor.Value);
}

protected override void HandleErrorsChanged (object sender, System.ComponentModel.DataErrorsChangedEventArgs e)
{
UpdateErrorsDisplayed (ViewModel.GetErrors (ViewModel.Property.Name));
}

protected override void UpdateErrorsDisplayed (IEnumerable errors)
{
if (ViewModel.HasErrors) {
SetErrors (errors);
} else {
SetErrors (null);
SetEnabled ();
}
}

protected override void SetEnabled ()
{
XEditor.Enabled = ViewModel.Property.CanWrite;
Expand Down
19 changes: 2 additions & 17 deletions Xamarin.PropertyEditing.Mac/Controls/BooleanEditorControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public BooleanEditorControl (IHostResourceProvider hostResource)
AddSubview (BooleanEditor);

this.AddConstraints (new[] {
NSLayoutConstraint.Create (BooleanEditor, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 6f),
NSLayoutConstraint.Create (BooleanEditor, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, -50f),
NSLayoutConstraint.Create (BooleanEditor, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1f, 0f),
NSLayoutConstraint.Create (BooleanEditor, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, 0f),
});
}

Expand All @@ -59,21 +59,6 @@ protected override void UpdateValue ()
}
}

protected override void UpdateErrorsDisplayed (IEnumerable errors)
{
if (ViewModel.HasErrors) {
SetErrors (errors);
} else {
SetErrors (null);
SetEnabled ();
}
}

protected override void HandleErrorsChanged (object sender, System.ComponentModel.DataErrorsChangedEventArgs e)
{
UpdateErrorsDisplayed (ViewModel.GetErrors (ViewModel.Property.Name));
}

protected override void SetEnabled ()
{
BooleanEditor.Enabled = ViewModel.Property.CanWrite;
Expand Down
21 changes: 5 additions & 16 deletions Xamarin.PropertyEditing.Mac/Controls/BrushEditorControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public BrushEditorControl (IHostResourceProvider hostResources)
};

this.popUpButton = new ColorPopUpButton {
Font = NSFont.FromFontName (DefaultFontName, DefaultFontSize),
ControlSize = NSControlSize.Small,
Font = NSFont.SystemFontOfSize (NSFont.SystemFontSizeForControlSize (NSControlSize.Small)),
TranslatesAutoresizingMaskIntoConstraints = false,
};

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

this.AddConstraints (new[] {
NSLayoutConstraint.Create (this.popUpButton, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 2f),
NSLayoutConstraint.Create (this.popUpButton, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, -32f),
NSLayoutConstraint.Create (this.popUpButton, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, DefaultControlHeight - 3),
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),
});

ViewDidChangeEffectiveAppearance ();
Expand All @@ -89,23 +90,11 @@ public override void ViewDidChangeEffectiveAppearance ()
public override NSView FirstKeyView => this.popUpButton;
public override NSView LastKeyView => this.popUpButton;

protected override void HandleErrorsChanged (object sender, DataErrorsChangedEventArgs e)
{
}

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

protected override void UpdateAccessibilityValues ()
{
}

protected override void UpdateErrorsDisplayed (IEnumerable errors)
{
}

string GetTitle ()
{
var title = LocalizationResources.CommonBrushTitleUnknown;
Expand Down
27 changes: 6 additions & 21 deletions Xamarin.PropertyEditing.Mac/Controls/CombinablePropertyEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,7 @@ public CombinablePropertyEditor (IHostResourceProvider hostResources)
public override nint GetHeight (EditorViewModel vm)
{
var realVm = (CombinablePropertyViewModel<T>)vm;
return DefaultControlHeight * realVm.Choices.Count;
}

protected override void HandleErrorsChanged (object sender, DataErrorsChangedEventArgs e)
{
UpdateErrorsDisplayed (ViewModel.GetErrors (e.PropertyName));
return subrowHeight * realVm.Choices.Count + 6;
}

protected override void SetEnabled ()
Expand All @@ -46,24 +41,14 @@ protected override void SetEnabled ()
}
}

protected override void UpdateErrorsDisplayed (IEnumerable errors)
{
if (ViewModel.HasErrors) {
SetErrors (errors);
} else {
SetErrors (null);
SetEnabled ();
}
}

protected override void OnViewModelChanged (PropertyViewModel oldModel)
{
base.OnViewModelChanged (oldModel);

if (ViewModel == null)
return;

float top = 0;
float top = 3;

while (this.combinableList.Count > ViewModel.Choices.Count) {
var child = this.combinableList.KeyAt (ViewModel.Choices.Count);
Expand All @@ -78,16 +63,15 @@ protected override void OnViewModelChanged (PropertyViewModel oldModel)
NSButton checkbox;
if (i >= this.combinableList.Count) {
checkbox = new FocusableBooleanButton ();

checkbox.Activated += SelectionChanged;

AddSubview (checkbox);

this.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, -33f),
NSLayoutConstraint.Create (checkbox, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, DefaultControlHeight),
NSLayoutConstraint.Create (checkbox, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, 0),
NSLayoutConstraint.Create (checkbox, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, subrowHeight),
});
} else {
checkbox = this.combinableList.KeyAt (i);
Expand All @@ -96,7 +80,7 @@ protected override void OnViewModelChanged (PropertyViewModel oldModel)
checkbox.Title = choice.Name;

this.combinableList[checkbox] = choice;
top += DefaultControlHeight;
top += subrowHeight;
}

// Set our tabable order
Expand Down Expand Up @@ -127,6 +111,7 @@ protected override void UpdateAccessibilityValues ()
}
}

private const int subrowHeight = 20;
private readonly OrderedDictionary<NSButton, FlaggableChoiceViewModel<T>> combinableList = new OrderedDictionary<NSButton, FlaggableChoiceViewModel<T>> ();
private NSView firstKeyView;
private NSView lastKeyView;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public BasePopOverControl (IHostResourceProvider hostResources, string title, st
NSLayoutConstraint.Create (viewTitle, NSLayoutAttribute.Left, NSLayoutRelation.Equal, iconView, NSLayoutAttribute.Right, 1f, 5f),
//NSLayoutConstraint.Create (viewTitle, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, 38f),
NSLayoutConstraint.Create (viewTitle, NSLayoutAttribute.Width, NSLayoutRelation.Equal, 1f, 120),
NSLayoutConstraint.Create (viewTitle, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, PropertyEditorControl.DefaultControlHeight),
NSLayoutConstraint.Create (viewTitle, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 24),
});
}

Expand Down
Loading

0 comments on commit f2f3549

Please sign in to comment.