Pablo-Gonzalez-Calderon / showybox-package

A Typst package for creating colorful and customizable boxes
MIT License
60 stars 5 forks source link

Title box anchor doesn't work in figures #24

Closed WannesMalfait closed 1 year ago

WannesMalfait commented 1 year ago

Problem

When a showybox is placed inside a figure, the title box is not positioned correctly. The shadow does seem to be positioned correctly however.

How to reproduce

This is a very simple example to reproduce the issue:

#import "@preview/showybox:2.0.0" : *

#let test() = showybox(
  title-style: (boxed-style: (anchor: (x: center, y: bottom))),
  title: "Title",
  shadow: (offset: 3pt), // Just here to show that shadows are placed correctly
)[#lorem(5)]

#test()
#figure[#test()]

The difference in output between the two versions

Additional info

I came across this issue when using the Lemmify package, which internally places content inside figures to be able to reference them easily.

Pablo-Gonzalez-Calderon commented 1 year ago

Yes, it seems to be an issue with figures. Issue #23 also mentioned something similar.

I'll take a look to this during the day to find a solution.

Thank you for reporting this bug! 😁

Pablo-Gonzalez-Calderon commented 1 year ago

I've found an extra line that causes the bug. Probably it was left there during a refactorization of title rendering. Now it seems that the title is well-placed inside and outside a figure.

For more details, this was the extra line:

...
place(
  top + props.title-style.boxed-style.anchor.x,
  dx: props.title-style.boxed-style.offset.x,
  dy: props.title-style.boxed-style.offset.y + if props.title-style.boxed-style.anchor.y == bottom {
    -my-state.final(loc)
  } else if props.title-style.boxed-style.anchor.y == horizon {
    -my-state.final(loc)/2
  },
  block(
    width: 100%, // <- Here. This was forcing the block to be 100% width, so the ``place`` won't take a visible effect on moving it
    spacing: 0pt,
    inset: (x: 1em),
    showy-title(props)
  )
)

Tell me if it now works for you to mark this as closed 🧐

Pablo-Gonzalez-Calderon commented 1 year ago

Small note: Now showybox's latest version is 2.0.1 (locally, in this repository). So, if you try the new changes using showybox as a local package, don't forget to use #import "@preview/showybox:2.0.1" : * instead of #import "@preview/showybox:2.0.0" : *

WannesMalfait commented 1 year ago

Works perfectly! (I just changed the one line in my preview folder). Will update to 2.0.1 when it is released. Thanks for the quick fix