Skip to content

Commit 2881df4

Browse files
authored
UI: fix text y_anchor and improve widget gallery (#1404)
1 parent ee0dd00 commit 2881df4

File tree

4 files changed

+39
-9
lines changed

4 files changed

+39
-9
lines changed

arcade/gui/examples/textured_slider.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
from typing import Union
2+
13
import arcade
24
from arcade import Window, View, Texture
3-
from arcade.gui import UIManager, Surface, UIAnchorLayout
5+
from arcade.gui import UIManager, Surface, UIAnchorLayout, NinePatchTexture
46
from arcade.gui.widgets.slider import UISlider
57

68

@@ -9,7 +11,12 @@ class UITextureSlider(UISlider):
911
Slider using
1012
"""
1113

12-
def __init__(self, bar: Texture, thumb: Texture, style=None, **kwargs):
14+
def __init__(self,
15+
bar: Union[Texture, NinePatchTexture],
16+
thumb: Union[Texture, NinePatchTexture],
17+
style=None,
18+
**kwargs
19+
):
1320
self.bar = bar
1421
self.thumb = thumb
1522
style = style or UISlider.DEFAULT_STYLE

arcade/gui/examples/widget_gallery.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
import arcade
77
from arcade import load_texture
8-
from arcade.gui import UIManager, UITextureButton, UIGridLayout, NinePatchTexture
8+
from arcade.gui import UIManager, UITextureButton, UIGridLayout, NinePatchTexture, UILabel, UITextureToggle
9+
from arcade.gui.examples.textured_slider import UITextureSlider
910
from arcade.gui.widgets.layout import UIAnchorLayout
1011

1112

@@ -45,12 +46,25 @@ def __init__(self):
4546
col_num=0,
4647
row_num=1)
4748

48-
button = UITextureButton(
49-
texture=load_texture(":resources:gui_basic_assets/red_button_normal.png"),
50-
texture_hovered=load_texture(":resources:gui_basic_assets/red_button_hover.png"),
51-
texture_pressed=load_texture(":resources:gui_basic_assets/red_button_press.png"),
52-
)
53-
button.rect = button.rect.resize(width=150, height=80)
49+
grid.add(
50+
child=UILabel(text="abcdefghijklmnopqrstuvwäöüABCDEFG"),
51+
col_num=0,
52+
row_num=2)
53+
54+
grid.add(
55+
child=UITextureToggle(
56+
on_texture=load_texture(":resources:gui_basic_assets/toggle/switch_green.png"),
57+
off_texture=load_texture(":resources:gui_basic_assets/toggle/switch_red.png")
58+
),
59+
col_num=0,
60+
row_num=3)
61+
grid.add(
62+
child=UITextureSlider(
63+
bar=arcade.load_texture(":resources:gui_basic_assets/slider_bar.png"),
64+
thumb=arcade.load_texture(":resources:gui_basic_assets/slider_thumb.png"),
65+
),
66+
col_num=0,
67+
row_num=4)
5468

5569
def on_draw(self):
5670
self.clear()

arcade/gui/nine_patch.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,14 @@ def size(self) -> Tuple[float, float]:
9191
"""
9292
return self.texture.size
9393

94+
@property
95+
def width(self):
96+
return self.texture.width
97+
98+
@property
99+
def height(self):
100+
return self.texture.height
101+
94102
def draw_sized(
95103
self,
96104
*,

arcade/gui/widgets/text.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ def __init__(
8383
italic=italic,
8484
stretch=stretch,
8585
align=align,
86+
anchor_y="bottom", # position text bottom left, to fit into scissor box
8687
dpi=dpi,
8788
multiline=multiline,
8889
**kwargs,

0 commit comments

Comments
 (0)