update size

This commit is contained in:
Mitchell Hashimoto
2023-02-17 20:16:20 -08:00
parent cd77408efc
commit 20f76a71ef
2 changed files with 11 additions and 19 deletions

View File

@ -45,7 +45,7 @@ class TerminalSurfaceView_Real: NSView, ObservableObject {
// Setup our surface. This will also initialize all the terminal IO.
var surface_cfg = ghostty_surface_config_s(
nsview: Unmanaged.passUnretained(self).toOpaque(),
scale_factor: 2.0)
scale_factor: 1.0)
guard let surface = ghostty_surface_new(app, &surface_cfg) else {
self.error = AppError.surfaceCreateError
return
@ -59,17 +59,11 @@ class TerminalSurfaceView_Real: NSView, ObservableObject {
}
override func resize(withOldSuperviewSize oldSize: NSSize) {
print("LAYER: \(self.layer?.bounds)")
super.resize(withOldSuperviewSize: oldSize)
print("RESIZE: \(oldSize) NEW: \(self.bounds)")
print("LAYER: \(self.layer?.bounds)")
}
override func draw(_ dirtyRect: NSRect) {
print("DRAW: \(dirtyRect)")
NSColor.green.setFill()
dirtyRect.fill()
super.draw(dirtyRect)
if let surface = self.surface {
ghostty_surface_set_size(surface, UInt32(self.bounds.size.width), UInt32(self.bounds.size.height))
}
}
override func mouseDown(with event: NSEvent) {

View File

@ -51,6 +51,7 @@ pub const Window = struct {
nsview: objc.Object,
scale_factor: f64,
core_win: *CoreWindow,
size: apprt.WindowSize,
pub const Options = extern struct {
/// The pointer to the backing NSView for the surface.
@ -67,6 +68,7 @@ pub const Window = struct {
.core_win = core_win,
.nsview = objc.Object.fromId(opts.nsview),
.scale_factor = opts.scale_factor,
.size = .{ .width = 800, .height = 600 },
};
}
@ -80,11 +82,7 @@ pub const Window = struct {
}
pub fn getSize(self: *const Window) !apprt.WindowSize {
_ = self;
// Initially our window will have a zero size. Until we can determine
// the size of the window, we just send down this value.
return apprt.WindowSize{ .width = 800, .height = 600 };
return self.size;
}
pub fn setSizeLimits(self: *Window, min: apprt.WindowSize, max_: ?apprt.WindowSize) !void {
@ -117,14 +115,14 @@ pub const Window = struct {
return false;
}
pub fn updateSize(self: *const Window, width: u32, height: u32) void {
const size: apprt.WindowSize = .{
pub fn updateSize(self: *Window, width: u32, height: u32) void {
self.size = .{
.width = width,
.height = height,
};
// Call the primary callback.
self.core_win.sizeCallback(size) catch |err| {
self.core_win.sizeCallback(self.size) catch |err| {
log.err("error in size callback err={}", .{err});
return;
};