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

"Virtual Sheet" support - Set a render area dimension for scribble elements #582

Open
Grisgram opened this issue Oct 23, 2024 · 1 comment
Labels
feature 💭 It would be extra good if...

Comments

@Grisgram
Copy link

Grisgram commented Oct 23, 2024

Hey Juju,
as discussed on discord, a feature to define an area, a virtual rectangle or "sheet" if you like, where text shall be aligned.

I receive this specification through a json file:

"title": {
	"align"	: "[fa_top][fa_left]",
	"font"	: "fntCleanTextSmallO",
	"at"	: [ 39, 26,325, 18 ],
},
"text": {
	"align"	: "[fa_middle][fa_center]",
	"font"	: "fntCleanTextSmallO",
	"at"	: [ 51,301,300,176 ],
},

and the at contains a rectangle, (left, top, width, height) in which the text shall be aligned according to align.

We can calculate this by hand with a string compare like if (string_contains(align, "fa_middle")) at[1] += at[3] / 2 but this is ugly code.
It would be great, if the scribble object allows to define a virtual sheet which it will consider when rendering text.

Could look like this:

scribble(...args...)
  .starting_format(...)
  .sheet(mywidth, myheight);

Now, when I render text at some position x/y, this is the top left corner where the sheet "starts" and from that origin point, the text will be aligned as if its bbox would be my_width/my_height in dimensions.

I could also imagine, that the sheet function takes 4 arguments, left.top.width.height and the left and top would be an additional offset to the x/y i send to draw.
Any of these solutions is fine!

I hope, I could explain, what I mean

cheers,
Gris

@JujuAdams JujuAdams changed the title Feature: "Virtual Sheet" support - Set a render area dimension for scribble elements "Virtual Sheet" support - Set a render area dimension for scribble elements Oct 23, 2024
@Grisgram
Copy link
Author

Grisgram commented Oct 23, 2024

Thinking about it, the sheet function should really take 4 arguments.

Because this opens a wonderful door: We can "align" text with scribble to the green variables of an object like this:

.sheet(-sprite_xoffset, -sprite_yoffset, sprite_width, sprite_height)

et voilá! Your entire sprite is the virtual area and you can align text in any corner or the center of your object, no matter where the origin of the sprite is located, by simply calling

.draw(x,y) where x and y are also the green variables, the coordinates of the object.

Maybe even a 5th argument?

a fifth argument could be a bool, auto_wrap to keep the text within the dimensions of the area. Or would you say, using a sheet will always auto-wrap? Would be very ok also.

@JujuAdams JujuAdams added the feature 💭 It would be extra good if... label Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature 💭 It would be extra good if...
Projects
None yet
Development

No branches or pull requests

2 participants