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

Conversation

jaanauati
Copy link

@jaanauati jaanauati commented Dec 22, 2024

Compute background dimensions preserving original aspect ratio.

The problem I'm trying to solve:

In my config I'm setting many different backgrounds, for all of them I'm typically setting custom width and height, so for each one of them I have to manually compute the right values based on aspect ratio. And since my images have different aspect ratios I'm find the process a bit tedious.

Current Behavior

Currently, wezterm supports size="Cover" which, as the documentation states: "scales the image to the smallest possible size to fill the viewport".

What I'm doing in this changeset?

In this PR I'm adding additional behavior for the mentioned unit, so, If only one of the dimension attributes is set to Cover (example height=Cover, width=200), the value of the mentioned attribute will be computed based on the dimension assigned to the other one, and of course, preserving the aspect ratio.

BTW, even though I used to do C many (many) years ago, I'm not familiar with rust AT ALL (I'm just learning some bits today after reading your code), so bear with me if things are not good enough.

Are there any other ways to approach this use-case?

Yeah, we could also introduce a new unit type?, example width="auto", but I was not sure so I decided to keep this simple, (to me, the current approach in this PR makes sense and feels like easy to use).

Examples:

1) Compute height based image width:

Here I'm setting an arbitrary width = 550px while I set height=Cover.

    background = {
        source = {
            File = wezterm.config_dir .. "/backgrounds/1.png",
        },
        vertical_align = "Bottom",
        horizontal_align = "Right",
        width = "550", 
	height = "Cover",
        repeat_x = "NoRepeat",
        repeat_y = "NoRepeat",
    },

Before:

image

After:

image

2) Compute correct width based on user provided height:

    background = {
        source = {
            File = wezterm.config_dir .. "/backgrounds/1.png",
        },
        vertical_align = "Bottom",
        horizontal_align = "Right",
        width = "Cover", 
        height = "754.6",
	width = "Cover",
        repeat_x = "NoRepeat",
        repeat_y = "NoRepeat",
    },

Before:

image

After:

image

@jaanauati jaanauati force-pushed the feature-dynamic-background-size branch from 504e5ea to c925a53 Compare December 22, 2024 00:53
@jaanauati jaanauati changed the title [Draft] Compute background dimensions preserving aspect ratio. Compute background dimensions preserving aspect ratio. Dec 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant