3.1 KiB
3.1 KiB
Theme Polish & Tone Mapping
Problem
- Missing Theme Colors: The
ThemePalettedataclass insrc/theme_models.pyonly defined a subset of the ~55 ImGui colors. Becausefrom_dictstrictly matched dataclass fields, colors likeresize_gripandtab_dimmedfrom the TOML files were being discarded, breaking window resizing handles and inactive tab styling. - Context Preview Syntax Palette:
theme_2.apply()failed to apply the syntax palette for non-NERV themes, andsrc/markdown_helper.pycached itsTextEditorinstances without clearing them on theme switch. This caused "Context Preview" to remain stuck on the previous theme's syntax colors. - Light Theme Brightness: The user requested a way to dim light themes. We will introduce a Tone Mapping system (Brightness, Contrast, Gamma) that mathematical adjusts the RGB colors before applying them to ImGui. The user requested this to be saved per-palette so each theme can have its own exposure profile.
Proposed Solution
1. Fix Theme Models
- Ensure
src/theme_models.py'sThemePalettedataclass has all missing ImGui colors (e.g.,resize_grip,resize_grip_active,resize_grip_hovered,tab_dimmed,tab_dimmed_selected,docking_preview,plot_lines,nav_windowing_highlight, etc.). (Note: I proactively applied the class definition update during exploration, but will formally commit it).
2. Fix Context Preview Syntax Highlight Sync
- Update
src/theme_2.pyto ensureapply_syntax_palette()is called for all themes duringapply(). - Add an
import src.markdown_helper; src.markdown_helper.get_renderer().clear_cache()call to the end oftheme_2.apply()to force code blocks to recreate theirTextEditorinstances with the new palette.
3. Per-Palette Tone Mapping
- Add mathematical tone mapping variables to
src/theme_2.py:_brightness,_contrast, and_gamma(stored as dictionaries keyed by the palette name to allow per-palette saving). - Implement a math function to adjust RGB floats:
- Brightness:
c * brightness - Contrast:
(c - 0.5) * contrast + 0.5 - Gamma:
pow(c, 1.0 / gamma)
- Brightness:
- Update the palette application loop in
theme_2.apply()to pass every color float through this tone mapper before callingstyle.set_color_(). - Update
save_to_configandload_from_configto persist the tone mapping overrides per-palette under[theme.tone_mapping.<palette>]. - Add Brightness, Contrast, and Gamma sliders to the Theme panel in
src/gui_2.py.
Implementation Steps
- Model & Sync Fixes: Verify
src/theme_models.pyand updatesrc/theme_2.py'sapply()function to trigger syntax updates and markdown cache clearing. - Tone Mapping Logic: Add the dicts and the math
_tone_map(rgb, palette)function totheme_2.py, wrapping all color assignments. - State Persistence: Update
save_to_config/load_from_configto handle the new per-palette dictionary. - UI Integration: Add the 3 sliders to
_render_theme_panelinsrc/gui_2.py, complete with a "Reset to Defaults" button for the current palette. - Testing: Run the existing test suite and verify no regressions in config saving.