Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf9f12b4

Browse files
committed
macos: implement Window functions
1 parentfef5e8c commitf9f12b4

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

‎examples/test-backend.zig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ pub fn main() !void {
1010
capy.row(.{}, .{}),
1111
);
1212

13-
// window.resize(800, 450);
13+
window.setTitle("Basic Backend Test");
14+
window.setPreferredSize(800,450);
1415
window.show();
1516
capy.runEventLoop();
1617
}

‎src/backends/macos/backend.zig

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -138,22 +138,20 @@ pub const Window = struct {
138138
}
139139

140140
pubfnresize(self:*Window,width:c_int,height:c_int)void {
141-
_=height;
142-
_=width;
143-
_=self;
144-
// const frame = objc.NSRect.make(
145-
// 100,
146-
// 100,
147-
// @as(objc.CGFloat, @floatFromInt(width)),
148-
// @as(objc.CGFloat, @floatFromInt(height)),
149-
// );
150-
// // TODO: resize animation can be handled using a DataWrapper on the user-facing API
151-
// _ = objc.msgSendByName(void, self.peer, "setFrame:display:", .{ frame, true }) catch unreachable;
141+
varframe=self.peer.getProperty(AppKit.NSRect,"frame");
142+
frame.size.width=@floatFromInt(width);
143+
frame.size.height=@floatFromInt(height);
144+
self.peer.msgSend(void,"setFrame:display:", .{frame,true });
152145
}
153146

154147
pubfnsetTitle(self:*Window,title: [*:0]constu8)void {
155-
_=self;
156-
_=title;
148+
constpool=objc.AutoreleasePool.init();
149+
deferpool.deinit();
150+
151+
constNSString=objc.getClass("NSString").?;
152+
conststring=NSString.msgSend(objc.Object,"alloc", .{})
153+
.msgSend(objc.Object,"initWithUTF8String:", .{title});
154+
self.peer.setProperty("title",string);
157155
}
158156

159157
pubfnsetChild(self:*Window,peer:?PeerType)void {
@@ -174,8 +172,8 @@ pub const Window = struct {
174172
}
175173

176174
pubfnclose(self:*Window)void {
177-
_=self;
178-
@panic("TODO: close window");
175+
self.peer.msgSend(void,"close", .{});
176+
_=activeWindows.fetchSub(1,.Release);
179177
}
180178
};
181179

@@ -233,10 +231,9 @@ pub fn runStep(step: shared.EventLoopStep) bool {
233231
constapp=NSApplication.msgSend(objc.Object,"sharedApplication", .{});
234232
if (!finishedLaunching) {
235233
finishedLaunching=true;
236-
// app.msgSend(void, "finishLaunching", .{});
237234
if (step==.Blocking) {
238235
// Run the NSApplication and stop it immediately using the delegate.
239-
// This is a similar technique to what GLFW does (see cocoa_window.m)
236+
// This is a similar technique to what GLFW does (see cocoa_window.m in GLFW's source code)
240237
app.msgSend(void,"run", .{});
241238
}
242239
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp