From a5c5da7a4842eaee1e3327e5ba99eb9692140dd8 Mon Sep 17 00:00:00 2001 From: Murilo Santana Date: Wed, 7 Apr 2021 07:14:42 -0300 Subject: [PATCH 1/2] add basic support for NSAttributedString --- cocoa/NSMenuItem.go | 6 ++++++ core/NSAttributedString.go | 25 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 core/NSAttributedString.go diff --git a/cocoa/NSMenuItem.go b/cocoa/NSMenuItem.go index 44413051..01194428 100644 --- a/cocoa/NSMenuItem.go +++ b/cocoa/NSMenuItem.go @@ -79,6 +79,12 @@ func (i NSMenuItem) SetTitle(s string) { i.Set("title:", core.String(s)) } +// SetAttributedTitle sets a custom string for the menu item's title. +// https://developer.apple.com/documentation/appkit/nsmenuitem/1514860-attributedtitle?language=objc +func (i NSMenuItem) SetAttributedTitle(s string) { + i.Set("attributedTitle:", core.NSAttributedString_FromString(s)) +} + // Image returns the menu item’s image. // https://developer.apple.com/documentation/appkit/nsmenuitem/1514819-image?language=objc func (i NSMenuItem) Image() NSImage { diff --git a/core/NSAttributedString.go b/core/NSAttributedString.go new file mode 100644 index 00000000..60e6d66c --- /dev/null +++ b/core/NSAttributedString.go @@ -0,0 +1,25 @@ +package core + +import ( + "github.com/progrium/macdriver/objc" +) + +// Wrapper for NSAttributedString +// https://developer.apple.com/documentation/foundation/nsattributedstring?language=objc +type NSAttributedString struct { + objc.Object +} + +var nsAttributedString = objc.Get("NSAttributedString") + +// NSAttributedString_FromString returns an initialized NSAttributedString +// https://developer.apple.com/documentation/foundation/nsattributedstring/1407481-initwithstring?language=objc +func NSAttributedString_FromString(str string) NSAttributedString { + nsstr := NSString_FromString(str) + obj := nsAttributedString.Alloc().Send("initWithString:", nsstr) + return NSAttributedString_FromObject(obj) +} + +func NSAttributedString_FromObject(obj objc.Object) NSAttributedString { + return NSAttributedString{obj} +} From ec21e5ee45f932e5c2cc11633adb2f669ecc5b38 Mon Sep 17 00:00:00 2001 From: Murilo Santana Date: Wed, 7 Apr 2021 07:14:56 -0300 Subject: [PATCH 2/2] typo --- core/NSString.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/NSString.go b/core/NSString.go index e99ecf2e..53eb0089 100644 --- a/core/NSString.go +++ b/core/NSString.go @@ -11,7 +11,7 @@ const ( NSUTF8StringEncoding = 4 ) -// Wrapper for NSPasteboard +// Wrapper for NSString // https://developer.apple.com/documentation/foundation/nsstring?language=occ type NSString struct { objc.Object