diff options
Diffstat (limited to 'Xamarin.PropertyEditing.Mac/Controls/Custom')
-rw-r--r-- | Xamarin.PropertyEditing.Mac/Controls/Custom/TabButton.cs | 82 |
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); + } + } +} |