Skip to content

Commit 6deb360

Browse files
committed
Improve sprite scaling for Button widget
Updated the Button widget to handle both AbstractImage and Animation types when scaling sprites. The code now checks for width and height attributes on the image, falling back to sprite dimensions if necessary, ensuring correct scaling for different image types.
1 parent 5c09eb7 commit 6deb360

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

tilingsgui/widgets.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,18 @@ def position(self, x: float, y: float, w: float, h: float) -> None:
231231
self._x, self._y, self._w, self._h = x, y, w, h
232232
if w > 0 and h > 0:
233233
# Scale to fit within the button bounds while maintaining aspect ratio
234-
scale_x = float(w) / float(self._sprite.image.width)
235-
scale_y = float(h) / float(self._sprite.image.height)
234+
# Handle both AbstractImage and Animation types
235+
image = self._sprite.image
236+
if hasattr(image, "width") and hasattr(image, "height"):
237+
img_width = float(image.width)
238+
img_height = float(image.height)
239+
else:
240+
# Fallback for Animation or other types - use sprite dimensions
241+
img_width = float(self._sprite.width)
242+
img_height = float(self._sprite.height)
243+
244+
scale_x = float(w) / img_width
245+
scale_y = float(h) / img_height
236246
# Use the smaller scale to ensure image fits within bounds
237247
scale = (
238248
min(scale_x, scale_y) * 0.95

0 commit comments

Comments
 (0)