Skip to content

Commit

Permalink
gen: Remove _As* pattern to clean up generated code (#129)
Browse files Browse the repository at this point in the history
* gen: remove _As* constrcutor pattern

* gen: fix up As calls

* gen: drop As* for Init methods

* gen: include typed Init_As
  • Loading branch information
tmc committed Jul 9, 2023
1 parent a8ace7c commit 8d32f63
Show file tree
Hide file tree
Showing 30 changed files with 591 additions and 154 deletions.
4 changes: 2 additions & 2 deletions cocoa/NSApplication.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ func init() {
return TerminateAfterWindowsClose
})
objc.RegisterClass(DefaultDelegateClass)
DefaultDelegate = objc.Get("DefaultDelegate").Alloc().Init()
DefaultDelegate = objc.Get("DefaultDelegate").Alloc().InitObject()
}

type NSApplication struct {
gen_NSApplication
}

func NSApplication_New() NSApplication {
return NSApplication_Alloc().Init_AsNSApplication()
return NSApplication_Alloc().Init()
}

func NSApp() NSApplication {
Expand Down
2 changes: 1 addition & 1 deletion cocoa/NSControl.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ type NSControl struct {
}

func NSControl_Init(frame core.NSRect) NSControl {
return NSControl_Alloc().InitWithFrame_AsNSControl(frame)
return NSControl_Alloc().InitWithFrame(frame)
}
4 changes: 2 additions & 2 deletions cocoa/NSImage.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ type NSImage struct {
}

func NSImage_InitWithData(data core.NSDataRef) NSImage {
return NSImage_Alloc().InitWithData_AsNSImage(data)
return NSImage_Alloc().InitWithData(data)
}

func NSImage_InitWithURL(url core.NSURL) NSImage {
return NSImage_Alloc().InitWithContentsOfURL_AsNSImage(url)
return NSImage_Alloc().InitWithContentsOfURL(url)
}

func NSImage_ImageNamed(name string) NSImage {
Expand Down
2 changes: 1 addition & 1 deletion cocoa/NSImageView.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ type NSImageView struct {
}

func NSImageView_New() NSImageView {
return NSImageView_Alloc().Init_AsNSImageView()
return NSImageView_Alloc().Init()
}
2 changes: 1 addition & 1 deletion cocoa/NSImage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

func TestNSImageSize(t *testing.T) {
img := NSImage_Alloc().InitWithSize_AsNSImage(core.Size(100, 200))
img := NSImage_Alloc().InitWithSize(core.Size(100, 200))
size := img.Size()
assert.EqualValues(t, 100, size.Width)
assert.EqualValues(t, 200, size.Height)
Expand Down
4 changes: 2 additions & 2 deletions cocoa/NSMenu.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ type NSMenu struct {
}

func NSMenu_New() NSMenu {
return NSMenu_Alloc().Init_AsNSMenu()
return NSMenu_Alloc().Init()
}

func NSMenu_Init(title string) NSMenu {
return NSMenu_Alloc().InitWithTitle_AsNSMenu(core.String(title))
return NSMenu_Alloc().InitWithTitle(core.String(title))
}

func (menu NSMenu) Title() string {
Expand Down
4 changes: 2 additions & 2 deletions cocoa/NSMenuItem.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ type NSMenuItem struct {
// NSMenuItem_Init returns an initialized instance of NSMenuItem.
// https://developer.apple.com/documentation/appkit/nsmenuitem/1514858-initwithtitle?language=objc
func NSMenuItem_Init(itemName string, action objc.Selector, keyEquivalent string) NSMenuItem {
return NSMenuItem_Alloc().InitWithTitleActionKeyEquivalent_AsNSMenuItem(
return NSMenuItem_Alloc().InitWithTitleActionKeyEquivalent(
core.String(itemName), action, core.String(keyEquivalent))
}

// NSMenuItem_New returns an initialized instance of NSMenuItem.
func NSMenuItem_New() NSMenuItem {
return NSMenuItem_Alloc().Init_AsNSMenuItem()
return NSMenuItem_Alloc().Init()
}

// NSMenuItem_Separator returns a menu item that is used to separate logical groups of menu commands.
Expand Down
2 changes: 1 addition & 1 deletion cocoa/NSNib.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func NSNib_InitWithNibNamed_Bundle(name string, bundle NSBundle) NSNib {
}

func NSNib_InitWithNibData_Bundle(data core.NSDataRef, bundle NSBundleRef) NSNib {
return NSNib_Alloc().InitWithNibDataBundle_AsNSNib(data, bundle)
return NSNib_Alloc().InitWithNibDataBundle(data, bundle)
}

func (nib NSNib) InstantiateWithOwner_TopLevelObjects(owner objc.Object) (core.NSArray, bool) {
Expand Down
2 changes: 1 addition & 1 deletion cocoa/NSPopover.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const (
)

func NSPopover_Init() NSPopover {
return NSPopover_Alloc().Init_AsNSPopover()
return NSPopover_Alloc().Init()
}

func (p NSPopover) SetContentSize(s core.NSSize) {
Expand Down
14 changes: 1 addition & 13 deletions cocoa/NSSound.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,5 @@ type NSSound struct {
}

func NSSound_InitWithData(data core.NSDataRef) NSSound {
return NSSound_Alloc().InitWithData_AsNSSound(data)
}

func (sound NSSound) Play() {
sound.Play()
}

func (sound NSSound) Pause() {
sound.Pause()
}

func (sound NSSound) Resume() {
sound.Resume()
return NSSound_Alloc().InitWithData(data)
}
2 changes: 1 addition & 1 deletion cocoa/NSTextView.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type NSTextView struct {
}

func NSTextView_Init(frame core.NSRect) NSTextView {
return NSTextView_Alloc().InitWithFrame_AsNSTextView(frame)
return NSTextView_Alloc().InitWithFrame(frame)
}

func (v NSTextView) String() string {
Expand Down
2 changes: 1 addition & 1 deletion cocoa/NSView.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type NSView struct {
}

func NSView_Init(frame core.NSRect) NSView {
return NSView_Alloc().InitWithFrame_AsNSView(frame)
return NSView_Alloc().InitWithFrame(frame)
}

func (v NSView) AddSubviewPositionedRelativeTo(subview NSViewRef, positioned int, relativeTo NSViewRef) {
Expand Down
2 changes: 1 addition & 1 deletion cocoa/NSViewController.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package cocoa
type NSViewController struct{ gen_NSViewController }

func NSViewController_New() NSViewController {
return NSViewController_Alloc().Init_AsNSViewController()
return NSViewController_Alloc().Init()
}

func (c NSViewController) SetView(v NSView) {
Expand Down
2 changes: 1 addition & 1 deletion cocoa/NSVisualEffectView.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type NSVisualEffectView struct {
}

func NSVisualEffectView_New() NSVisualEffectView {
return NSVisualEffectView_Alloc().Init_AsNSVisualEffectView()
return NSVisualEffectView_Alloc().Init()
}

// effect.Set("translatesAutoresizingMaskIntoConstraints:", false)
Expand Down
8 changes: 2 additions & 6 deletions cocoa/NSWindow.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ type NSWindow struct {
var nsWindow = objc.Get("NSWindow")

func NSWindow_New() NSWindow {
return NSWindow_Alloc().Init_AsNSWindow()
return NSWindow_Alloc().Init()
}

func NSWindow_WithContentViewController(controller NSViewControllerRef) NSWindow {
return NSWindow_WindowWithContentViewController(controller)
}

func NSWindow_Init(rect core.NSRect, windowStyle core.NSUInteger, bufferingType NSBackingStoreType, deferCreation bool) NSWindow {
return NSWindow_Alloc().InitWithContentRectStyleMaskBackingDefer_AsNSWindow(
return NSWindow_Alloc().InitWithContentRectStyleMaskBackingDefer(
rect, core.NSUInteger(windowStyle), core.NSUInteger(bufferingType), deferCreation,
)
}
Expand Down Expand Up @@ -65,10 +65,6 @@ func (w NSWindow) MovableByWindowBackground() bool {
return w.IsMovableByWindowBackground()
}

func (w NSWindow) SetFrameDisplay(frame core.NSRect, display bool) {
w.SetFrameDisplay(frame, display)
}

func (w NSWindow) CollectionBehavior() uint {
return uint(w.gen_NSWindow.CollectionBehavior())
}
Expand Down
Loading

0 comments on commit 8d32f63

Please sign in to comment.