apprt: window size limits

This commit is contained in:
Mitchell Hashimoto
2022-12-30 15:36:25 -08:00
parent d5895f9034
commit b502d5aa7d
2 changed files with 21 additions and 5 deletions

View File

@ -379,11 +379,10 @@ pub fn create(alloc: Allocator, app: *App, config: *const Config) !*Window {
// Set a minimum size that is cols=10 h=4. This matches Mac's Terminal.app
// but is otherwise somewhat arbitrary.
// TODO:
// try window.setSizeLimits(.{
// .width = @floatToInt(u32, cell_size.width * 10),
// .height = @floatToInt(u32, cell_size.height * 4),
// }, .{ .width = null, .height = null });
try window.setSizeLimits(.{
.width = @floatToInt(u32, cell_size.width * 10),
.height = @floatToInt(u32, cell_size.height * 4),
}, null);
// Call our size callback which handles all our retina setup
// Note: this shouldn't be necessary and when we clean up the window

View File

@ -149,6 +149,23 @@ pub const Window = struct {
}
}
/// Set the size limits of the window.
/// Note: this interface is not good, we should redo it if we plan
/// to use this more. i.e. you can't set max width but no max height,
/// or no mins.
pub fn setSizeLimits(self: *Window, min: apprt.WindowSize, max_: ?apprt.WindowSize) !void {
try self.window.setSizeLimits(.{
.width = min.width,
.height = min.height,
}, if (max_) |max| .{
.width = max.width,
.height = max.height,
} else .{
.width = null,
.height = null,
});
}
/// Returns the content scale for the created window.
pub fn getContentScale(self: *const Window) !apprt.ContentScale {
const scale = try self.window.getContentScale();