I was scratching my head at this one for a little while, and I think
I've identified a bug and a fix. I'm working from the latest svn (hg?)
version of pyglet as far as I know.

When creating a label which has multiline enabled and halign set to
centered, like this:

my_label = pyglet.text.Label("Any text with a \n newline.",
multiline=True, halign="center", width=100) # width is mandatory with
multiline

The lines are not centered as is the intended result according to the
documentation. Instead, they are left aligned (the default). You can
fix it like this:

my_label.set_style("align","center")

But that shouldn't be necessary. Upon investigating pyglet/text/
__init__.py, I think I've identified the problem. The Label
constructor accepts 'halign' as an argument, then calls the following:

=== pyglet/text/__init__.py, starting at line 435 ===

self.document.set_style(0, len(self.document.text), {
            'font_name': font_name,
            'font_size': font_size,
            'bold': bold,
            'italic': italic,
            'color': color,
            'halign': halign,
        })

======

As you can see, it tries to set the "halign" style to the value of the
"halign" argument. What it needs to do is set the "align" (no h) style
to the value of the "halign" argument. There is no "halign" style,
although some mailing list communication seems to indicate that it WAS
a style at some point. The fix is pretty much one line;

======

            'color': color,
-            'halign': halign,
+            'align': halign,
        })

======

That corrects the bug completely based on my testing; it just remaps
the constructor argument to the proper style name.

I apologize if this is a known issue, duplicate bug, broken as
intended, or being reported in the wrong place. It's just something
that was confusing me for a while, so I figured I could mention it.

-- 
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/pyglet-users?hl=en.

Reply via email to