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

Allow setting text alignment mode #64

Open
ben-wes opened this issue Oct 19, 2024 · 8 comments · May be fixed by #65
Open

Allow setting text alignment mode #64

ben-wes opened this issue Oct 19, 2024 · 8 comments · May be fixed by #65

Comments

@ben-wes
Copy link
Contributor

ben-wes commented Oct 19, 2024

currently, the text coordinate always is at the upper left of the text bounding box - obviously resulting in top-left aligned text.

For some use cases (especially when displaying numbers), right alignment would be a nice option to have.

For this, we could add a new alignment setting (similar to the way that colors are set) like set_text_align(mode). An open question here is whether the vertical alignment is also necessary or if left, center, right are enough.

Tcl/Tk uses compass directions for this (see https://www.tcl.tk/man/tcl8.4/TkCmd/options.htm#M-anchor): n, ne, e, se, s, sw, w, nw, center ... that would be an option as well, but not sure if needed and if that would easily be adaptable for purr data and plugdata?

@agraef
Copy link
Owner

agraef commented Oct 21, 2024

It's possible in purr-data as long as HTML SVG supports it. Of which I'm almost certain, but I'm not sure how much work it would be. (There's stacked lines of text in HTML SVG, but I'm not sure that the HTML text alignment styles are supported there. If they are then it should be rather trivial, otherwise you'd have to do it by calculating the bounding box of the text and applying transformation matrices.)

@ben-wes
Copy link
Contributor Author

ben-wes commented Oct 21, 2024

Thanks for the feedback! Looks like all options would be possible with combinations of alignment-baseline and text-anchor:

@timothyschoen : any thoughts on this? i might give the vanilla version a try.

@ben-wes
Copy link
Contributor Author

ben-wes commented Oct 21, 2024

adding to this: probably, horizontal alignment is more relevant in this context?

so maybe the function could have an optional second argument and expect set_text_align(horizontal_alignment, vertical_alignment) - like for example:

set_text_align(LEFT)
set_text_align(RIGHT, BOTTOM)

or set_text_align is just for horizontal alignment and we'd add set_text_align_vertical? so many options! ;)

i'd be fine with any variant (also the mode for both directions), but maybe one seems preferable from a more experienced point of view here?

@timothyschoen
Copy link
Contributor

timothyschoen commented Oct 22, 2024

We could either have set_text_align, or add an extra argument to draw_text, so we'd have draw_text(x, y, w, fontheight, align = top_left), so the alignment is left by default for backward compatibility. Both are okay with me.

I'd define alignment options like this:

  • top_left
  • top_centred
  • top_right
  • centred_left
  • centred
  • centred_right
  • bottom_left
  • bottom_centred
  • bottom_right

I'd prefer to limit it to one argument, and this should be clear enough?

@ben-wes
Copy link
Contributor Author

ben-wes commented Oct 22, 2024

sounds like a good option to me as well to set it directly in draw_text() as optional argument.

i'd stick with center instead of centred if fine for you since that's more common, i think. and having just center instead of center_center might not be consistent, but convenient.

to avoid misunderstandings from my side: should these be strings or values like SIGNAL and DATA?

@timothyschoen
Copy link
Contributor

I think values are better here. I agree about using "center" instead!

@ben-wes
Copy link
Contributor Author

ben-wes commented Oct 22, 2024

thanks for the feedback! sorry for coming up with more and more questions here ... but i see in pd.lua that we have these definitions:

-- constants used in the signal and graphics API
DATA = 0
SIGNAL = 1
Colors = {background = 0, foreground = 1, outline = 2}

... not sure now if we would add all these alignment values on this level? but then again, i'm not sure how to implement that at all - so i'll probably have to better understand a few more parts of the code first. :)

ben-wes added a commit to ben-wes/pd-lua that referenced this issue Oct 22, 2024
@ben-wes ben-wes linked a pull request Oct 22, 2024 that will close this issue
@ben-wes
Copy link
Contributor Author

ben-wes commented Oct 22, 2024

see #65. we can discuss the details there if it looks good in general.

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 a pull request may close this issue.

3 participants