Hi!
The problem is that pyglet.text.Label prints text in a box just fine, but
pyglet.text.layout.TextLayout does not. I tried using scrollable and
incremental layouts to no avail. What am I doing wrong?
import pyglet
from pyglet.gl import *
from pyglet import resource
WIN_WIDTH = 1024
WIN_HEIGHT = 768
class Box():
def __init__(self, x, y, w, h, batch=None, group=None):
self.BOX_DEFAULT_COLOR = (20, 20, 20,
20, 20, 20,
50, 50, 50,
20, 20, 20)
self.BOX_LINES_DEFAULT_COLOR = (200, 75, 0, # right bottom
240, 115, 0, # right top
240, 115, 0, # top right
240, 115, 0, # top left
240, 115, 0, # left top
200, 75, 0, # left bottom
200, 75, 0, # bottom left
200, 75, 0,) # bottom right
self.vertex_list = batch.add(4, pyglet.gl.GL_QUADS, group,
('v2i', (x+w, y, x+w, y+h, x, y+h, x,
y)),
('c3B', self.BOX_DEFAULT_COLOR))
self.vertex_list = batch.add(8, pyglet.gl.GL_LINES, group,
('v2i', (x+w+1, y, x+w+1, y+h, # right
x+w, y+h, x, y+h, # top
x, y+h, x, y, # left
x, y-1, x+w, y-1)), # bottom
('c3B', self.BOX_LINES_DEFAULT_COLOR))
graphics_batch = pyglet.graphics.Batch()
text_batch = pyglet.graphics.Batch()
box_group = pyglet.graphics.OrderedGroup(1)
text_group = pyglet.graphics.OrderedGroup(2)
font = pyglet.font.load(('Verdana', 'Helvetica', 'Arial'))
if pyglet.font.have_font('Verdana'):
font_name = 'Verdana'
elif pyglet.font.have_font('Helvetica'):
font_name = 'Helvetica'
elif pyglet.font.have_font('Arial'):
font_name = 'Arial'
text = """Humpty Dumpty sat on a wall,
Humpty Dumpty had a great fall.
All the king's horses and all the king's men
Couldn't put Humpty together again."""
document = pyglet.text.decode_text(text)
document.set_style(0, len(document.text),
dict(font_name=font_name, font_size=8, color=(230, 230,
230, 255),
background_color=None))
layout = pyglet.text.layout.TextLayout(document, 180, 380, wrap_lines=True,
batch=text_batch, group=text_group)
layout.x=410
layout.y=490
layout.x_anchor='left'
layout.y_anchor='top'
label = pyglet.text.Label(text, font_name=font_name, font_size=8,
color=(230, 230, 230, 255), x=110, y=490,
width=180, height=380, anchor_x='left',
anchor_y='top', align='left', multiline=True, batch=text_batch,
group=text_group)
labelbox = Box(100, 100, 200, 400, batch=graphics_batch, group=box_group)
layoutbox = Box(400, 100, 200, 400, batch=graphics_batch, group=box_group)
win = pyglet.window.Window(width=WIN_WIDTH,height=WIN_HEIGHT,caption='Test
Window',resizable=False)
@win.event
def on_draw():
win.clear()
graphics_batch.draw()
text_batch.draw()
def update(dt):
pass
pyglet.clock.schedule_interval(update, 1/60.)
pyglet.app.run()
--
You received this message because you are subscribed to the Google Groups
"pyglet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.