some organization pass, still need to review a bunch
This commit is contained in:
+66
-67
@@ -14,7 +14,7 @@ from contextlib import nullcontext
|
||||
from imgui_bundle import imgui, hello_imgui
|
||||
from typing import Any, Optional
|
||||
|
||||
import src.theme_nerv
|
||||
from src import theme_nerv
|
||||
|
||||
from src import imgui_scopes as imscope
|
||||
from src.theme_nerv import DATA_GREEN
|
||||
@@ -60,18 +60,18 @@ def _build_semantic_colour_dict(theme: ThemeFile) -> dict[str, tuple[float, floa
|
||||
|
||||
_BUILTIN_PALETTES: dict[str, dict[int, tuple]] = {
|
||||
"ImGui Dark": {},
|
||||
"NERV": {},
|
||||
"NERV": {},
|
||||
}
|
||||
|
||||
_TOML_PALETTES: dict[str, ThemeFile] = {}
|
||||
_TOML_COLOUR_CACHE: dict[str, dict[int, tuple[float, float, float, float]]] = {}
|
||||
_TOML_PALETTES: dict[str, ThemeFile] = {}
|
||||
_TOML_COLOUR_CACHE: dict[str, dict[int, tuple[float, float, float, float]]] = {}
|
||||
_TOML_SEMANTIC_CACHE: dict[str, dict[str, tuple[float, float, float, float]]] = {}
|
||||
|
||||
_current_palette: str = "10x Dark"
|
||||
_current_font_path: str = "fonts/Inter-Regular.ttf"
|
||||
_current_font_size: float = 16.0
|
||||
_current_scale: float = 1.0
|
||||
_transparency: float = 1.0
|
||||
_current_palette: str = "10x Dark"
|
||||
_current_font_path: str = "fonts/Inter-Regular.ttf"
|
||||
_current_font_size: float = 16.0
|
||||
_current_scale: float = 1.0
|
||||
_transparency: float = 1.0
|
||||
_child_transparency: float = 1.0
|
||||
|
||||
# Per-palette tone mapping: { "Palette Name": value }
|
||||
@@ -106,8 +106,8 @@ def _tone_map(rgb: tuple[float, float, float, float], palette: str) -> tuple[flo
|
||||
r = max(0, r)**(1.0/g); g_val = max(0, g_val)**(1.0/g); bl = max(0, bl)**(1.0/g)
|
||||
return (max(0.0, min(1.0, r)), max(0.0, min(1.0, g_val)), max(0.0, min(1.0, bl)), a)
|
||||
|
||||
_crt_filter = CRTFilter()
|
||||
_alert_pulsing = AlertPulsing()
|
||||
_crt_filter = CRTFilter()
|
||||
_alert_pulsing = AlertPulsing()
|
||||
_status_flicker = StatusFlicker()
|
||||
|
||||
# ------------------------------------------------------------------ public API
|
||||
@@ -160,7 +160,7 @@ def get_color(name: str, alpha: float = 1.0) -> imgui.ImVec4:
|
||||
if palette_name in _TOML_SEMANTIC_CACHE:
|
||||
d = _TOML_SEMANTIC_CACHE[palette_name]
|
||||
if name in d:
|
||||
rgba = list(d[name])
|
||||
rgba = list(d[name])
|
||||
rgba[3] = alpha
|
||||
return imgui.ImVec4(*_tone_map(tuple(rgba), palette_name))
|
||||
|
||||
@@ -172,25 +172,25 @@ def get_color(name: str, alpha: float = 1.0) -> imgui.ImVec4:
|
||||
|
||||
# 2. Hardcoded fallbacks if not in TOML (matches ThemePalette defaults)
|
||||
fallbacks = {
|
||||
"text": (200, 200, 200),
|
||||
"text_disabled": (130, 130, 130),
|
||||
"status_success": (80, 255, 80),
|
||||
"status_warning": (255, 152, 48),
|
||||
"status_error": (255, 72, 64),
|
||||
"status_info": (0, 255, 255),
|
||||
"bubble_user": (30, 45, 75),
|
||||
"bubble_ai": (35, 65, 45),
|
||||
"bubble_vendor": (65, 55, 30),
|
||||
"bubble_system": (25, 25, 25),
|
||||
"slice_manual": (255, 165, 0),
|
||||
"slice_auto": (0, 255, 0),
|
||||
"slice_selection": (100, 100, 255),
|
||||
"diff_added": (51, 230, 51),
|
||||
"diff_removed": (230, 51, 51),
|
||||
"diff_header": (77, 178, 255),
|
||||
"text": (200, 200, 200),
|
||||
"text_disabled": (130, 130, 130),
|
||||
"status_success": (80, 255, 80),
|
||||
"status_warning": (255, 152, 48),
|
||||
"status_error": (255, 72, 64),
|
||||
"status_info": (0, 255, 255),
|
||||
"bubble_user": (30, 45, 75),
|
||||
"bubble_ai": (35, 65, 45),
|
||||
"bubble_vendor": (65, 55, 30),
|
||||
"bubble_system": (25, 25, 25),
|
||||
"slice_manual": (255, 165, 0),
|
||||
"slice_auto": (0, 255, 0),
|
||||
"slice_selection": (100, 100, 255),
|
||||
"diff_added": (51, 230, 51),
|
||||
"diff_removed": (230, 51, 51),
|
||||
"diff_header": (77, 178, 255),
|
||||
"table_header_text": (255, 255, 255),
|
||||
"table_row_bg": (0, 0, 0),
|
||||
"table_row_bg_alt": (10, 10, 10),
|
||||
"table_row_bg": (0, 0, 0),
|
||||
"table_row_bg_alt": (10, 10, 10),
|
||||
}
|
||||
if name in fallbacks:
|
||||
rgb = fallbacks[name]
|
||||
@@ -202,8 +202,8 @@ def get_color(name: str, alpha: float = 1.0) -> imgui.ImVec4:
|
||||
def get_role_tint(role: str) -> imgui.ImVec4:
|
||||
"""Returns a subtle background tint color based on the message role."""
|
||||
mapping = {
|
||||
"User": "bubble_user",
|
||||
"AI": "bubble_ai",
|
||||
"User": "bubble_user",
|
||||
"AI": "bubble_ai",
|
||||
"Vendor API": "bubble_vendor",
|
||||
}
|
||||
return get_color(mapping.get(role, "bubble_system"), alpha=0.6)
|
||||
@@ -213,7 +213,6 @@ def apply(palette_name: str) -> None:
|
||||
global _current_palette
|
||||
_current_palette = palette_name
|
||||
if palette_name == 'NERV':
|
||||
from src import theme_nerv
|
||||
theme_nerv.apply_nerv()
|
||||
apply_syntax_palette(get_syntax_palette_for_theme(palette_name))
|
||||
return
|
||||
@@ -228,7 +227,7 @@ def apply(palette_name: str) -> None:
|
||||
elif palette_name in _TOML_PALETTES:
|
||||
colours = _TOML_COLOUR_CACHE.get(palette_name, {})
|
||||
if not colours:
|
||||
theme = _TOML_PALETTES[palette_name]
|
||||
theme = _TOML_PALETTES[palette_name]
|
||||
colours = _build_imgui_colour_dict(theme)
|
||||
_TOML_COLOUR_CACHE[palette_name] = colours
|
||||
imgui.style_colors_dark()
|
||||
@@ -243,33 +242,33 @@ def apply(palette_name: str) -> None:
|
||||
|
||||
# 2. Professional tweaks
|
||||
style = imgui.get_style()
|
||||
style.window_rounding = 6.0
|
||||
style.child_rounding = 4.0
|
||||
style.frame_rounding = 4.0
|
||||
style.popup_rounding = 4.0
|
||||
style.window_rounding = 6.0
|
||||
style.child_rounding = 4.0
|
||||
style.frame_rounding = 4.0
|
||||
style.popup_rounding = 4.0
|
||||
style.scrollbar_rounding = 12.0
|
||||
style.grab_rounding = 4.0
|
||||
style.tab_rounding = 4.0
|
||||
style.grab_rounding = 4.0
|
||||
style.tab_rounding = 4.0
|
||||
style.window_border_size = 1.0
|
||||
style.frame_border_size = 1.0
|
||||
style.popup_border_size = 1.0
|
||||
style.frame_border_size = 1.0
|
||||
style.popup_border_size = 1.0
|
||||
|
||||
win_bg = style.color_(imgui.Col_.window_bg)
|
||||
win_bg = style.color_(imgui.Col_.window_bg)
|
||||
win_bg.w = _transparency
|
||||
style.set_color_(imgui.Col_.window_bg, win_bg)
|
||||
|
||||
for col_idx in [imgui.Col_.child_bg, imgui.Col_.frame_bg, imgui.Col_.popup_bg]:
|
||||
c = style.color_(col_idx)
|
||||
c = style.color_(col_idx)
|
||||
c.w = _child_transparency
|
||||
style.set_color_(col_idx, c)
|
||||
|
||||
style.window_padding = imgui.ImVec2(8.0, 8.0)
|
||||
style.frame_padding = imgui.ImVec2(8.0, 4.0)
|
||||
style.item_spacing = imgui.ImVec2(8.0, 4.0)
|
||||
style.item_inner_spacing = imgui.ImVec2(4.0, 4.0)
|
||||
style.scrollbar_size = 14.0
|
||||
style.anti_aliased_lines = True
|
||||
style.anti_aliased_fill = True
|
||||
style.window_padding = imgui.ImVec2(8.0, 8.0)
|
||||
style.frame_padding = imgui.ImVec2(8.0, 4.0)
|
||||
style.item_spacing = imgui.ImVec2(8.0, 4.0)
|
||||
style.item_inner_spacing = imgui.ImVec2(4.0, 4.0)
|
||||
style.scrollbar_size = 14.0
|
||||
style.anti_aliased_lines = True
|
||||
style.anti_aliased_fill = True
|
||||
style.anti_aliased_lines_use_tex = True
|
||||
|
||||
# 3. Sync syntax palette and clear markdown render cache
|
||||
@@ -299,18 +298,18 @@ def get_palette_names() -> list[str]:
|
||||
def save_to_config(config: dict) -> None:
|
||||
"""Persist theme settings into the config dict."""
|
||||
config.setdefault("theme", {})
|
||||
config["theme"]["palette"] = _current_palette
|
||||
config["theme"]["font_path"] = _current_font_path
|
||||
config["theme"]["font_size"] = _current_font_size
|
||||
config["theme"]["scale"] = _current_scale
|
||||
config["theme"]["transparency"] = _transparency
|
||||
config["theme"]["palette"] = _current_palette
|
||||
config["theme"]["font_path"] = _current_font_path
|
||||
config["theme"]["font_size"] = _current_font_size
|
||||
config["theme"]["scale"] = _current_scale
|
||||
config["theme"]["transparency"] = _transparency
|
||||
config["theme"]["child_transparency"] = _child_transparency
|
||||
tm = {}
|
||||
for p in set(list(_brightness.keys()) + list(_contrast.keys()) + list(_gamma.keys())):
|
||||
tm[p] = {
|
||||
"brightness": _brightness.get(p, 1.0),
|
||||
"contrast": _contrast.get(p, 1.0),
|
||||
"gamma": _gamma.get(p, 1.0)
|
||||
"contrast": _contrast.get(p, 1.0),
|
||||
"gamma": _gamma.get(p, 1.0)
|
||||
}
|
||||
config["theme"]["tone_mapping"] = tm
|
||||
|
||||
@@ -322,15 +321,15 @@ def load_from_config(config: dict) -> None:
|
||||
_current_palette = t.get("palette", "10x Dark")
|
||||
if _current_palette in ("", "DPG Default"):
|
||||
_current_palette = "10x Dark"
|
||||
_current_font_path = t.get("font_path", "fonts/Inter-Regular.ttf")
|
||||
_current_font_size = float(t.get("font_size", 16.0))
|
||||
_current_scale = float(t.get("scale", 1.0))
|
||||
_transparency = float(t.get("transparency", 1.0))
|
||||
_current_font_path = t.get("font_path", "fonts/Inter-Regular.ttf")
|
||||
_current_font_size = float(t.get("font_size", 16.0))
|
||||
_current_scale = float(t.get("scale", 1.0))
|
||||
_transparency = float(t.get("transparency", 1.0))
|
||||
_child_transparency = float(t.get("child_transparency", 1.0))
|
||||
tm = t.get("tone_mapping", {})
|
||||
tm = t.get("tone_mapping", {})
|
||||
_brightness = {p: float(v.get("brightness", 1.0)) for p, v in tm.items()}
|
||||
_contrast = {p: float(v.get("contrast", 1.0)) for p, v in tm.items()}
|
||||
_gamma = {p: float(v.get("gamma", 1.0)) for p, v in tm.items()}
|
||||
_contrast = {p: float(v.get("contrast", 1.0)) for p, v in tm.items()}
|
||||
_gamma = {p: float(v.get("gamma", 1.0)) for p, v in tm.items()}
|
||||
|
||||
# ------------------------------------------------------------------ external themes
|
||||
|
||||
@@ -341,8 +340,8 @@ def load_themes_from_disk() -> None:
|
||||
loaded: dict[str, ThemeFile] = {}
|
||||
if themes_dir.exists() and themes_dir.is_dir():
|
||||
loaded.update(load_themes_from_dir(themes_dir, scope="global"))
|
||||
_TOML_PALETTES = loaded
|
||||
_TOML_COLOUR_CACHE = {name: _build_imgui_colour_dict(t) for name, t in loaded.items()}
|
||||
_TOML_PALETTES = loaded
|
||||
_TOML_COLOUR_CACHE = {name: _build_imgui_colour_dict(t) for name, t in loaded.items()}
|
||||
_TOML_SEMANTIC_CACHE = {name: _build_semantic_colour_dict(t) for name, t in loaded.items()}
|
||||
|
||||
def get_syntax_palette_for_theme(theme_name: str) -> str:
|
||||
|
||||
Reference in New Issue
Block a user