Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/xamarin/Xamarin.PropertyEditing.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Maupin <ermaup@microsoft.com>2019-01-26 00:45:43 +0300
committerEric Maupin <ermaup@microsoft.com>2019-01-26 00:45:43 +0300
commit0acb05e1d21a7d86f467fe02be5e941809cb2d3f (patch)
treeaf91510d25bc69a6b81362d6e6e7af7954727763 /Xamarin.PropertyEditing.Mac/Controls/Custom
parent488124c7dd20b85c7b65dcd8f70852c3d32aaeda (diff)
[mac] Update arrange mode to tabs
Diffstat (limited to 'Xamarin.PropertyEditing.Mac/Controls/Custom')
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/Custom/TabButton.cs82
1 files changed, 82 insertions, 0 deletions
diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/TabButton.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/TabButton.cs
new file mode 100644
index 0000000..eb6807c
--- /dev/null
+++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/TabButton.cs
@@ -0,0 +1,82 @@
+using System;
+using AppKit;
+using CoreGraphics;
+using Foundation;
+
+namespace Xamarin.PropertyEditing.Mac
+{
+ internal class TabButton
+ : NSButton
+ {
+ public TabButton (IHostResourceProvider hostResource, string imageName)
+ {
+ if (hostResource == null)
+ throw new ArgumentNullException (nameof (hostResource));
+ if (imageName == null)
+ throw new ArgumentNullException (nameof (imageName));
+
+ Bordered = false;
+ Action = new ObjCRuntime.Selector (ClickedName);
+
+ var clicked = new NSClickGestureRecognizer (OnClicked);
+ AddGestureRecognizer (clicked);
+
+ this.hostResource = hostResource;
+ this.imageName = imageName;
+
+ ViewDidChangeEffectiveAppearance ();
+ }
+
+ public event EventHandler Clicked;
+
+ public bool Selected
+ {
+ get { return this.selected; }
+ set
+ {
+ Enabled = value;
+ this.selected = value;
+ NeedsDisplay = true;
+ }
+ }
+
+ public override CGSize IntrinsicContentSize
+ {
+ get
+ {
+ var size = base.IntrinsicContentSize;
+ return new CGSize (size.Width + 2 + 10, size.Height + 2 + 10);
+ }
+ }
+
+ public override void ViewDidChangeEffectiveAppearance ()
+ {
+ base.ViewDidChangeEffectiveAppearance ();
+ Image = this.hostResource.GetNamedImage (this.imageName);
+ }
+
+ public override void DrawRect (CGRect dirtyRect)
+ {
+ base.DrawRect (dirtyRect);
+ if (!Selected)
+ return;
+
+ NSBezierPath path = new NSBezierPath ();
+ path.AppendPathWithRect (new CGRect (Bounds.X, Bounds.Height - 2, Bounds.Width, 2));
+ (Selected ? NSColor.Text : NSColor.DisabledControlText).Set ();
+ path.Fill ();
+ }
+
+ private readonly string imageName;
+ private readonly IHostResourceProvider hostResource;
+ private bool selected;
+
+ private const string ClickedName = "OnClicked";
+
+ [Export (ClickedName)]
+ private void OnClicked()
+ {
+ Clicked?.Invoke (this, EventArgs.Empty);
+ }
+ }
+}