diff options
author | Larry Ewing <lewing@microsoft.com> | 2018-07-12 02:06:50 +0300 |
---|---|---|
committer | Larry Ewing <lewing@microsoft.com> | 2018-07-16 22:05:49 +0300 |
commit | d258ab2cfb7509f43fa0420d6fe68b23a2b7fe5e (patch) | |
tree | 7244370941d3d77e69cf883c9754ddf47c8b04b9 /Xamarin.PropertyEditing.Mac/Controls/Custom | |
parent | 74d3e8ef0f360ad4273905518b59be552c8a83ca (diff) |
Add UnderlinedTabViewController
Make an initial work for a TabViewController
that renders tabs like the Design mockups.
Diffstat (limited to 'Xamarin.PropertyEditing.Mac/Controls/Custom')
6 files changed, 130 insertions, 5 deletions
diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/BrushTabViewController.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/BrushTabViewController.cs index 93e2e50..c47f88a 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/Custom/BrushTabViewController.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/BrushTabViewController.cs @@ -8,7 +8,7 @@ using Xamarin.PropertyEditing.ViewModels; namespace Xamarin.PropertyEditing.Mac { - internal class BrushTabViewController : NotifyingTabViewController<BrushPropertyViewModel> + internal class BrushTabViewController : UnderlinedTabViewController<BrushPropertyViewModel> { public BrushTabViewController () { diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/ColorComponentTabViewController.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/ColorComponentTabViewController.cs index 0e51c03..75be1ff 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/Custom/ColorComponentTabViewController.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/ColorComponentTabViewController.cs @@ -1,14 +1,15 @@ using System; +using System.Collections.Generic; using System.ComponentModel; using AppKit; using Xamarin.PropertyEditing.ViewModels; namespace Xamarin.PropertyEditing.Mac { - internal class ColorComponentTabViewController : NotifyingTabViewController<SolidBrushViewModel> + internal class ColorComponentTabViewController : UnderlinedTabViewController<SolidBrushViewModel> { public ColorComponentTabViewController () - { + { foreach (var value in Enum.GetValues (typeof (ChannelEditorType))) { var editorType = (ChannelEditorType)value; AddTabViewItem (new NSTabViewItem { @@ -34,6 +35,7 @@ namespace Xamarin.PropertyEditing.Mac var controller = item.ViewController as ColorComponentViewController; base.WillSelect (tabView, item); + controller.ViewModel = ViewModel; EditorType = controller.EditorType; } diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/NotifyingViewController.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/NotifyingViewController.cs index 21eaa73..c572a27 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/Custom/NotifyingViewController.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/NotifyingViewController.cs @@ -10,7 +10,7 @@ using Xamarin.PropertyEditing.ViewModels; namespace Xamarin.PropertyEditing.Mac { - class NotifyingViewController<T> : NSViewController, INotifyingListner<T> where T : NotifyingObject + internal class NotifyingViewController<T> : NSViewController, INotifyingListner<T> where T : NotifyingObject { internal T ViewModel { get => Adaptor.ViewModel; diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/SolidColorBrushEditor.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/SolidColorBrushEditor.cs index cba853a..75ddb6d 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/Custom/SolidColorBrushEditor.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/SolidColorBrushEditor.cs @@ -12,7 +12,7 @@ using Xamarin.PropertyEditing.ViewModels; namespace Xamarin.PropertyEditing.Mac { - internal class EditorInteraction : NotifyingObject + internal class EditorInteraction { public EditorInteraction (SolidBrushViewModel viewModel, ColorEditorLayer layer) { diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/UnderlinedTabViewController.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/UnderlinedTabViewController.cs new file mode 100644 index 0000000..8225319 --- /dev/null +++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/UnderlinedTabViewController.cs @@ -0,0 +1,71 @@ +using System.Linq; +using AppKit; + +namespace Xamarin.PropertyEditing.Mac +{ + internal class UnderlinedTabViewController<TViewModel> : NotifyingTabViewController<TViewModel> where TViewModel : NotifyingObject + { + private NSStackView labelStack = new NSStackView () { + Spacing = 4f, + }; + + public override void NumberOfItemsChanged (NSTabView tabView) + { + base.NumberOfItemsChanged (tabView); + var items = this.labelStack.Views.ToList (); + foreach (var view in items) { + this.labelStack.RemoveView (view); + } + var i = 0; + foreach (var item in TabViewItems) { + this.labelStack.AddView (new UnderlinedTextField () { + BackgroundColor = NSColor.Clear, + Editable = false, + Bezeled = false, + StringValue = item.Label, + Selected = i == SelectedTabViewItemIndex, + }, NSStackViewGravity.Leading); + i++; + } + } + + public override void MouseDown (NSEvent theEvent) + { + var hit = View.HitTest (View.Superview.ConvertPointFromView (theEvent.LocationInWindow, null)); + if (!(hit is UnderlinedTextField)) + return; + + int i = 0; + foreach (var label in labelStack.Views) { + if (hit == label) { + SelectedTabViewItemIndex = i; + break; + } + i++; + } + } + + public override void DidSelect (NSTabView tabView, NSTabViewItem item) + { + base.DidSelect (tabView, item); + for (int i = 0; i < this.labelStack.Views.Length; i++) { + var underlined = this.labelStack.Views[i] as UnderlinedTextField; + if (underlined != null) + underlined.Selected = SelectedTabViewItemIndex == i; + } + } + + public override void LoadView () + { + var stack = new NSStackView () { + Spacing = 0, + Alignment = NSLayoutAttribute.Width, + Orientation = NSUserInterfaceLayoutOrientation.Vertical + }; + + stack.AddView (this.labelStack, NSStackViewGravity.Leading); + stack.AddView (TabView, NSStackViewGravity.Bottom); + View = stack; + } + } +} diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/UnderlinedTextField.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/UnderlinedTextField.cs new file mode 100644 index 0000000..2bc17f3 --- /dev/null +++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/UnderlinedTextField.cs @@ -0,0 +1,52 @@ +using AppKit; +using CoreGraphics; + +namespace Xamarin.PropertyEditing.Mac +{ + internal class UnderlinedTextField : NSTextField + { + public UnderlinedTextField () + { + TranslatesAutoresizingMaskIntoConstraints = false; + AutoresizingMask = NSViewResizingMask.MaxXMargin; + UsesSingleLineMode = true; + } + + private bool selected; + public bool Selected + { + get => selected; + set + { + //if (selected == value) + // return; + selected = value; + TextColor = selected ? NSColor.Text : NSColor.DisabledControlText; + + //Enabled = value; + NeedsDisplay = true; + } + } + + public override void DrawRect (CGRect dirtyRect) + { + base.DrawRect (dirtyRect); + if (!Selected) + return; + + NSBezierPath path = new NSBezierPath (); + path.AppendPathWithRect (new CGRect (Bounds.X + 1, Bounds.Bottom - 3, Bounds.Width - 2, 3.5)); + NSColor.Text.Set (); + path.Fill (); + } + + public override CGSize IntrinsicContentSize + { + get + { + var size = base.IntrinsicContentSize; + return new CGSize (size.Width + 2, size.Height + 5); + } + } + } +} |