mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-20 10:46:07 +03:00
renderer: change padding to integers
Screen size is always an integer, it makes sense for padding to also be rounded to some integer.
This commit is contained in:
@ -344,8 +344,14 @@ pub fn init(
|
|||||||
const cell_size = try renderer.CellSize.init(alloc, font_group);
|
const cell_size = try renderer.CellSize.init(alloc, font_group);
|
||||||
|
|
||||||
// Convert our padding from points to pixels
|
// Convert our padding from points to pixels
|
||||||
const padding_x = std.math.floor((@as(f32, @floatFromInt(config.@"window-padding-x")) * x_dpi) / 72);
|
const padding_x: u32 = padding_x: {
|
||||||
const padding_y = std.math.floor((@as(f32, @floatFromInt(config.@"window-padding-y")) * y_dpi) / 72);
|
const padding_x: f32 = @floatFromInt(config.@"window-padding-x");
|
||||||
|
break :padding_x @intFromFloat(@floor(padding_x * x_dpi / 72));
|
||||||
|
};
|
||||||
|
const padding_y: u32 = padding_y: {
|
||||||
|
const padding_y: f32 = @floatFromInt(config.@"window-padding-y");
|
||||||
|
break :padding_y @intFromFloat(@floor(padding_y * y_dpi / 72));
|
||||||
|
};
|
||||||
const padding: renderer.Padding = .{
|
const padding: renderer.Padding = .{
|
||||||
.top = padding_y,
|
.top = padding_y,
|
||||||
.bottom = padding_y,
|
.bottom = padding_y,
|
||||||
@ -2102,8 +2108,8 @@ fn posToViewport(self: Surface, xpos: f64, ypos: f64) terminal.point.Viewport {
|
|||||||
// amount from the renderer. This is a bug but realistically balanced
|
// amount from the renderer. This is a bug but realistically balanced
|
||||||
// padding is so small it doesn't affect selection. This may not be true
|
// padding is so small it doesn't affect selection. This may not be true
|
||||||
// at large font sizes...
|
// at large font sizes...
|
||||||
const xpos_adjusted: f64 = xpos - @as(f64, @floatCast(self.padding.left));
|
const xpos_adjusted: f64 = xpos - @as(f64, @floatFromInt(self.padding.left));
|
||||||
const ypos_adjusted: f64 = ypos - @as(f64, @floatCast(self.padding.top));
|
const ypos_adjusted: f64 = ypos - @as(f64, @floatFromInt(self.padding.top));
|
||||||
|
|
||||||
// xpos and ypos can be negative if while dragging, the user moves the
|
// xpos and ypos can be negative if while dragging, the user moves the
|
||||||
// mouse off the surface. Likewise, they can be larger than our surface
|
// mouse off the surface. Likewise, they can be larger than our surface
|
||||||
|
@ -821,10 +821,10 @@ pub fn setScreenSize(self: *Metal, dim: renderer.ScreenSize) !void {
|
|||||||
const old = self.uniforms;
|
const old = self.uniforms;
|
||||||
self.uniforms = .{
|
self.uniforms = .{
|
||||||
.projection_matrix = math.ortho2d(
|
.projection_matrix = math.ortho2d(
|
||||||
-1 * padding.left,
|
-1 * @as(f32, @floatFromInt(padding.left)),
|
||||||
@as(f32, @floatFromInt(padded_dim.width)) + padding.right,
|
@floatFromInt(padded_dim.width + padding.right),
|
||||||
@as(f32, @floatFromInt(padded_dim.height)) + padding.bottom,
|
@floatFromInt(padded_dim.height + padding.bottom),
|
||||||
-1 * padding.top,
|
-1 * @as(f32, @floatFromInt(padding.top)),
|
||||||
),
|
),
|
||||||
.cell_size = .{
|
.cell_size = .{
|
||||||
@floatFromInt(self.cell_size.width),
|
@floatFromInt(self.cell_size.width),
|
||||||
|
@ -146,10 +146,10 @@ const SetScreenSize = struct {
|
|||||||
|
|
||||||
// 2D orthographic projection with the full w/h
|
// 2D orthographic projection with the full w/h
|
||||||
math.ortho2d(
|
math.ortho2d(
|
||||||
-1 * padding.left,
|
-1 * @as(f32, @floatFromInt(padding.left)),
|
||||||
@as(f32, @floatFromInt(padded_size.width)) + padding.right,
|
@floatFromInt(padded_size.width + padding.right),
|
||||||
@as(f32, @floatFromInt(padded_size.height)) + padding.bottom,
|
@floatFromInt(padded_size.height + padding.bottom),
|
||||||
-1 * padding.top,
|
-1 * @as(f32, @floatFromInt(padding.top)),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -48,8 +48,8 @@ pub const ScreenSize = struct {
|
|||||||
/// Subtract padding from the screen size.
|
/// Subtract padding from the screen size.
|
||||||
pub fn subPadding(self: ScreenSize, padding: Padding) ScreenSize {
|
pub fn subPadding(self: ScreenSize, padding: Padding) ScreenSize {
|
||||||
return .{
|
return .{
|
||||||
.width = self.width -| @as(u32, @intFromFloat(padding.left + padding.right)),
|
.width = self.width -| (padding.left + padding.right),
|
||||||
.height = self.height -| @as(u32, @intFromFloat(padding.top + padding.bottom)),
|
.height = self.height -| (padding.top + padding.bottom),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -84,10 +84,10 @@ pub const GridSize = struct {
|
|||||||
|
|
||||||
/// The padding to add to a screen.
|
/// The padding to add to a screen.
|
||||||
pub const Padding = struct {
|
pub const Padding = struct {
|
||||||
top: f32 = 0,
|
top: u32 = 0,
|
||||||
bottom: f32 = 0,
|
bottom: u32 = 0,
|
||||||
right: f32 = 0,
|
right: u32 = 0,
|
||||||
left: f32 = 0,
|
left: u32 = 0,
|
||||||
|
|
||||||
/// Returns padding that balances the whitespace around the screen
|
/// Returns padding that balances the whitespace around the screen
|
||||||
/// for the given grid and cell sizes.
|
/// for the given grid and cell sizes.
|
||||||
@ -117,10 +117,10 @@ pub const Padding = struct {
|
|||||||
|
|
||||||
const zero = @as(f32, 0);
|
const zero = @as(f32, 0);
|
||||||
return .{
|
return .{
|
||||||
.top = @max(zero, padding_top),
|
.top = @intFromFloat(@max(zero, padding_top)),
|
||||||
.bottom = @max(zero, padding_bot),
|
.bottom = @intFromFloat(@max(zero, padding_bot)),
|
||||||
.right = @max(zero, padding_right),
|
.right = @intFromFloat(@max(zero, padding_right)),
|
||||||
.left = @max(zero, padding_left),
|
.left = @intFromFloat(@max(zero, padding_left)),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user