Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add NSAttributedString #43

Merged
merged 2 commits into from
Apr 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cocoa/NSMenuItem.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
25 changes: 25 additions & 0 deletions core/NSAttributedString.go
Original file line number Diff line number Diff line change
@@ -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}
}
2 changes: 1 addition & 1 deletion core/NSString.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down