from __future__ import annotations
from abc import abstractmethod
from dataclasses import dataclass
from typing import Mapping, TypeVar, Generic, overload, Any
from arcade.gui.property import DictProperty
from arcade.gui.widgets import UIWidget
[docs]
@dataclass
class UIStyleBase:
"""
Base class for styles to ensure a general interface and implement additional magic.
Support dict like access syntax.
A styled widget should own a dataclass, which subclasses this class
"""
@overload
def get(self, key, default: str) -> str: ...
@overload
def get(self, key, default: Any) -> Any: ...
[docs]
def get(self, key, default=None):
return self[key] if key in self else default
def __contains__(self, item):
return hasattr(self, item)
def __getitem__(self, item):
return getattr(self, item)
def __setitem__(self, key, value):
setattr(self, key, value)
StyleRef = TypeVar("StyleRef", bound=UIStyleBase)