| 452 | self._should_render = should_render |
| 453 | |
| 454 | def texture(self, asset_path: str, width: int | None = None, height: int | None = None, |
| 455 | alpha_premultiply=False, keep_aspect_ratio=True, flip_x: bool = False) -> rl.Texture: |
| 456 | if width is not None: |
| 457 | width = round(width) |
| 458 | if height is not None: |
| 459 | height = round(height) |
| 460 | |
| 461 | cache_key = f"{asset_path}_{width}_{height}_{alpha_premultiply}_{keep_aspect_ratio}_{flip_x}" |
| 462 | if cache_key in self._textures: |
| 463 | return self._textures[cache_key] |
| 464 | |
| 465 | with as_file(ASSETS_DIR.joinpath(asset_path)) as fspath: |
| 466 | image_obj = self._load_image_from_path(fspath.as_posix(), width, height, alpha_premultiply, keep_aspect_ratio, flip_x) |
| 467 | texture_obj = self._load_texture_from_image(image_obj) |
| 468 | |
| 469 | # Set logical size so widget layout math stays at 1x coordinates |
| 470 | if self._scale != 1.0 and width is not None and height is not None: |
| 471 | texture_obj.width = width |
| 472 | texture_obj.height = height |
| 473 | |
| 474 | self._textures[cache_key] = texture_obj |
| 475 | return texture_obj |
| 476 | |
| 477 | def _load_image_from_path(self, image_path: str, width: int | None = None, height: int | None = None, |
| 478 | alpha_premultiply: bool = False, keep_aspect_ratio: bool = True, flip_x: bool = False) -> rl.Image: |