I've been toying with the idea of adding support for text and fonts to the Button library where you could input text, font and size (as well as up and down states) and have it produce a button with said text.
The issue is.... is that actually useful? I'm wondering if it is just easier to produce images with the text you want already in them. Is using text within an app expensive compared to adding a Bitmap?
I think it might be useful for rapid prototyping... no going to photoshop or other imaging editing software to produce images for buttons, you could do it all within Gideros to quickly produce a prototyp UI.
Thoughts?
Comments
If someone would create/extend button class with text support, I would really appreciate it
As i said all credits here goes to him.
Likes: ar2rsawseen, Teranth
Gideros Project is attached if you want to test it out!
EDIT: I forgot to mention that the images are entirely optional, you can have text only buttons.
Also trimmed code here (it was very long). The rest of the functions are the same as button class, only they are "function TextButton:function()"
Likes: talis, ar2rsawseen
Thanks again for sharing.
#MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
I can't find baseline parameters, I have searched all over the place and couldn't find it.
I'm trying to make it work like CSS (padding, margin).
Also, does any fork of textbutton include a way to specifiy width and height (and crop the image given as a parameter for up and down status).
From my understanding now the button's width comes from the bitmap's width? but most of the time the image is just used as a background for a button with a given width.
Unless I didn't understand well how those classes work... (and probability is high).
Button width is equal to the max width of it's children and no more I believe.
You can try using getBounds() method to get the baseline offset.
y coordinate is usually somewhere along -7px
First I get the bounds of the text string ( sprite:getBounds() ) and then the bounds of the box, for the text remember the render position is actually the bottom left corner of the bounding box, not the top left.
I then just take one away from the other to work out the text draw offset relative to the top left of the box.
#MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
For those that are looking for unofficial-official steps on how to work with getBounds() : >> [ Link ]