Is there a way to justify the text in a Label?

1,995 views
Skip to first unread message

darkdi...@gmail.com

unread,
Mar 7, 2013, 12:37:16 PM3/7/13
to kivy-...@googlegroups.com
I think the title is self-explanatory   ; )

I'm trying to use kivy for some kind of interactive-book for childrens, but I can't find a way to justify the text in a Label (the text in a book page in this project)

Thanks in advance !

Ben Rousch

unread,
Mar 7, 2013, 1:02:10 PM3/7/13
to kivy-...@googlegroups.com
Does halign do what you need?
http://kivy.org/docs/api-kivy.uix.label.html#kivy.uix.label.Label.halign
> --
> You received this message because you are subscribed to the Google Groups
> "Kivy users support" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to kivy-users+...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>



--
Ben Rousch
bro...@gmail.com
http://clusterbleep.net/

darkdi...@gmail.com

unread,
Mar 7, 2013, 1:10:07 PM3/7/13
to kivy-...@googlegroups.com
with halign y can align the text in the left/center/right side, but I need to align on left AND right sides at once just like in here

Mathieu Virbel

unread,
Mar 7, 2013, 1:13:46 PM3/7/13
to kivy-...@googlegroups.com
Nop, it's not implemented. But that can be done.
Open a feature request on the github, and submit a Pull Request :D

Mathieu

Le 07/03/2013 19:10, darkdi...@gmail.com a �crit :
> with halign y can align the text in the left/center/right side, but I
> need to align on left AND right sides at once just like in here
> <http://en.wikipedia.org/wiki/Justification_(typesetting)>
>
>
>
>
> El jueves, 7 de marzo de 2013 19:02:10 UTC+1, Ben Rousch escribi�:
>
> Does halign do what you need?
> http://kivy.org/docs/api-kivy.uix.label.html#kivy.uix.label.Label.halign
> <http://kivy.org/docs/api-kivy.uix.label.html#kivy.uix.label.Label.halign>
>
>
> On Thu, Mar 7, 2013 at 12:37 PM, <darkdi...@gmail.com
> <javascript:>> wrote:
> > I think the title is self-explanatory ; )
> >
> > I'm trying to use kivy for some kind of interactive-book for
> childrens, but
> > I can't find a way to justify the text in a Label (the text in a
> book page
> > in this project)
> >
> > Thanks in advance !
> >
> > --
> > You received this message because you are subscribed to the Google
> Groups
> > "Kivy users support" group.
> > To unsubscribe from this group and stop receiving emails from it,
> send an
> > email to kivy-users+...@googlegroups.com <javascript:>.
> > For more options, visit https://groups.google.com/groups/opt_out
> <https://groups.google.com/groups/opt_out>.
> >
> >
>
>
>
> --
> Ben Rousch
> bro...@gmail.com <javascript:>
> http://clusterbleep.net/

Gabriel Pettier

unread,
Mar 7, 2013, 1:29:42 PM3/7/13
to kivy-...@googlegroups.com
Hi

I had a quick look, and I don't think we have an easy way to do this
(pygame and sdl core text providers doesn't seem to offer justification
options), so I guess the easiest route would be to render word by word,
and manage the spaces between them yourself. I may be missing something
though, maybe someone will have a better idea.

Mathieu Virbel

unread,
Mar 7, 2013, 1:32:00 PM3/7/13
to kivy-...@googlegroups.com
That's right. We already have the logic to render per-word.
If justify is set for halign, we can do the first pass as usual (left or
right, doesn't matter), then justify in the second pass (we'll know
exactly the size of each word + width of the line.)

Mathieu

Le 07/03/2013 19:29, Gabriel Pettier a �crit :

Akshay Arora

unread,
Mar 9, 2013, 2:05:29 PM3/9/13
to kivy-...@googlegroups.com
Hello darkdijkstra,

checkout https://github.com/kivy/kivy/pull/1001

 You can test by running the following commands on the master from github.

    git pull
    git checkout text_justified
    python your_app.py

This introduces a `justify` option along with `left`, `right` and `center`

Best Regards.

On Fri, Mar 8, 2013 at 12:02 AM, Mathieu Virbel <txp...@gmail.com> wrote:
That's right. We already have the logic to render per-word.
If justify is set for halign, we can do the first pass as usual (left or
right, doesn't matter), then justify in the second pass (we'll know
exactly the size of each word + width of the line.)

Mathieu

darkdi...@gmail.com

unread,
Mar 12, 2013, 10:47:35 AM3/12/13
to kivy-...@googlegroups.com
Wow, I've seen now it's implemented... last week I wrote some functions to fill a BoxContainer with Labels trying to justify the text... It worked... a bit   XD

Kivy has improved itself one more time !!

krister viirsaar

unread,
Mar 18, 2013, 10:26:07 AM3/18/13
to kivy-...@googlegroups.com
dude what's you email? (google hides it from me)
Reply all
Reply to author
Forward
0 new messages