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

feat: add cover color-changing-cover #129

Merged
merged 11 commits into from
Dec 7, 2024

Conversation

enklht
Copy link
Contributor

@enklht enklht commented Dec 3, 2024

This pull request introduces a new (pseudo) semitransparent cover function that provides a method for hiding content in slides. The function changes the text color of elements to a specified color if they contain text. If an element does not contain text, it can use hide as a fallback.

This implementation has been successfully tested with the default examples and the specific example provided in issue #112.

@OrangeX4 OrangeX4 added the enhancement New feature or request label Dec 4, 2024
@OrangeX4 OrangeX4 self-requested a review December 4, 2024 06:22
@OrangeX4
Copy link
Member

OrangeX4 commented Dec 4, 2024

Can we achieve translucency by modifying the alpha value instead of fixing a color? We can think about the hacky code that I have as proof of concept below

#set page(width: 20em, height: auto)

#let update-alpha(constructor: rgb, color, alpha) = constructor(..color.components(alpha: true).slice(0, -1), alpha)

#show par: it => {
  if repr(text.fill).split("(").at(0) == "rgb" {
    set text(fill: update-alpha(text.fill, 50%))
    it
  } else {
    it
  }
}

// ----------------
// content
// ----------------


#set text(rgb("#000000"))

Test

#set text(rgb("#ff0000"))

Test

image

@enklht
Copy link
Contributor Author

enklht commented Dec 4, 2024

What do you think about this approach?

The transparentize method should handle most of the heavy lifting, which means we may not need to rely on many "hacks."

if it.has("child") {
return _contains-text(it.child)
}
if it.has("children") {
Copy link
Member

Choose a reason for hiding this comment

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

The table and grid types also have children, I'm not sure if this should be included?

Copy link
Contributor Author

@enklht enklht Dec 4, 2024

Choose a reason for hiding this comment

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

I understand. It might be good to have an option to toggle the behaviour, or exclude those elements (using util.is-sequence?)

Copy link
Member

Choose a reason for hiding this comment

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

Since the table has borders, we should use util.is-sequence as default, but it can indeed be made into a configuration.

@enklht
Copy link
Contributor Author

enklht commented Dec 4, 2024

Quick Update: I discovered that the new alpha-changing-cover doesn't function perfectly when the text color is modified within the paused items.

see https://typst.app/project/wL4tuMqQ3FQArqLDmRrDj0

@enklht
Copy link
Contributor Author

enklht commented Dec 6, 2024

Update: The enhanced function now provides improved handling of color-changing texts. This is achieved by utilizing the context feature and the update-alpha function. This works well with the example I made the other day.

Note

The decision to use update-alpha instead of transparentize was deliberate. Unlike transparentize, which applies relative changes that can accumulate to cause nested texts to vanish, update-alpha allows to specify absolute text opacities. This approach ensures consistent visibility for nested text elements.

@enklht
Copy link
Contributor Author

enklht commented Dec 6, 2024

While this is slightly tangential to the current PR, I'd like to propose an improvement to the update-alpha function:

#let update-alpha(color, alpha) = color.opacify(100%).transparentize(alpha)

This revised implementation can handle all color constructors uniformly. It first ensures full opacity with opacify(100%), then applies the desired transparency using transparentize(alpha).

@OrangeX4
Copy link
Member

OrangeX4 commented Dec 6, 2024

If update-alpha is used, we need to consider non-rgb cases, like #set text(luma(80%)).

@enklht
Copy link
Contributor Author

enklht commented Dec 6, 2024

My latest proposal addresses that issue!

@OrangeX4
Copy link
Member

OrangeX4 commented Dec 7, 2024

Thanks!

@OrangeX4 OrangeX4 merged commit 9c8f49b into touying-typ:main Dec 7, 2024
@enklht enklht deleted the feature-color-changing-cover branch December 7, 2024 13:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants