Skip to content

Commit

Permalink
Add RGB support to label init (#1091)
Browse files Browse the repository at this point in the history
* Add Label pipe annotation + docstring update

* Add RGB unpacking + alpha padding to Label.__init__
  • Loading branch information
pushfoo committed Apr 16, 2024
1 parent 835fd9b commit 5ee6e3a
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions pyglet/text/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ def __init__(
multiline: bool = False, dpi: int | None = None,
font_name: str | None = None, font_size: int | None = None,
bold: bool | str = False, italic: bool | str = False, stretch: bool | str = False,
color: tuple[int, int, int, int] = (255, 255, 255, 255),
color: tuple[int, int, int, int] | tuple[int, int, int] = (255, 255, 255, 255),
align: ContentVAlign = "left",
batch: Batch | None = None, group: Group | None = None,
program: ShaderProgram | None = None,
Expand All @@ -373,7 +373,8 @@ def __init__(
stretch:
Stretch font style.
color:
Font colour, as RGBA components in range [0, 255].
Font color as RGBA or RGB components, each within
``0 <= component <= 255``.
x:
X coordinate of the label.
y:
Expand Down Expand Up @@ -411,6 +412,9 @@ def __init__(
Optional graphics shader to use. Will affect all glyphs.
"""
doc = decode_text(text)
r, g, b, *a = color
rgba = r, g, b, a[0] if a else 255

super().__init__(doc, x, y, z, width, height, anchor_x, anchor_y, rotation,
multiline, dpi, batch, group, program, init_document=False)

Expand All @@ -420,7 +424,7 @@ def __init__(
"bold": bold,
"italic": italic,
"stretch": stretch,
"color": color,
"color": rgba,
"align": align,
})

Expand Down

0 comments on commit 5ee6e3a

Please sign in to comment.