(9.07) Label positioning on button

christianboutin.com

13-09-2009 15:16:37

Is there a way to set the position of the text area on a button? I'm seeing the label_verticalTextAlignment variable, but it can't be set with a pixel value. The combination of font and images I use make it so even though the text might be mathematically centered, it doesn't look centered at all.



I'm seeing I can go into Button:onDraw and just add a few pixels to yPos to solve it. If there's a clean way to access/change this text position I don't see it. Seeing the code though I could probably code it proper in the LabelDesc (maybe?) label_positionDelta or something like that? and have it accessible from user-code and the skindef file.

I'll probably move on SVN soon so I can contribute to this.

kungfoomasta

13-09-2009 16:40:33

There was another user with the same issue a while back, because the particular .ttf file did not correctly center the glyphs. (Maybe it was intentional?)

What I'm thinking is that we should have a property "label_verticalOffset", which can shift the text up or down, 'after' it has been vertically aligned. (Probably done in the onDraw function as you've mentioned) If you agree to this solution I can go ahead and add it to SVN, it wouldn't take long at all. Basically I would add the following property, add get/set functions for it, and update the _initialize and onDraw functions to use the property.

Also I must say I'm impressed with the amount of investigation and familiarizing with the code base you've done! :D

christianboutin.com

13-09-2009 16:52:52

label_verticalOffset would solve my problem. Thanks! I'm thinking though someone might also want label_horizontalOffset (for example, in the case of a button where the text zone on the button is not centered, but he would still want the text to be centered within that zone). So while you're there...

Investigating the code is the least I can do before bugging you, kind sir. I'm also impressed with what you've done. Simple, straightforward and has a lot of potential. Keep up the good work! I'll try and sync myself with SVN soon so I can submit patches and so on properly.

Cheers!

kungfoomasta

13-09-2009 17:15:08

While adding in the functionality I realized I would like to maximize the number of widgets that could make use of this offset, for example TitleBars, MenuItems, etc.

What I've done currently is created a Text class, which has an 'allotedWidth', which defines the amount of width the text has before it starts wrapping to the next line. (If allotted with it 0 or less, the text does not wrap) With this property, the Text class handles horizontal centering of text, within the allotted width. The vertical centering of text is done in the Widget, which vertically places the text.

What I'm thinking is that I would change allottedWidth to be allottedSize, and try to move vertical centering functionality inside the Text class, so that all widgets using text could easily tap into the offset property. I'm not sure how much effort would be required to implement this, but it feels like the right design. I'm going to try and do this now.

christianboutin.com

13-09-2009 17:27:33

Yeah it's probably wise to standardise this. For the record I can totally live without that functionality in the short term. Tons of other things to do before game's end so don't rush this for my sake. Thanks!

kungfoomasta

13-09-2009 19:48:24

Ok its done. I have not done thorough testing other than loading up the Editor and creating layouts as the editor allows. (the editor is not fully functional) Also I didn't really test the offset functionality. If you want to jump to SVN and give it a shot and let me know if there are any problems, that would be helpful.

christianboutin.com

13-09-2009 21:44:05

Works like a charm! Thanks a lot!