Name the set in a canceled bake's log line, make a bake setting drag one undo step and hold Auto-rebake while it is held

A drag stays one undo step while a panel is open in its own floating
window: the press is kept in egui memory, not in a frame cache that the
floating window's own pass clears every frame.
This commit is contained in:
Rebornim committed 2026-11-27 06:13:17 +00:00
1 parent ff51384164
commit cb8a46deb7
8 files changed
+103 -11

No files matched your search

+3 -1
View File
@@ -31,7 +31,9 @@ impl Session {
self.edit("Bake mesh maps", |session| {
session.store_bake_maps(texture_set, finished.resolution, height, finished.maps, Some((&kept_sources, painted_stroke)))
})?;
self.log.info("Baker", format!("Kept {} baked maps of texture set {texture_set} from the canceled bake", kept.len()));
// Named like the Texture Set List and the progress footer, which count sets from 1
let name = self.doc.project.texture_sets.get(texture_set).map_or_else(|| format!("{}", texture_set + 1), |set| set.name.clone());
self.log.info("Baker", format!("Kept {} baked maps of texture set {name} from the canceled bake", kept.len()));
Ok(kept)
}
}
+14
View File
@@ -158,3 +158,17 @@ fn a_canceled_bake_keeps_the_out_of_date_mark_of_a_map_it_did_not_finish() {
assert_eq!(kept, [BakedMap::Id]);
assert!(!session.bake_changes(0, BakedMap::Position).is_empty(), "Position still has its old pixels, so it stays out of date");
}
#[test]
fn a_canceled_bakes_log_line_names_the_set_as_the_texture_set_list_does() {
let mut session = sample_session(256, 64).unwrap();
let stored = session.baked(0).cloned().unwrap();
let (map, data) = stored.maps.iter().next().map(|(map, data)| (*map, data.clone())).unwrap();
let finished = BakedMaps { resolution: stored.resolution, maps: [(map, data)].into() };
session.keep_canceled_bake(0, finished, &Default::default(), 0).unwrap();
let name = session.doc.project.texture_sets[0].name.clone();
let line = session.log.iter().find(|line| line.contains("canceled bake")).map(|line| line.message.clone()).unwrap();
assert!(line.contains(&format!("texture set {name} ")), "the first set is not numbered 0: {line}");
}
+6
View File
@@ -46,6 +46,12 @@ pub(crate) fn poll(app: &mut TextureCraftApp, ctx: &egui::Context) {
let now = app.last_time;
ctx.request_repaint_after(std::time::Duration::from_secs_f64(SETTLE_SECONDS));
// A held press (a slider dragged and paused) is still editing: the wait starts once it is let go
if ctx.input(|input| input.pointer.any_down()) {
app.auto_rebake.pending = Some((waiting, now));
return;
}
match &app.auto_rebake.pending {
Some((seen, since)) if *seen == waiting && now - since >= SETTLE_SECONDS => {}
Some((seen, _)) if *seen == waiting => return,
+4 -4
View File
@@ -231,15 +231,15 @@ fn edit_settings(
let mut settings = before.clone();
let reset = egui::ScrollArea::vertical().id_salt(scroll_id).auto_shrink([false; 2]).show(ui, |ui| contents(app, ui, &mut settings)).inner;
if settings == before && reset.is_none() {
return false;
}
// One drag is one undo step: a press's later changes continue its first one
let Some(merge) = crate::widgets::press_edit(ui, ui.make_persistent_id((scroll_id, "press")), settings != before || reset.is_some()) else { return false };
let mut patch = settings_patch(&before, &settings);
if let (Some(fields), Some(Value::Object(reset))) = (patch.as_object_mut(), reset) {
fields.extend(reset);
}
app.run("bake.settings", json!({ "ts": texture_sets, "patch": patch }));
app.run("bake.settings", json!({ "ts": texture_sets, "patch": patch, "merge": merge }));
true
}
@@ -1042,6 +1042,28 @@ fn a_reopened_editor_starts_a_new_undo_step_after_a_hidden_release() {
assert_eq!(edit(Some(owner), true), Some(false), "a separate press starts an undo step after reopening");
}
/// A floating panel in its own OS window runs a pass of its own between two frames of the main window: the drag stays one undo step
#[test]
fn a_drag_stays_one_undo_step_while_another_window_draws() {
let context = egui::Context::default();
let owner = egui::Id::unique("held editor");
let edit = |events| {
let mut result = None;
let mut output = context.run_ui(egui::RawInput { events, ..Default::default() }, |ui| result = crate::widgets::press_edit(ui, owner, true));
output.textures_delta.clear();
result
};
let press = egui::Event::PointerButton { pos: egui::Pos2::ZERO, button: egui::PointerButton::Primary, pressed: true, modifiers: egui::Modifiers::NONE };
assert_eq!(edit(vec![press]), Some(false), "the press starts an undo step");
let viewport = egui::ViewportId::from_hash_of("floating History");
let floating =
egui::RawInput { viewport_id: viewport, viewports: std::iter::once((viewport, egui::ViewportInfo::default())).collect(), ..Default::default() };
context.run_ui(floating, |_| {}).textures_delta.clear();
assert_eq!(edit(Vec::new()), Some(true), "the held press continues its undo step");
}
#[test]
fn section_tabs_show_focus_before_a_keyboard_jump() {
let mut harness = builder(Brightness::MediumDark).build_ui(|ui| {
+14 -6
View File
@@ -31,26 +31,34 @@ pub(crate) fn press_edit(ui: &Ui, id: egui::Id, changed: bool) -> Option<bool> {
return None;
}
ui.memory_mut(|memory| {
let edits = memory.caches.cache::<egui::cache::FramePublisher<egui::Id, u64>>();
// Kept in memory, not a frame cache: a floating panel in its own OS window ends a pass of its own inside ours, which would clear it every frame
let frame = ui.ctx().cumulative_frame_nr();
ui.data_mut(|data| {
let id = id.with("pointer edit");
let previous = edits.get(&id).copied();
let previous = data.get_temp::<PressEdit>(id);
let merge = match press {
Some(start) => {
let continuing = previous == Some(start);
let continuing = previous.is_some_and(|previous| previous.press == start);
if changed || continuing {
edits.set(id, start);
data.insert_temp(id, PressEdit { press: start, frame });
}
continuing
}
// A final movement still belongs to the press that ended
None => release_only && previous.is_some(),
None => release_only && previous.is_some_and(|previous| previous.frame + 1 >= frame),
};
changed.then_some(merge)
})
}
/// The press an editor's last change belonged to, and the frame it was seen in
#[derive(Clone, Copy)]
struct PressEdit {
press: u64,
frame: u64,
}
/// [`slider`] for a value re-read from the document every frame: `Some(merge)` on every frame
/// that changes `value` (live while dragging, a click on the track, a typed value). `merge` is
/// true for the later changes of one drag, so the edit that applies them (with the command's
+15
View File
@@ -159,3 +159,18 @@ fn the_rows_icon_turns_auto_rebake_on_for_its_map_and_off_again() {
harness.run_steps(2);
assert_eq!(auto_rebake(&harness), None);
}
#[test]
fn no_rebake_starts_while_the_pointer_is_held_so_a_paused_drag_stays_one_undo_step() {
let mut harness = harness(64);
change_settings(&mut harness, json!({ "positionMode": "boundingBox" }));
// Held still well past the settle time, as a hand pausing mid-drag
let corner = egui::pos2(1590.0, 990.0);
harness.drag_at(corner);
harness.run_steps(120);
assert!(harness.state().bake.is_none(), "the edit is not over while the press lasts");
harness.drop_at(corner);
super::step_until(&mut harness, "the rebake after the release", |app| app.bake.is_some());
}
+25
View File
@@ -737,3 +737,28 @@ fn a_baked_maps_row_shows_out_of_date_once_its_settings_change() {
harness.get_by_label("Out of date: Position");
assert!(harness.query_by_label("Out of date: Normal").is_none(), "never baked: not out of date");
}
#[test]
fn dragging_secondary_rays_is_one_undo_step() {
let mut harness = harness(Some(BakedMap::AmbientOcclusion));
select_map(&mut harness, "Ambient Occlusion");
let rays_before = harness.state().session.doc.project.texture_sets[0].bake.maps.ao.parameters.rays.rays;
let history_steps = harness.state().session.history_labels().len();
let track = harness.get_by_role_and_label(Role::Slider, "Secondary Rays").rect();
let at = |share: f32| egui::pos2(track.left() + track.width() * share, track.center().y);
harness.drag_at(at(0.2));
harness.run_steps(crate::DRAG_STEP_FRAMES);
for step in 1..=3 {
harness.hover_at(at(0.2 + 0.15 * step as f32));
harness.run_steps(crate::DRAG_STEP_FRAMES);
}
// The release moves too, and that last change still belongs to the drag
harness.drop_at(at(0.8));
harness.run_steps(crate::SETTLE_FRAMES);
let session = &harness.state().session;
assert_ne!(session.doc.project.texture_sets[0].bake.maps.ao.parameters.rays.rays, rays_before, "the drag changed the rays");
assert_eq!(session.history_labels().len(), history_steps + 1, "{:?}", session.history_labels());
}