halign problem

504 views
Skip to first unread message

Simon

unread,
Jul 10, 2011, 4:27:29 PM7/10/11
to Kivy users support
Hi,

I'm trying to use the halign property of a Label and can't get it to
work - or am misunderstanding what it does.

I've created a single label and returned it from the MyApp.build()
method. I want the text within this label to be right aligned so that
when I change it (by writing to the text property) it doesn't leap
around. However the text always seems to be centered.

All I'm doing is adding halign='right' to the arguments to the Label()
constructor.

I'm running on Mac OS 10.6 with the latest release kivy download.

Cheers,
Simon.

Mathieu Virbel

unread,
Jul 10, 2011, 5:20:26 PM7/10/11
to kivy-...@googlegroups.com
Hi simon,

The halign is not the only thing you must take care about: the size of the container is also important.
The label is rendered into a texture. The valign/halign work inside the texture rendering.
Then, the texture is displayed centered on the Label widget.

If you don't understand really how it's work, check the examples/widgets/textalign.py, you have all the cases explained. :)

Mathieu

2011/7/10 Simon <simonfrom...@googlemail.com>

cygnusx

unread,
Jul 10, 2011, 8:36:47 PM7/10/11
to Kivy users support
Well, does this has a function? It would be nicer to get the halign
somewhat more easy to set-up and less complicated to understand I
guess..

On 10 jul, 23:20, Mathieu Virbel <m...@kivy.org> wrote:
> Hi simon,
>
> The halign is not the only thing you must take care about: the size of the
> container is also important.
> The label is rendered into a texture. The valign/halign work inside the
> texture rendering.
> Then, the texture is displayed centered on the Label widget.
>
> If you don't understand really how it's work, check the
> examples/widgets/textalign.py, you have all the cases explained. :)
>
> Mathieu
>
> 2011/7/10 Simon <simonfromcambri...@googlemail.com>> Hi,

Mathieu Virbel

unread,
Jul 11, 2011, 3:01:48 AM7/11/11
to kivy-...@googlegroups.com
It's not a functionnality, it's the way we are doing the work inside widget. The content and the bounding box are seperated.
I know it can be not really user friendly sometime, but at least, we are not forcing you to a single usage of widget.

As for the Label, by default, the text is rendered without any size constrain. Giving a constrain with text_size property can be more slower, since if the widget change size, the text will be rerendered. You can also achieve padding by reducing text_size constrain.
If you want a Label with that by default, better is to create a widget like:

class ConstrainedLabel(Label):
  pass

And in the kv:

<ConstrainedLabel>:
  text_size: (self.width - 20, None) # padding of 10 pixels each side


Hope that's help

Mathieu

2011/7/11 cygnusx <cyg...@gmail.com>

Simon

unread,
Jul 11, 2011, 10:34:42 AM7/11/11
to Kivy users support
Thanks Mathieu,

The textalign example wasn't in the 1.0.6 download but now I've got a
copy from git I've got it working well enough for now.

Cheers,
Simon.
Reply all
Reply to author
Forward
0 new messages