@@ -8,8 +8,9 @@ const EventFunctions = shared.EventFunctions(@This());
88const EventType = shared .BackendEventType ;
99const BackendError = shared .BackendError ;
1010const MouseButton = shared .MouseButton ;
11- //pub const PeerType = *c.GtkWidget;
12- pub const PeerType = * opaque {};
11+
12+ // pub const PeerType = *opaque {};
13+ pub const PeerType = objc .id ;
1314
1415var activeWindows = std .atomic .Atomic (usize ).init (0 );
1516var hasInit : bool = false ;
@@ -40,14 +41,62 @@ pub const EventUserData = struct {
4041 focusOnClick : bool = false ,
4142};
4243
44+ var test_data = EventUserData { .peer = undefined };
4345pub inline fn getEventUserData (peer : PeerType ) * EventUserData {
4446 _ = peer ;
47+ return & test_data ;
4548 //return @ptrCast(*EventUserData, @alignCast(@alignOf(EventUserData), c.g_object_get_data(@ptrCast(*c.GObject, peer), "eventUserData").?));
4649}
4750
4851pub fn Events (comptime T : type ) type {
49- _ = T ;
50- return struct {};
52+ return struct {
53+ const Self = @This ();
54+
55+ pub fn setUserData (self : * T , data : anytype ) void {
56+ comptime {
57+ if (! std .meta .trait .isSingleItemPtr (@TypeOf (data ))) {
58+ @compileError (std .fmt .comptimePrint ("Expected single item pointer, got {s}" , .{@typeName (@TypeOf (data ))}));
59+ }
60+ }
61+
62+ getEventUserData (self .peer ).userdata = @intFromPtr (data );
63+ }
64+
65+ pub inline fn setCallback (self : * T , comptime eType : EventType , cb : anytype ) ! void {
66+ const data = & getEventUserData (self .peer ).user ;
67+ switch (eType ) {
68+ .Click = > data .clickHandler = cb ,
69+ .Draw = > data .drawHandler = cb ,
70+ .MouseButton = > data .mouseButtonHandler = cb ,
71+ .MouseMotion = > data .mouseMotionHandler = cb ,
72+ .Scroll = > data .scrollHandler = cb ,
73+ .TextChanged = > data .changedTextHandler = cb ,
74+ .Resize = > data .resizeHandler = cb ,
75+ .KeyType = > data .keyTypeHandler = cb ,
76+ .KeyPress = > data .keyPressHandler = cb ,
77+ .PropertyChange = > data .propertyChangeHandler = cb ,
78+ }
79+ }
80+
81+ pub fn setOpacity (self : * const T , opacity : f32 ) void {
82+ _ = opacity ;
83+ _ = self ;
84+ }
85+
86+ pub fn getWidth (self : * const T ) u32 {
87+ _ = self ;
88+ return 100 ;
89+ }
90+
91+ pub fn getHeight (self : * const T ) u32 {
92+ _ = self ;
93+ return 100 ;
94+ }
95+
96+ pub fn deinit (self : * const T ) void {
97+ _ = self ;
98+ }
99+ };
51100}
52101
53102pub const Window = struct {
@@ -59,8 +108,8 @@ pub const Window = struct {
59108
60109 pub fn create () BackendError ! Window {
61110 const NSWindow = objc .getClass ("NSWindow" ) catch return BackendError .InitializationError ;
62- const rect = objc .NSRectMake (100 , 100 , 200 , 200 );
63- const style = AppKit .NSWindowStyleMask .Titled | AppKit .NSWindowStyleMask .Closable | AppKit .NSWindowStyleMask .Miniaturizable | AppKit .NSWindowStyleMask .Resizable ;
111+ const rect = objc .NSRect . make (100 , 100 , 200 , 200 );
112+ const style = AppKit .NSWindowStyleMask .Titled | AppKit .NSWindowStyleMask .Closable | AppKit .NSWindowStyleMask .Miniaturizable | AppKit .NSWindowStyleMask .Resizable | AppKit . NSWindowStyleMask . FullSizeContentView ;
64113
65114 std .log .info ("make new rect" , .{});
66115 const newRect = objc .msgSendByName (objc .NSRect , NSWindow , "frameRectForContentRect:styleMask:" , .{ rect , style }) catch unreachable ;
@@ -82,7 +131,12 @@ pub const Window = struct {
82131 }
83132
84133 pub fn resize (self : * Window , width : c_int , height : c_int ) void {
85- const frame = objc .NSRectMake (100 , 100 , @as (objc .CGFloat , @floatFromInt (width )), @as (objc .CGFloat , @floatFromInt (height )));
134+ const frame = objc .NSRect .make (
135+ 100 ,
136+ 100 ,
137+ @as (objc .CGFloat , @floatFromInt (width )),
138+ @as (objc .CGFloat , @floatFromInt (height )),
139+ );
86140 // TODO: resize animation can be handled using a DataWrapper on the user-facing API
87141 _ = objc .msgSendByName (void , self .peer , "setFrame:display:" , .{ frame , true }) catch unreachable ;
88142 }
@@ -106,6 +160,7 @@ pub const Window = struct {
106160
107161 pub fn show (self : * Window ) void {
108162 std .log .info ("show window" , .{});
163+ objc .msgSendByName (void , self .peer , "setIsVisible:" , .{ @as (objc .id , self .peer ), @as (u8 , @intFromBool (true )) }) catch unreachable ;
109164 objc .msgSendByName (void , self .peer , "makeKeyAndOrderFront:" , .{@as (objc .id , self .peer )}) catch unreachable ;
110165 std .log .info ("showed window" , .{});
111166 _ = activeWindows .fetchAdd (1 , .Release );
@@ -117,6 +172,51 @@ pub const Window = struct {
117172 }
118173};
119174
175+ pub const Container = struct {
176+ peer : objc.id ,
177+
178+ pub usingnamespace Events (Container );
179+
180+ pub fn create () BackendError ! Container {
181+ return Container { .peer = undefined };
182+ }
183+
184+ pub fn add (self : * const Container , peer : PeerType ) void {
185+ _ = peer ;
186+ _ = self ;
187+ }
188+
189+ pub fn remove (self : * const Container , peer : PeerType ) void {
190+ _ = peer ;
191+ _ = self ;
192+ }
193+
194+ pub fn move (self : * const Container , peer : PeerType , x : u32 , y : u32 ) void {
195+ _ = y ;
196+ _ = x ;
197+ _ = peer ;
198+ _ = self ;
199+ }
200+
201+ pub fn resize (self : * const Container , peer : PeerType , w : u32 , h : u32 ) void {
202+ _ = h ;
203+ _ = w ;
204+ _ = peer ;
205+ _ = self ;
206+ }
207+
208+ pub fn setTabOrder (self : * const Container , peers : []const PeerType ) void {
209+ _ = peers ;
210+ _ = self ;
211+ }
212+ };
213+
214+ pub const Canvas = struct {
215+ pub usingnamespace Events (Canvas );
216+
217+ pub const DrawContext = struct {};
218+ };
219+
120220pub fn postEmptyEvent () void {
121221 @panic ("TODO: postEmptyEvent" );
122222}
0 commit comments