Skip to content

Added to-absolute method to length.#3117

Merged
laurmaedje merged 12 commits into
typst:mainfrom
Dherse:len-resolve
Jan 3, 2024
Merged

Added to-absolute method to length.#3117
laurmaedje merged 12 commits into
typst:mainfrom
Dherse:len-resolve

Conversation

@Dherse

@Dherse Dherse commented Jan 1, 2024

Copy link
Copy Markdown
Contributor

Adds the .to-absolute(styles) method to length to allow retrieving a length as absolute (without the em part) when in the right context.

This changes fixes packages like tablex (https://github.com/PgBiel/typst-tablex) that use the following code:

#let measure-pt(len, styles) = {
    let measured-pt = measure(box(width: len), styles).width

    if measured-pt > 0pt {
        return measured-pt
    }

    measured-pt = -measure(box(width: -len), styles).width
    return measured-pt
}

@laurmaedje laurmaedje left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm okay with adding this, but think we should discuss the name a bit. resolve is quite generic. Maybe we can find a name that describes more concretely what is happening.

Comment thread crates/typst/src/layout/length.rs Outdated
@istudyatuni

Copy link
Copy Markdown
Contributor

measure, but as a method?

@Dherse Dherse changed the title Added resolve method to length. Added to-absolute method to length. Jan 2, 2024
@Dherse

Dherse commented Jan 2, 2024

Copy link
Copy Markdown
Contributor Author

measure, but as a method?

We discussed this on Discord quickly with @laurmaedje and agreed that to-absolute was a better name since resolve is too generic and measure carries a different meaning.

@laurmaedje laurmaedje enabled auto-merge January 3, 2024 09:41
@laurmaedje

Copy link
Copy Markdown
Member

Thanks!

@laurmaedje laurmaedje added this pull request to the merge queue Jan 3, 2024
Merged via the queue into typst:main with commit 3aeb150 Jan 3, 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.

3 participants