fix(dur): apply correct offset for animations bigger than the terminal

Animations bigger than the rendering area would have an alignment to the
top left instead of center.
This commit is contained in:
Titanium Brain 2026-04-25 13:03:17 +01:00
commit 2792381af4

View file

@ -358,11 +358,8 @@ fn calc_start_position(terminal_buffer: *TerminalBuffer, dur_movie: *DurFormat,
const buf_width: u32 = @intCast(terminal_buffer.width);
const buf_height: u32 = @intCast(terminal_buffer.height);
var movie_width: u32 = dur_movie.columns;
var movie_height: u32 = dur_movie.lines;
if (movie_width > buf_width) movie_width = buf_width;
if (movie_height > buf_height) movie_height = buf_height;
const movie_width: u32 = dur_movie.columns;
const movie_height: u32 = dur_movie.lines;
const start_pos: IVec2 = switch (offset_alignment) {
DurOffsetAlignment.center => .{ center(buf_width) - center(movie_width), center(buf_height) - center(movie_height) },
@ -545,14 +542,14 @@ fn draw(self: *DurFile) void {
const buf_height: u32 = @intCast(self.terminal_buffer.height);
// y is used as an iterator in the durformat, while cell_y gives us the correct placement for the cell (same for x)
for (0..self.frame_size[VEC_Y]) |y| {
for (@max(0, -self.start_pos[VEC_Y])..@intCast(self.frame_size[VEC_Y])) |y| {
const y_offset_i = @as(i32, @intCast(y)) + self.start_pos[VEC_Y];
// we skip the pass if it falls outside of the draw window (ensure no int underflow)
const cell_y: u32 = if (y_offset_i >= 0 and y_offset_i < buf_height) @intCast(y_offset_i) else continue;
var iter = std.unicode.Utf8View.initUnchecked(current_frame.contents[y]).iterator();
for (0..self.frame_size[VEC_X]) |x| {
for (@max(0, -self.start_pos[VEC_X])..@intCast(self.frame_size[VEC_X])) |x| {
const x_offset_i = @as(i32, @intCast(x)) + self.start_pos[VEC_X];
// skip pass, same as y but also increment the codepoint iter to fetch correct values in later passes
const cell_x: u32 = if (x_offset_i >= 0 and x_offset_i < buf_width) @intCast(x_offset_i) else {