Merge pull request #4848 from dotCooCoo/fix/issue-4837

Fix #4837: the saved color scheme, accent and canvas color show at launch
This commit is contained in:
BFlat
2026-10-31 20:08:36 +07:00
committed by GitHub
3 changed files with 34 additions and 2 deletions
+2 -1
View File
@@ -400,7 +400,8 @@ impl VectorcraftApp {
crate::ime::install_hooks(ctx);
self.adopt_context(ctx);
if !self.styled {
theme::apply(ctx, self.ui.brightness);
// The saved accent, color scheme and canvas color, not the defaults (#4837).
prefs_dialog::reapply(self, ctx);
egui_extras::install_image_loaders(ctx);
self.styled = true;
}
+13 -1
View File
@@ -125,7 +125,7 @@ pub fn apply_runtime(app: &mut VectorcraftApp, ctx: &egui::Context) {
scrub: p.scrub_numeric_fields,
bare_points: p.numbers_without_units_are_points,
};
let id = egui::Id::unique("dc-applied-prefs");
let id = applied_id();
let prev: Option<Applied> = ctx.data(|d| d.get_temp::<Option<Applied>>(id)).flatten();
if prev != Some(want) {
theme::apply_with(ctx, want.brightness, want.accent, want.scheme);
@@ -160,6 +160,18 @@ pub fn apply_runtime(app: &mut VectorcraftApp, ctx: &egui::Context) {
}
}
/// Where [`apply_runtime`] keeps the preferences it last pushed into `ctx`.
fn applied_id() -> egui::Id {
egui::Id::unique("dc-applied-prefs")
}
/// [`apply_runtime`] with nothing recorded as applied, so the theme (brightness, accent, color
/// scheme and canvas color) and the other UI-side preferences are pushed into `ctx` again.
pub(crate) fn reapply(app: &mut VectorcraftApp, ctx: &egui::Context) {
ctx.data_mut(|d| d.remove::<Option<Applied>>(applied_id()));
apply_runtime(app, ctx);
}
pub fn show(app: &mut VectorcraftApp, ctx: &egui::Context) {
let Some(mut d) = app.ui.dialog.clone() else { return };
let t = Tokens::get(ctx);
+19
View File
@@ -60,6 +60,25 @@ fn canvas_color_choices_paint_the_pasteboard() {
assert!(app.run("prefs.set", serde_json::json!({"key": "canvasColor", "value": "pink"})).is_err());
}
/// #4837: the saved Color Scheme, Accent and Canvas Color are the ones the first frame shows, not
/// the defaults the first UI pass installs.
#[test]
fn saved_scheme_accent_and_canvas_color_show_from_the_first_frame() {
let mut app = app();
for (key, value) in [("uiColorScheme", "classic"), ("uiAccent", "pink"), ("canvasColor", "white")] {
app.run("prefs.set", json!({"key": key, "value": value})).unwrap();
}
let ctx = egui::Context::default();
for _ in 0..2 {
let mut out = ctx.run_ui(egui::RawInput::default(), |ui| app.logic(ui.ctx()));
out.textures_delta.clear();
let (t, classic) = (Tokens::get(&ctx), Tokens::for_scheme(Scheme::Classic, app.ui.brightness, Accent::Pink));
assert_eq!((t.accent, t.app_bar, t.panel), (classic.accent, classic.app_bar, classic.panel));
assert_eq!(t.pasteboard, egui::Color32::WHITE);
assert_eq!(ctx.global_style().visuals.hyperlink_color, classic.accent);
}
}
fn app() -> VectorcraftApp {
VectorcraftApp::new(Session::new(), Services::default())
}