Browse Source

Add `new` shorthand

gingerBill 3 years ago
parent
commit
2958c1d6aa
2 changed files with 29 additions and 21 deletions
  1. 3 0
      core/sys/darwin/Foundation/NSObject.odin
  2. 26 21
      core/sys/darwin/Foundation/NSWindow.odin

+ 3 - 0
core/sys/darwin/Foundation/NSObject.odin

@@ -31,6 +31,9 @@ copy :: proc(self: ^Copying($T)) -> ^T where intrinsics.type_is_subtype_of(T, Ob
 	return msgSend(^T, self, "copy")
 }
 
+new :: proc($T: typeid) -> ^T where intrinsics.type_is_subtype_of(T, Object) {
+	return init(alloc(T))
+}
 
 @(objc_type=Object, objc_name="retain")
 retain :: proc(self: ^Object) {

+ 26 - 21
core/sys/darwin/Foundation/NSWindow.odin

@@ -19,6 +19,32 @@ Responder :: struct {using _: Object}
 @(objc_class="NSView")
 View :: struct {using _: Responder}
 
+@(objc_type=View, objc_name="layer")
+View_layer :: proc(self: ^View) -> ^Layer {
+	return msgSend(^Layer, self, "layer")
+}
+
+@(objc_type=View, objc_name="setLayer")
+View_setLayer :: proc(self: ^View, layer: ^Layer) {
+	msgSend(nil, self, "setLayer:", layer)
+}
+@(objc_type=View, objc_name="setSubLayer")
+View_setSubLayer :: proc(self: ^View, layer: ^Layer) {
+	msgSend(nil, self, "setSubLayer:", layer)
+}
+
+
+@(objc_type=View, objc_name="wantsLayer")
+View_wantsLayer :: proc(self: ^View) -> BOOL {
+	return msgSend(BOOL, self, "wantsLayer")
+}
+
+@(objc_type=View, objc_name="setWantsLayer")
+View_setWantsLayer :: proc(self: ^View, wantsLayer: BOOL) {
+	msgSend(nil, self, "setWantsLayer:", wantsLayer)
+}
+
+
 @(objc_class="NSWindow")
 Window :: struct {using _: Responder}
 
@@ -45,7 +71,6 @@ Window_setOpaque :: proc(self: ^Window, ok: NS.BOOL) {
 	msgSend(nil, self, "setOpaque:", ok)
 }
 
-
 @(objc_type=Window, objc_name="backgroundColor")
 Window_backgroundColor :: proc(self: ^Window) -> ^NS.Color {
 	return msgSend(^NS.Color, self, "backgroundColor")
@@ -54,23 +79,3 @@ Window_backgroundColor :: proc(self: ^Window) -> ^NS.Color {
 Window_setBackgroundColor :: proc(self: ^Window, color: ^NS.Color) {
 	msgSend(nil, self, "setBackgroundColor:", color)
 }
-
-@(objc_type=View, objc_name="layer")
-View_layer :: proc(self: ^View) -> ^Layer {
-	return msgSend(^Layer, self, "layer")
-}
-
-@(objc_type=View, objc_name="setLayer")
-View_setLayer :: proc(self: ^View, layer: ^Layer) {
-	msgSend(nil, self, "setLayer:", layer)
-}
-
-@(objc_type=View, objc_name="wantsLayer")
-View_wantsLayer :: proc(self: ^View) -> BOOL {
-	return msgSend(BOOL, self, "wantsLayer")
-}
-
-@(objc_type=View, objc_name="setWantsLayer")
-View_setWantsLayer :: proc(self: ^View, wantsLayer: BOOL) {
-	msgSend(nil, self, "setWantsLayer:", wantsLayer)
-}