spirali / nelsie

Framework for Creating Slides
MIT License
39 stars 4 forks source link

Support responsive scaling #20

Open Kobzol opened 4 months ago

Kobzol commented 4 months ago

It is useful to have the ability to re-scale the whole slide deck to a different resolution and/or ratio (e.g. 4:3, 16:9, etc.). While this can be done manually in the Python code, e.g. like this:

foo.box(width=scale_width(500), height=scale_height(500))

The way I do it is that I have some reference resolution (e.g. FullHD), against which I code the contents of my slides, and then some actual resolution, which is rendered by elsie. Before rendering, I recompute all of the values essentially just by dividing FullHD with the actual resolution, to get the final scaled value. In this way I can modify the target render resolution with a one-line change, without modifying the contents of the slides.

However, it is a bit annoying if we have to scale all the values of presentations with my own functions everywhere.

It would be nice if there was some was to hook into nelsie, so that we could automatically rescale all values, like X, Y, width, height etc., before rendering, or if nelsie had this built-in, so that you could specify a source (logical) resolution, and a target render resolution.

A related alternative is to allow specifying all values as relative, e.g. as percentages.

spirali commented 4 months ago

Percentage specification is allowed. What is not sufficient on this approach?

Kobzol commented 4 months ago

A few reasons:

spirali commented 4 months ago

I will think about it, but actually fonts is something that cannot be naively scaled in this way, as you have just one parameter for fonts (i.e. text are objects with a fixed aspect ratio). If you are rescaling a slide to different aspect ratio, you cannot rescale fonts to new ratio of width and height at same time.

Kobzol commented 4 months ago

I know, it's not perfect, but it's still better to have a somewhat scaled font than to not see the text at all if I change the resolution a lot :)