Rename background image modes aligned with the CSS standards

This commit is contained in:
yunusey
2025-05-24 00:05:49 -04:00
parent 4541e280a5
commit 72eef89b25
3 changed files with 37 additions and 37 deletions

View File

@ -469,23 +469,23 @@ foreground: Color = .{ .r = 0xFF, .g = 0xFF, .b = 0xFF },
/// ///
/// Valid values are: /// Valid values are:
/// ///
/// * `zoomed` - Image is scaled to fit the window, preserving aspect ratio. /// * `contain` - Image is scaled to fit the window, preserving aspect ratio.
/// * `stretched` - Image is stretched to fill the window, not preserving aspect ratio. /// * `fill` - Image is stretched to fill the window, not preserving aspect ratio.
/// * `cropped` - Image is centered in the window, preserving the aspect ratio /// * `cover` - Image is centered in the window, preserving the aspect ratio
/// but cropping the image to fill the window, as needed. /// but cropping the image to fill the window, as needed.
/// * `tiled` - Image is repeated horizontally and vertically to fill the window. /// * `tiled` - Image is repeated horizontally and vertically to fill the window.
/// * `centered` - Image is centered in the window and displayed 1-to-1 pixel /// * `centered` - Image is centered in the window and displayed 1-to-1 pixel
/// scale, preserving both the aspect ratio and the image size. /// scale, preserving both the aspect ratio and the image size.
/// * `upper-left` - Image is anchored to the upper left corner of the window, /// * `top-left` - Image is anchored to the top left corner of the window,
/// preserving the aspect ratio. /// preserving the aspect ratio.
/// * `upper-right` - Image is anchored to the upper right corner of the window, /// * `top-right` - Image is anchored to the top right corner of the window,
/// preserving the aspect ratio. /// preserving the aspect ratio.
/// * `lower-left` - Image is anchored to the lower left corner of the window, /// * `bottom-left` - Image is anchored to the bottom left corner of the window,
/// preserving the aspect ratio. /// preserving the aspect ratio.
/// * `lower-right` - Image is anchored to the lower right corner of the window, /// * `bottom-right` - Image is anchored to the bottom right corner of the window,
/// preserving the aspect ratio. /// preserving the aspect ratio.
/// ///
@"background-image-mode": BackgroundImageMode = .zoomed, @"background-image-mode": BackgroundImageMode = .contain,
/// The foreground and background color for selection. If this is not set, then /// The foreground and background color for selection. If this is not set, then
/// the selection color is just the inverted window background and foreground /// the selection color is just the inverted window background and foreground
@ -6330,15 +6330,15 @@ pub const AlphaBlending = enum {
/// in sync with the values in the vertex shader used to render the /// in sync with the values in the vertex shader used to render the
/// background image (`bgimage`). /// background image (`bgimage`).
pub const BackgroundImageMode = enum(u8) { pub const BackgroundImageMode = enum(u8) {
zoomed = 0, contain = 0,
stretched = 1, fill = 1,
cropped = 2, cover = 2,
tiled = 3, tiled = 3,
centered = 4, centered = 4,
upper_left = 5, @"top-left" = 5,
upper_right = 6, @"top-right" = 6,
lower_left = 7, @"bottom-left" = 7,
lower_right = 8, @"bottom-right" = 8,
}; };
/// See freetype-load-flag /// See freetype-load-flag

View File

@ -11,7 +11,7 @@ pub const Input = extern struct {
terminal_height: u32 = 0, terminal_height: u32 = 0,
/// uint mode /// uint mode
mode: configpkg.BackgroundImageMode = .zoomed, mode: configpkg.BackgroundImageMode = .contain,
}; };
program: gl.Program, program: gl.Program,

View File

@ -3,15 +3,15 @@
// These are the possible modes that "mode" can be set to. // These are the possible modes that "mode" can be set to.
// //
// NOTE: this must be kept in sync with the BackgroundImageMode // NOTE: this must be kept in sync with the BackgroundImageMode
const uint MODE_ZOOMED = 0u; const uint MODE_CONTAIN = 0u;
const uint MODE_STRETCHED = 1u; const uint MODE_FILL = 1u;
const uint MODE_CROPPED = 2u; const uint MODE_COVER = 2u;
const uint MODE_TILED = 3u; const uint MODE_TILED = 3u;
const uint MODE_CENTERED = 4u; const uint MODE_CENTERED = 4u;
const uint MODE_UPPER_LEFT = 5u; const uint MODE_TOP_LEFT = 5u;
const uint MODE_UPPER_RIGHT = 6u; const uint MODE_TOP_RIGHT = 6u;
const uint MODE_LOWER_LEFT = 7u; const uint MODE_BOTTOM_LEFT = 7u;
const uint MODE_LOWER_RIGHT = 8u; const uint MODE_BOTTOM_RIGHT = 8u;
layout (location = 0) in vec2 terminal_size; layout (location = 0) in vec2 terminal_size;
layout (location = 1) in uint mode; layout (location = 1) in uint mode;
@ -40,7 +40,7 @@ void main() {
); );
switch (mode) { switch (mode) {
case MODE_ZOOMED: case MODE_CONTAIN:
// If zoomed, we want to scale the image to fit the terminal // If zoomed, we want to scale the image to fit the terminal
if (aspect_ratio.x > aspect_ratio.y) { if (aspect_ratio.x > aspect_ratio.y) {
scale.x = aspect_ratio.y / aspect_ratio.x; scale.x = aspect_ratio.y / aspect_ratio.x;
@ -49,7 +49,7 @@ void main() {
scale.y = aspect_ratio.x / aspect_ratio.y; scale.y = aspect_ratio.x / aspect_ratio.y;
} }
break; break;
case MODE_CROPPED: case MODE_COVER:
// If cropped, we want to scale the image to fit the terminal // If cropped, we want to scale the image to fit the terminal
if (aspect_ratio.x < aspect_ratio.y) { if (aspect_ratio.x < aspect_ratio.y) {
scale.x = aspect_ratio.y / aspect_ratio.x; scale.x = aspect_ratio.y / aspect_ratio.x;
@ -59,16 +59,16 @@ void main() {
} }
break; break;
case MODE_CENTERED: case MODE_CENTERED:
case MODE_UPPER_LEFT: case MODE_TOP_LEFT:
case MODE_UPPER_RIGHT: case MODE_TOP_RIGHT:
case MODE_LOWER_LEFT: case MODE_BOTTOM_LEFT:
case MODE_LOWER_RIGHT: case MODE_BOTTOM_RIGHT:
// If centered, the final scale of the image should match the actual // If centered, the final scale of the image should match the actual
// size of the image and should be centered // size of the image and should be centered
scale.x = image_size.x / terminal_size.x; scale.x = image_size.x / terminal_size.x;
scale.y = image_size.y / terminal_size.y; scale.y = image_size.y / terminal_size.y;
break; break;
case MODE_STRETCHED: case MODE_FILL:
case MODE_TILED: case MODE_TILED:
// We don't need to do anything for stretched or tiled // We don't need to do anything for stretched or tiled
break; break;
@ -77,23 +77,23 @@ void main() {
vec2 final_image_size = terminal_size * position * scale; vec2 final_image_size = terminal_size * position * scale;
vec2 offset = vec2(0.0, 0.0); vec2 offset = vec2(0.0, 0.0);
switch (mode) { switch (mode) {
case MODE_ZOOMED: case MODE_CONTAIN:
case MODE_STRETCHED: case MODE_FILL:
case MODE_CROPPED: case MODE_COVER:
case MODE_TILED: case MODE_TILED:
case MODE_CENTERED: case MODE_CENTERED:
offset = (terminal_size * (1.0 - scale)) / 2.0; offset = (terminal_size * (1.0 - scale)) / 2.0;
break; break;
case MODE_UPPER_LEFT: case MODE_TOP_LEFT:
offset = vec2(0.0, 0.0); offset = vec2(0.0, 0.0);
break; break;
case MODE_UPPER_RIGHT: case MODE_TOP_RIGHT:
offset = vec2(terminal_size.x - image_size.x, 0.0); offset = vec2(terminal_size.x - image_size.x, 0.0);
break; break;
case MODE_LOWER_LEFT: case MODE_BOTTOM_LEFT:
offset = vec2(0.0, terminal_size.y - image_size.y); offset = vec2(0.0, terminal_size.y - image_size.y);
break; break;
case MODE_LOWER_RIGHT: case MODE_BOTTOM_RIGHT:
offset = vec2(terminal_size.x - image_size.x, terminal_size.y - image_size.y); offset = vec2(terminal_size.x - image_size.x, terminal_size.y - image_size.y);
break; break;
} }