farbschema angepasst

This commit is contained in:
Bernd Reuther committed 2026-10-05 18:40:31 +02:00
1 parent 440d1004b6
commit 1a8e99ef82
2 files changed
+50 -150

No files matched your search

+19 -72
View File
@@ -46,13 +46,13 @@ DEFAULT_SETTINGS = {
}
BASE_THEME = {
"background": "#111111", "surface": "#181818", "text": "#eeeeee",
"background": "#111111", "surface": "#181818", "surface_dark": "#0b0b0b", "text": "#eeeeee",
"text_secondary": "#cccccc", "primary": "#1769aa", "accent": "#ffcc33",
"success": "#2e7d32", "warning": "#ed6c02", "danger": "#d32f2f",
}
BASE_COLOR_LABELS = {
"background": "Hintergrund", "surface": "Flächen", "text": "Text",
"background": "Hintergrund", "surface_dark": "Dunkle Fläche", "surface": "Flächen", "text": "Text",
"text_secondary": "Sekundärtext", "primary": "Primärfarbe", "accent": "Akzentfarbe",
"success": "Erfolg", "warning": "Warnung", "danger": "Fehler / Gefahr",
}
@@ -72,81 +72,28 @@ def _mix(a, b, amount):
def _lighten(value, amount): return _mix(value, "#ffffff", amount)
def _darken(value, amount): return _mix(value, "#000000", amount)
def _luminance(value):
rgb = _hex_rgb(value)
if rgb is None:
return 0.0
channels = [c / 255.0 for c in rgb]
linear = [c / 12.92 if c <= 0.04045 else ((c + 0.055) / 1.055) ** 2.4 for c in channels]
return 0.2126 * linear[0] + 0.7152 * linear[1] + 0.0722 * linear[2]
def _contrast_ratio(a, b):
return (max(_luminance(a), _luminance(b)) + 0.05) / (min(_luminance(a), _luminance(b)) + 0.05)
def _contrast_text(background):
return "#ffffff" if _contrast_ratio("#ffffff", background) >= _contrast_ratio("#000000", background) else "#000000"
def _ensure_contrast(foreground, background, minimum=4.5):
if _contrast_ratio(foreground, background) >= minimum:
return foreground
target = "#ffffff" if _contrast_ratio("#ffffff", background) > _contrast_ratio("#000000", background) else "#000000"
lo, hi = 0.0, 1.0
for _ in range(12):
mid = (lo + hi) / 2
candidate = _mix(foreground, target, mid)
if _contrast_ratio(candidate, background) >= minimum:
hi = mid
else:
lo = mid
return _mix(foreground, target, hi)
def _surface_step(value, background, amount):
return _lighten(value, amount) if _luminance(background) < 0.5 else _darken(value, amount)
def derive_theme(base):
c = dict(BASE_THEME)
if isinstance(base, dict):
for key in BASE_THEME:
value = base.get(key)
if isinstance(value, str) and re.fullmatch(r"#[0-9a-fA-F]{6}", value.strip()):
c[key] = value.strip()
bg = c["background"]
surface = c["surface"]
# User-selected text colors are kept as close as possible to the chosen
# color, but are automatically corrected when they would become unreadable.
text = _ensure_contrast(c["text"], bg, 4.5)
secondary = _ensure_contrast(c["text_secondary"], bg, 4.5)
surface_alt = _surface_step(surface, bg, 0.14)
control = _surface_step(surface, bg, 0.10)
control_hover = _surface_step(surface, bg, 0.20)
primary = c["primary"]
accent = c["accent"]
primary_hover = _surface_step(primary, bg, 0.14)
success = c["success"]
warning = c["warning"]
danger = c["danger"]
if isinstance(value, str) and re.fullmatch(r"#[0-9a-fA-F]{6}", value.strip()): c[key] = value.strip()
bg, surface, surface_dark = c["background"], c["surface"], c["surface_dark"]
text, secondary = c["text"], c["text_secondary"]
primary, accent = c["primary"], c["accent"]
success, warning, danger = c["success"], c["warning"], c["danger"]
return {
"background": bg, "surface": surface, "surface_alt": surface_alt, "surface_dark": _darken(bg,.22),
"text": text, "text_secondary": secondary,
"text_muted": _ensure_contrast(_mix(secondary,bg,.35), bg, 3.0),
"text_faint": _ensure_contrast(_mix(secondary,bg,.58), bg, 2.2),
"border": _surface_step(surface,bg,.28), "border_subtle": _surface_step(surface,bg,.16),
"control": control, "control_hover": control_hover,
"primary": primary, "primary_hover": primary_hover, "primary_text": _contrast_text(primary),
"accent": accent,
"success": success, "success_text": _contrast_text(success),
"warning": warning, "warning_text": _contrast_text(warning),
"danger": danger, "danger_soft": _mix(danger,bg,.82), "danger_soft_hover": _mix(danger,bg,.70),
"error": _mix(danger,bg,.72), "error_text": _contrast_text(_mix(danger,bg,.72)),
"recording": danger, "recording_border": _mix(danger,bg,.55), "recording_text": _contrast_text(danger),
"selection": _mix(primary,bg,.84), "shadow": "#000000",
"scroll_thumb": _mix(secondary,bg,.35), "scroll_thumb_hover": _mix(secondary,bg,.18),
"scroll_thumb_active": secondary, "live_surface": _mix(danger,bg,.84),
"table_header": _surface_step(surface,bg,.08), "table_text": _ensure_contrast(text,surface,4.5),
"footer": _ensure_contrast(_mix(secondary,bg,.50), bg, 2.2), "white": "#ffffff",
"surface_modal": _surface_step(surface,bg,.05), "overlay": "rgba(0,0,0,.78)",
"background": bg, "surface": surface, "surface_alt": _lighten(surface,.12), "surface_dark": surface_dark,
"text": text, "text_secondary": secondary, "text_muted": _mix(secondary,bg,.35), "text_faint": _mix(secondary,bg,.58),
"border": _lighten(surface,.28), "border_subtle": _lighten(surface,.16), "control": _lighten(surface,.12), "control_hover": _lighten(surface,.24),
"primary": primary, "primary_hover": _lighten(primary,.16), "accent": accent,
"success": _darken(success,.42), "success_text": _lighten(success,.68), "warning": _darken(warning,.48),
"danger": danger, "danger_soft": _darken(danger,.58), "danger_soft_hover": _darken(danger,.42),
"error": _darken(danger,.62), "error_text": _lighten(danger,.70), "recording": _darken(danger,.08), "recording_border": _darken(danger,.52),
"selection": "rgba(80,150,255,.16)", "shadow": "#000000", "scroll_thumb": _mix(secondary,bg,.35),
"scroll_thumb_hover": _mix(secondary,bg,.18), "scroll_thumb_active": secondary, "live_surface": _mix(danger,bg,.84),
"table_header": _lighten(surface,.08), "table_text": text, "footer": _mix(secondary,bg,.50), "white": "#ffffff",
"surface_modal": _lighten(surface,.05), "overlay": "rgba(0,0,0,.78)",
}
DEFAULT_THEME = derive_theme(BASE_THEME)
@@ -2033,7 +1980,7 @@ a { color:var(--color-text-secondary); }
.color-field input[type=color] { width:48px; height:40px; padding:3px; background:var(--color-control); border:1px solid var(--color-control-hover); border-radius:5px; cursor:pointer; }
.theme-intro { margin:-4px 0 16px; color:var(--color-text-muted); font-size:14px; line-height:1.45; }
.actions { display:flex; gap:10px; flex-wrap:wrap; margin-top:20px; }
button { border:0; border-radius:5px; padding:10px 16px; background:var(--color-primary); color:var(--color-primary-text); font-size:15px; cursor:pointer; }
button { border:0; border-radius:5px; padding:10px 16px; background:var(--color-primary); color:var(--color-white); font-size:15px; cursor:pointer; }
button:hover { background:var(--color-primary-hover); }
.note { color:var(--color-text-muted); font-size:13px; margin-top:8px; }
.message { padding:10px 12px; border-radius:6px; margin-bottom:16px; background:var(--color-success); color:var(--color-success-text); }