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

True semitransparency during uncover #91

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

ntjess
Copy link
Contributor

@ntjess ntjess commented Aug 29, 2023

Fix #17 by providing a more generalized cover function. Works with several content types (not just text) and on several background colors instead of assuming white. Sample usage:

#import "polylux.typ": *

#set page(width: 2in, height: 2.2in, background: rect(width: 100%, height: 100%))

#let slide = polylux-slide

#let img = image("assets/logo.png", height: 0.5in)


#slide[
  = Hello, world

  #uncover(2, mode: "transparent", img)

  #set text(fill: white)
  #let bg(fill, h: 45%) = place(rect(width: 100%, height: h, fill: fill))

  // Typst `green` is not true green
  #add-hider-mode("green", cover-with-rect.with(fill: rgb(46, 204, 64, 90%)))
  // Use "transparent" on black background as default when no
  // mode is specified
  #add-hider-mode("default", logic.cover-with-black-rect)
  #bg(black)
  #uncover(2, [Some text])
  #side-by-side[
    #uncover(2, img)
  ][
    // Let the user specify their own modes when operating on nonstandard background
    // colors
    #uncover(2, mode: "green", box(img, fill: green, outset: 1em))
  ]
]

Produces:
image

@andreasKroepelin
Copy link
Owner

I tried this myself already but never got the positioning of the covering rect right! So stack seems to be the magic ingredient... Very cool. I will take a closer look at this soon.

For instance, if an object to be hidden spans two background colors, you can specify `(fill: "000d", stroke: (bottom: rgb("fffd) + 0.2in))` to have the cover work even in that case

"width" and "height" can also be directly overridden in cases where their defaults don't work properly, e.g. with heavy strokes of slanted lines
This will more closely match the current default of `gray.lighten(50%)`
Convenient for one-time background colors that shouldn't incur a cumbersome registration to global state
This allows inline content to remain inline after being covered
Consider the case of `cover-with-rect(block(...))`. This should explicitly be in its own block, but adding a box deterministically inside `cover` will promote this to inline content. Providing an optional argument allows block-level content to stay that way if desired. "inline" is still a sensible default, since paragraph breaks around a box will allow it to be its own block anyway.
@ntjess
Copy link
Contributor Author

ntjess commented Sep 25, 2023

Out of curiosity, any movement on reviewing this PR?

@andreasKroepelin
Copy link
Owner

Not yet, sorry. I am quite busy at the moment.

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.

Make transparent covering actually transparent
2 participants