Add css caching, adapt to LineLayout and Textlayout, add link support, add a resolve_url function, cache colors and space widths for fonts, fix bug crashing if font doesnt exist

This commit is contained in:
csd4ni3l
2025-07-22 18:32:27 +02:00
parent 385552bb08
commit 8b9b70c475
6 changed files with 200 additions and 71 deletions

View File

@@ -1,5 +1,7 @@
import logging, traceback
from functools import lru_cache
import pyglet.display, arcade
def dump_platform():
@@ -64,19 +66,21 @@ class FakePyPresence():
def close(self, *args, **kwargs):
...
@lru_cache
def hex_to_rgb(hex_color):
hex_color = hex_color.lstrip('#')
if len(hex_color) != 6:
return (127, 127, 127)
return tuple(int(hex_color[i:i+2], 16) for i in (0, 2, 4))
@lru_cache
def get_color_from_name(rgb_name):
rgb_name = rgb_name.upper()
if rgb_name.startswith("LIGHT"):
color_name = rgb_name.split("LIGHT")[1]
color_value = arcade.csscolor.__dict__.get(f"LIGHT_{color_name}")
if not color_value:
arcade.color.__dict__.get(f"LIGHT_{color_name}")
color_value = arcade.color.__dict__.get(f"LIGHT_{color_name}")
if color_value:
return color_value