Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions arcade/examples/gui/2_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,27 @@

import arcade
from arcade.gui import (
NinePatchTexture,
UIAnchorLayout,
UIBoxLayout,
UIButtonRow,
UIDropdown,
UIDummy,
UIFlatButton,
UIImage,
UIInputText,
UILabel,
UISpace,
UIManager,
UIMessageBox,
UIOnActionEvent,
UITextArea,
UIOnChangeEvent,
UITextureButton,
UITextureToggle,
UISlider,
UITextureSlider,
UIBoxLayout,
UIImage,
UIDummy,
UISpace,
UISpriteWidget,
NinePatchTexture,
UIDropdown,
UIMessageBox,
UIManager,
UITextArea,
UITextureButton,
UITextureSlider,
UITextureToggle,
UIView,
)

Expand Down Expand Up @@ -612,6 +612,7 @@ def _show_other_widgets(self):
text_area.with_padding(left=10, right=10)
text_area.with_border(color=arcade.uicolor.GRAY_CONCRETE, width=2)


def main():
window = arcade.Window(title="GUI Example: Widget Gallery")
window.show_view(GalleryView())
Expand Down
14 changes: 12 additions & 2 deletions arcade/gui/surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def __init__(
self._size = size
self._pos = position
self._pixel_ratio = pixel_ratio
self._pixelated = False

self.texture = self.ctx.texture(self.size_scaled, components=4)
self.fbo: Framebuffer = self.ctx.framebuffer(color_attachments=[self.texture])
Expand Down Expand Up @@ -142,7 +143,9 @@ def draw_texture(

tex.draw_rect(rect=LBWH(0, 0, width, height))
else:
arcade.draw_texture_rect(tex, LBWH(x, y, width, height), angle=angle, alpha=alpha)
arcade.draw_texture_rect(
tex, LBWH(x, y, width, height), angle=angle, alpha=alpha, pixelated=self._pixelated
)

def draw_sprite(self, x: float, y: float, width: float, height: float, sprite: arcade.Sprite):
"""Draw a sprite to the surface
Expand All @@ -157,7 +160,7 @@ def draw_sprite(self, x: float, y: float, width: float, height: float, sprite: a
sprite.position = x + width // 2, y + height // 2
sprite.width = width
sprite.height = height
arcade.draw_sprite(sprite)
arcade.draw_sprite(sprite, pixelated=self._pixelated)

@contextmanager
def activate(self) -> Generator[Self, None, None]:
Expand Down Expand Up @@ -226,11 +229,18 @@ def draw(
Args:
area: Limit the area in the surface we're drawing
(l, b, w, h)
pixelated: If True, the texture will be rendered pixelated
"""
# Set blend function
blend_func = self.ctx.blend_func
self.ctx.blend_func = self.blend_func_render

# Handle the pixelated shortcut if filter is not set
if self._pixelated:
self.texture.filter = self.ctx.NEAREST, self.ctx.NEAREST
else:
self.texture.filter = self.ctx.LINEAR, self.ctx.LINEAR

self.texture.use(0)
self._program["pos"] = self._pos
self._program["size"] = self._size
Expand Down
7 changes: 6 additions & 1 deletion arcade/gui/ui_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ def on_draw():
"""

_enabled = False
_pixelated = False
"""Experimental feature to pixelate the UI, all textures will be rendered pixelated,
which will mostly influence scaled background images.
This property has to be set right after the UIManager is created."""

DEFAULT_LAYER = 0
OVERLAY_LAYER = 10
Expand Down Expand Up @@ -198,6 +202,7 @@ def _get_surface(self, layer: int) -> Surface:
size=self.window.get_size(),
pixel_ratio=self.window.get_pixel_ratio(),
)
self._surfaces[layer]._pixelated = self._pixelated

return self._surfaces[layer]

Expand Down Expand Up @@ -316,7 +321,7 @@ def on_update(self, time_delta):
"""Dispatches an update event to all widgets in the UIManager."""
return self.dispatch_ui_event(UIOnUpdateEvent(self, time_delta))

def draw(self) -> None:
def draw(self, pixelated=False) -> None:
"""Will draw all widgets to the window.

UIManager caches all rendered widgets into a framebuffer (something like a
Expand Down
27 changes: 27 additions & 0 deletions arcade/gui/widgets/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,33 @@ def text(self, value):
else:
self.trigger_full_render()

@property
def font_name(self) -> FontNameOrNames:
"""Font name of the label. Use :py:meth:`~arcade.gui.UILabel.update_font` to change."""
return self._label.font_name

@property
def font_size(self) -> float:
"""Font size of the label. Use :py:meth:`~arcade.gui.UILabel.update_font` to change."""
return self._label.font_size

@property
def font_color(self) -> Color:
"""Font color of the label. Use :py:meth:`~arcade.gui.UILabel.update_font` to change."""
return self._label.color

@property
def bold(self) -> bool | str:
"""Return if the label is in bold style.
Use :py:meth:`~arcade.gui.UILabel.update_font` to change."""
return self._label.bold

@property
def italic(self) -> bool | str:
"""Return if the label is in italic style.
Use :py:meth:`~arcade.gui.UILabel.update_font` to change."""
return self._label.italic

def _update_label(self):
"""Update the position and size of the label.

Expand Down
Loading