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

More intuitive padding specification #4887

Open
aplavin opened this issue Mar 22, 2025 · 1 comment
Open

More intuitive padding specification #4887

aplavin opened this issue Mar 22, 2025 · 1 comment
Labels
enhancement Feature requests and enhancements

Comments

@aplavin
Copy link
Contributor

aplavin commented Mar 22, 2025

Currently, padding for objects (eg Label) is specified as four numbers, padding=(a, b, c, d).
I personally find it very hard to remember the order, and basically never get it right on the first try. Probably the issue lies in the apparent similarity with CSS (it also uses four numbers), but a completely different order: (l, r, b, t) in Makie and (t, r, b, l) in CSS.

Can we use a more intuitive interface? Some potential examples:

  • Two intervals instead of four numbers: padding=(0 ± 5, 0 ± 2) for 5px horizontal and 2px vertical, or (-3..5, -2..1) for different offsets in all four directions. This is already easier to understand, the l/r and t/b order is clear, only hor-vert remains, but it is more natural (x always comes before y).
  • An explicit rectangle, like padding=Rect(0 ± 5, 0 ± 2). Slightly more verbose, but even more understandable and can neatly generalize to other shapes. Currently used in MakieExtra.textwithbox to try out this specification in practice.

I think either of these would be an improvement. Maybe even both should be supported, with a tuple-of-intervals being converted to a rect under the hood. Rects would play especially nicely if GeometryBasics could define a dilate(shape_a, shape_b) morphological operation.
Or maybe something different would be even better here?..

@aplavin aplavin added the enhancement Feature requests and enhancements label Mar 22, 2025
@ffreyer
Copy link
Collaborator

ffreyer commented Mar 22, 2025

Makie.jl/src/conversions.jl

Lines 2036 to 2038 in 381cf4a

to_lrbt_padding(x::Real) = Vec4f(x)
to_lrbt_padding(xy::VecTypes{2}) = Vec4f(xy[1], xy[1], xy[2], xy[2])
to_lrbt_padding(pad::VecTypes{4}) = to_ndim(Vec4f, pad, 0)

We could extend this to include a..b and Rect(l, b, w, h)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature requests and enhancements
Projects
None yet
Development

No branches or pull requests

2 participants