Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compute background dimensions preserving aspect ratio. #6504

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions wezterm-gui/src/termwindow/background.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,16 +488,32 @@ impl crate::TermWindow {
} else {
((pixel_height * aspect).floor(), pixel_height)
};

let computed_background_height = match layer.def.height {
BackgroundSize::Cover => match layer.def.width {
BackgroundSize::Dimension(n) => (n.evaluate_as_pixels(h_context) / aspect) as f32,
_ => min_aspect_height,
}
_ => min_aspect_height,
};

let computed_background_width = match layer.def.width {
BackgroundSize::Cover => match layer.def.height {
BackgroundSize::Dimension(n) => (n.evaluate_as_pixels(v_context) * aspect).floor(),
_ => min_aspect_width,
}
_ => min_aspect_width,
};

let width = match layer.def.width {
BackgroundSize::Contain => max_aspect_width as f32,
BackgroundSize::Cover => min_aspect_width as f32,
BackgroundSize::Cover => computed_background_width as f32,
BackgroundSize::Dimension(n) => n.evaluate_as_pixels(h_context),
};

let height = match layer.def.height {
BackgroundSize::Contain => max_aspect_height as f32,
BackgroundSize::Cover => min_aspect_height as f32,
BackgroundSize::Cover => computed_background_height as f32,
BackgroundSize::Dimension(n) => n.evaluate_as_pixels(v_context),
};

Expand Down