UI Theme editor: Dracula preset, canvas follows theme

- Fifth built-in preset: Dracula (#282a36 bg, #ff79c6 keyword), same
  colours in both designers.
- The canvas background now follows the UI theme when the project has
  no window background of its own (project background still wins);
  View -> Color Theme Apply repaints code view + canvas, and the saved
  theme is applied to the canvas at startup.
- Theme tests + selftest updated to 5 built-ins with Dracula checks.
- Verified: make 0 warnings, SELFTEST PASS 29, theme tests 60/0,
  palette self-test 583/583; all five presets + a custom colour
  applied live under Xvfb and persisted across a restart.
This commit is contained in:
cnmcdee committed 2026-11-29 14:56:07 +00:00
1 parent e7d35b6d9b
commit d48d49f60c
4 files changed
+40 -12

No files matched your search

+22 -6
View File
@@ -908,13 +908,23 @@ static void set_project_size(int w, int h) {
gtk_widget_set_size_request(g_canvas, w, h);
}
// Effective canvas background: the project's own window background
// wins; with no project background the UI theme background shows, so
// View -> UI Theme recolours the canvas too (not just the code view).
static void apply_canvas_background() {
std::string bg = g_project.background.empty()
? theme_current().background
: g_project.background;
std::string css = "* { background: " + bg + "; }";
if (g_canvas_css && g_viewport)
gtk_css_provider_load_from_data(g_canvas_css, css.c_str(), -1, nullptr);
}
static void set_project_background(const std::string& raw) {
GdkRGBA rgba;
if (!raw.empty() && !gdk_rgba_parse(&rgba, raw.c_str())) return;
g_project.background = raw;
std::string css = raw.empty() ? "" : "* { background: " + raw + "; }";
if (g_canvas_css && g_viewport)
gtk_css_provider_load_from_data(g_canvas_css, css.c_str(), -1, nullptr);
apply_canvas_background();
}
// ------------------------------------------------------- chart plotting
@@ -4146,17 +4156,21 @@ static gboolean selftest_step(gpointer) {
// Phase 10: color themes + code-view gutter / folding.
{
// Four distinct built-ins; unknown name falls back to Light.
// Five distinct built-ins; unknown name falls back to Light.
std::vector<std::string> tnames = CodeTheme::builtin_names();
check(tnames.size() == 4);
check(tnames.size() == 5);
CodeTheme light = CodeTheme::builtin("Light");
CodeTheme dark = CodeTheme::builtin("Dark");
CodeTheme mono = CodeTheme::builtin("Monokai");
CodeTheme solar = CodeTheme::builtin("Solarized Dark");
CodeTheme drac = CodeTheme::builtin("Dracula");
check(light.keyword != dark.keyword &&
dark.keyword != mono.keyword &&
mono.keyword != solar.keyword);
mono.keyword != solar.keyword &&
solar.keyword != drac.keyword);
check(light.background != dark.background);
check(drac.background == "#282a36" && drac.keyword == "#ff79c6" &&
drac.foreground == "#f8f8f2");
check(CodeTheme::builtin("Nope").name == "Light");
check(CodeTheme::valid_color("#1a2b3c") &&
!CodeTheme::valid_color("red") &&
@@ -4517,6 +4531,7 @@ int main(int argc, char** argv) {
gtk_style_context_add_provider(
gtk_widget_get_style_context(g_viewport),
GTK_STYLE_PROVIDER(g_canvas_css), GTK_STYLE_PROVIDER_PRIORITY_USER);
apply_canvas_background();
}
GObject* quit = gtk_builder_get_object(builder, "mi_quit");
@@ -4576,6 +4591,7 @@ int main(int argc, char** argv) {
if (g_codeview)
codeview_set_theme(
g_codeview, t);
apply_canvas_background();
});
}),
nullptr);
+7 -1
View File
@@ -96,7 +96,7 @@ bool CodeTheme::valid_color(const std::string& s) {
}
std::vector<std::string> CodeTheme::builtin_names() {
return {"Light", "Dark", "Monokai", "Solarized Dark"};
return {"Light", "Dark", "Monokai", "Solarized Dark", "Dracula"};
}
CodeTheme CodeTheme::builtin(const std::string& name) {
@@ -119,6 +119,12 @@ CodeTheme CodeTheme::builtin(const std::string& name) {
t.keyword = "#859900"; t.type = "#2aa198"; t.string = "#b58900";
t.comment = "#586e75"; t.number = "#d33682";
t.preprocessor = "#cb4b16"; t.current_line = "#073642";
} else if (name == "Dracula") {
t.name = "Dracula";
t.background = "#282a36"; t.foreground = "#f8f8f2";
t.keyword = "#ff79c6"; t.type = "#8be9fd"; t.string = "#f1fa8c";
t.comment = "#6272a4"; t.number = "#bd93f9";
t.preprocessor = "#ffb86c"; t.current_line = "#44475a";
} else {
t.name = "Light"; // default, incl. unknown names
}
+2 -2
View File
@@ -1,6 +1,6 @@
// LightGUI code-view color themes — syntax-highlighting themes for the
// code view (src/codeview.h). Four built-ins: Light, Dark, Monokai,
// Solarized Dark. Each theme colours keywords, types, strings, comments,
// code view (src/codeview.h). Five built-ins: Light, Dark, Monokai,
// Solarized Dark, Dracula. Each theme colours keywords, types, strings, comments,
// numbers, preprocessor lines, plus the view background/foreground and
// the current-execution-line background.
//
+9 -3
View File
@@ -82,18 +82,24 @@ int main(int argc, char** argv) {
// 1. Built-in themes.
std::vector<std::string> names = CodeTheme::builtin_names();
check(names.size() == 4, "builtins-count-4");
check(names.size() == 5, "builtins-count-5");
check(names[0] == "Light" && names[1] == "Dark" &&
names[2] == "Monokai" && names[3] == "Solarized Dark",
names[2] == "Monokai" && names[3] == "Solarized Dark" &&
names[4] == "Dracula",
"builtins-names");
CodeTheme light = CodeTheme::builtin("Light");
CodeTheme dark = CodeTheme::builtin("Dark");
CodeTheme mono = CodeTheme::builtin("Monokai");
CodeTheme solar = CodeTheme::builtin("Solarized Dark");
CodeTheme drac = CodeTheme::builtin("Dracula");
check(light.keyword != dark.keyword &&
dark.keyword != mono.keyword &&
mono.keyword != solar.keyword,
mono.keyword != solar.keyword &&
solar.keyword != drac.keyword,
"builtins-distinct-keywords");
check(drac.background == "#282a36" && drac.keyword == "#ff79c6" &&
drac.foreground == "#f8f8f2",
"dracula-colours");
check(light.background != dark.background &&
dark.background != mono.background,
"builtins-distinct-backgrounds");