Show History steps as flat rows with the current step outlined

The History panel lists every step as a full-width row: the current step
is outlined in the accent, the pointer's row gets a soft band, undone
steps stay dim and clickable. The Undo and Redo buttons under the list
are gone; undo and redo stay in the Edit menu and on Ctrl+Z / Ctrl+Y.

Part of #890.
This commit is contained in:
Rebornim committed 2026-11-28 11:59:48 +00:00
1 parent 7c8dd1ae4e
commit 178e2d1928
4 files changed
+124 -57

No files matched your search

+9 -2
View File
@@ -583,6 +583,9 @@ struct Panels<'a> {
/// Room between a panel's edges and its contents
const PANEL_BODY_MARGIN: Margin = Margin::symmetric(8, 4);
/// Room around a panel of full-width list rows: none at the sides
const LIST_PANEL_MARGIN: Margin = Margin::symmetric(0, 4);
/// Narrowest Properties panel and so its dock column: the 300 point design width plus the solid scroll bar; narrower, the 3D projection settings' X, Y, Z fields (the widest row) overlap
pub const PROPERTIES_MIN_WIDTH: f32 = 310.0;
@@ -613,8 +616,12 @@ pub(crate) fn panel_body(app: &mut TextureCraftApp, ui: &mut Ui, panel: Panel) {
return;
}
// Properties draws full-width bands and tabs, so it keeps its own margins
let margin = if panel == Panel::Properties { Margin::ZERO } else { PANEL_BODY_MARGIN };
// Properties draws full-width bands and tabs and History full-width rows, so they draw their own side margins
let margin = match panel {
Panel::Properties => Margin::ZERO,
Panel::History => LIST_PANEL_MARGIN,
_ => PANEL_BODY_MARGIN,
};
egui::Frame::new().inner_margin(margin).show(ui, |ui| match panel {
Panel::MeshMapSettings => crate::bake_mode::mesh_map_settings_panel(app, ui),
Panel::Assets => crate::shelf::body(app, ui),
+56 -36
View File
@@ -1,9 +1,6 @@
//! Floating windows and the dockable History panel
#[cfg(any(target_arch = "wasm32", test))]
use egui::vec2;
use egui::{RichText, Ui};
use egui_phosphor::regular as ic;
use egui::{RichText, Ui, vec2};
use serde_json::json;
use crate::TextureCraftApp;
@@ -249,45 +246,40 @@ pub(crate) fn dialog_scroll_margin(ui: &egui::Ui) -> egui::Margin {
margin
}
/// The History panel body (a dock tab)
/// The height of one History row
const HISTORY_ROW_HEIGHT: f32 = 21.0;
/// Where a History row's name starts, from the panel's left edge
const HISTORY_NAME_LEFT: f32 = 12.0;
const HISTORY_NAME_SIZE: f32 = 12.0;
/// The current step's outline sits inside the row: a little air at the left, less before the scrollbar
const HISTORY_MARK_INSET_LEFT: f32 = 4.0;
const HISTORY_MARK_INSET_RIGHT: f32 = 3.0;
/// The History panel body (a dock tab): one row per step, the current one outlined
pub(crate) fn history(app: &mut TextureCraftApp, ui: &mut Ui) {
let tokens = Tokens::get(ui.ctx());
let (done, undone) = (app.session.history_labels(), app.session.redo_labels());
let done_count = done.len() as i64;
let rows = std::iter::once((tr("Project opened").to_owned(), tokens.text_dim))
.chain(done.iter().map(|label| (tr_history(label), tokens.text)))
.chain(undone.iter().map(|label| (trf("{action} (undone)", &[("action", &tr_history(label))]), tokens.text_dim)));
// A click on a step goes back (or forward) to it: steps to undo, or to redo when negative
let mut jump = 0i64;
// Bottom up: the Undo and Redo row keeps its place under a list that fills the rest of the panel
ui.with_layout(egui::Layout::bottom_up(egui::Align::Min), |ui| {
ui.horizontal(|ui| {
if ui.add_enabled(app.session.can_undo(), egui::Button::new(format!("{} {}", ic::ARROW_COUNTER_CLOCKWISE, tr("Undo")))).clicked() {
app.run("edit.undo", json!({}));
egui::ScrollArea::vertical().auto_shrink([false, false]).show(ui, |ui| {
ui.spacing_mut().item_spacing.y = 0.0;
for (row, (name, color)) in rows.enumerate() {
// Each row is the state after that many steps
let steps = done_count - row as i64;
if history_row(ui, &tokens, &name, color, steps == 0).on_hover_text(tr("Return to this step")).clicked() {
// Point history is consumed before the document rows shown here
jump = if steps >= 0 {
app.session.history_undo_steps(steps as usize) as i64
} else {
-(app.session.history_redo_steps((-steps) as usize) as i64)
};
}
if ui.add_enabled(app.session.can_redo(), egui::Button::new(format!("{} {}", ic::ARROW_CLOCKWISE, tr("Redo")))).clicked() {
app.run("edit.redo", json!({}));
}
});
ui.with_layout(egui::Layout::top_down(egui::Align::Min), |ui| {
egui::ScrollArea::vertical().auto_shrink([false, false]).show(ui, |ui| {
let done_count = done.len() as i64;
let rows = std::iter::once(RichText::new(tr("Project opened")).color(tokens.text_dim))
.chain(done.iter().map(|label| RichText::new(tr_history(label))))
.chain(undone.iter().map(|label| RichText::new(trf("{action} (undone)", &[("action", &tr_history(label))])).color(tokens.text_dim)));
for (row, text) in rows.enumerate() {
// Each row is the state after that many steps
let steps = done_count - row as i64;
if ui.selectable_label(steps == 0, text).on_hover_text(tr("Return to this step")).clicked() {
// Point history is consumed before the document rows shown here
jump = if steps >= 0 {
app.session.history_undo_steps(steps as usize) as i64
} else {
-(app.session.history_redo_steps((-steps) as usize) as i64)
};
}
}
});
});
}
});
if jump > 0 {
@@ -297,6 +289,34 @@ pub(crate) fn history(app: &mut TextureCraftApp, ui: &mut Ui) {
}
}
/// One History row across the panel: a band under the pointer, the current step outlined
fn history_row(ui: &mut Ui, tokens: &Tokens, name: &str, color: egui::Color32, current: bool) -> egui::Response {
let (rect, response) = ui.allocate_exact_size(vec2(ui.available_width(), HISTORY_ROW_HEIGHT), egui::Sense::click());
response.widget_info(|| egui::WidgetInfo::selected(egui::Role::Button, true, current, name));
if !ui.is_rect_visible(rect) {
return response;
}
let painter = ui.painter().with_clip_rect(rect.intersect(ui.clip_rect()));
if current {
let mark = egui::Rect::from_min_max(rect.min + vec2(HISTORY_MARK_INSET_LEFT, 0.0), rect.max - vec2(HISTORY_MARK_INSET_RIGHT, 0.0));
painter.rect(mark, 0.0, tokens.field, egui::Stroke::new(1.0, tokens.accent), egui::StrokeKind::Inside);
} else if response.hovered() {
painter.rect_filled(rect, 0.0, tokens.row);
}
// A name too long for the row ends in an ellipsis, as far from the outline's right side as it starts from its left
let room = rect.width() - HISTORY_NAME_LEFT - HISTORY_MARK_INSET_RIGHT - (HISTORY_NAME_LEFT - HISTORY_MARK_INSET_LEFT);
let mut job = egui::text::LayoutJob::simple_singleline(name.to_owned(), egui::FontId::proportional(HISTORY_NAME_SIZE), color);
job.wrap = egui::text::TextWrapping::truncate_at_width(room.max(0.0));
let shown = painter.layout_job(job);
painter.galley(egui::pos2(rect.left() + HISTORY_NAME_LEFT, rect.center().y - shown.size().y / 2.0), shown, color);
if response.has_focus() {
crate::property_sheet::paint_focus_outline(&painter, rect, tokens.text_strong);
}
response
}
/// Browser File › Export Mesh: pick the download format
#[cfg(target_arch = "wasm32")]
fn export_mesh(app: &mut TextureCraftApp, ctx: &egui::Context) {
+50 -10
View File
@@ -1,7 +1,9 @@
//! A click on a step of the History panel goes back or forward to it.
use egui::accesskit::Toggled;
use egui::{Key, Modifiers};
use egui_kittest::Harness;
use egui_kittest::kittest::Queryable;
use egui_kittest::kittest::{NodeT, Queryable};
use serde_json::json;
use texturecraft_engine::geom::glam::Vec3;
use texturecraft_engine::{Session, execute};
@@ -19,6 +21,22 @@ fn history_harness(session: Session) -> Harness<'static, TextureCraftApp> {
harness
}
/// Undo or redo one step from the keyboard, as the Edit menu's shortcuts do
fn press(harness: &mut Harness<'_, TextureCraftApp>, key: Key) {
harness.key_press_modifiers(Modifiers::COMMAND, key);
harness.run_steps(3);
}
/// The rows the panel shows as the current step: name and top edge
fn current_rows(harness: &Harness<'_, TextureCraftApp>) -> Vec<(String, f32)> {
harness
.get_all_by_role(egui::accesskit::Role::Button)
.filter(|node| node.accesskit_node().toggled() == Some(Toggled::True))
.filter_map(|node| Some((node.accesskit_node().label()?, node.rect().top())))
.filter(|(name, _)| name.contains("Rename layer") || name == "Project opened")
.collect()
}
/// Three document rows provide an intermediate target that detects both short and excessive jumps
fn renamed_session() -> Session {
let mut session = texturecraft_engine::sample_session(256, 64).unwrap();
@@ -49,6 +67,7 @@ fn history_jump_accounts_for_drafts_with_and_without_an_empty_checkpoint() {
session.path_checkpoint();
let mut harness = history_harness(session);
// The list runs oldest first, so the first "Rename layer" row is the oldest step
harness.get_all_by_label("Rename layer").next().unwrap().click();
harness.run_steps(3);
@@ -60,7 +79,7 @@ fn history_jump_accounts_for_drafts_with_and_without_an_empty_checkpoint() {
}
}
/// A row jump traverses point history, while the Undo and Redo buttons still take one point step
/// A row jump traverses point history, while Ctrl+Z and Ctrl+Y still take one point step
#[test]
fn history_jump_accounts_for_stored_point_edits_without_changing_single_steps() {
let mut session = renamed_session();
@@ -77,12 +96,10 @@ fn history_jump_accounts_for_stored_point_edits_without_changing_single_steps()
let done = session.history_labels().len();
let mut harness = history_harness(session);
harness.get_by_label(&format!("{} Undo", egui_phosphor::regular::ARROW_COUNTER_CLOCKWISE)).click();
harness.run_steps(3);
press(&mut harness, Key::Z);
assert_eq!(harness.state().session.tool.path.points, moved);
assert_eq!(harness.state().session.history_labels().len(), done);
harness.get_by_label(&format!("{} Redo", egui_phosphor::regular::ARROW_CLOCKWISE)).click();
harness.run_steps(3);
press(&mut harness, Key::Y);
assert_eq!(harness.state().session.tool.path.points, original);
assert_eq!(harness.state().session.history_labels().len(), done);
@@ -91,6 +108,7 @@ fn history_jump_accounts_for_stored_point_edits_without_changing_single_steps()
assert_eq!(harness.state().session.tool.path.points, original);
assert_eq!(harness.state().session.history_labels().len(), done);
// The list runs oldest first, so the first "Rename layer" row is the oldest step
harness.get_all_by_label("Rename layer").next().unwrap().click();
harness.run_steps(3);
@@ -126,15 +144,14 @@ fn history_redo_jump_accounts_for_point_steps_without_changing_single_steps() {
assert_eq!(session.redo_labels().len(), 3);
let mut harness = history_harness(session);
harness.get_by_label(&format!("{} Redo", egui_phosphor::regular::ARROW_CLOCKWISE)).click();
harness.run_steps(3);
press(&mut harness, Key::Y);
assert_eq!(harness.state().session.tool.path.points.len(), 2);
assert_eq!(harness.state().session.history_labels().len(), done - 3);
harness.get_by_label(&format!("{} Undo", egui_phosphor::regular::ARROW_COUNTER_CLOCKWISE)).click();
harness.run_steps(3);
press(&mut harness, Key::Z);
assert_eq!(harness.state().session.tool.path.points, original);
assert_eq!(harness.state().session.history_labels().len(), done - 3);
// The last undone row is the newest step, so clicking it redoes up to the end
harness.get_all_by_label("Rename layer (undone)").last().unwrap().click();
harness.run_steps(3);
@@ -193,3 +210,26 @@ fn clicking_a_history_step_returns_to_it() {
assert_eq!(name(&h), "Step C");
assert!(!h.state().session.can_redo());
}
/// The panel has no Undo and Redo buttons; exactly one row reads as the current step, it moves with Ctrl+Z, and undone rows stay clickable
#[test]
fn only_the_current_step_is_marked_selected() {
let mut harness = history_harness(renamed_session());
// Undo and redo live in the Edit menu and on their shortcuts, not in a button row under the list
assert!(harness.query_by_label(&format!("{} Undo", egui_phosphor::regular::ARROW_COUNTER_CLOCKWISE)).is_none());
assert!(harness.query_by_label(&format!("{} Redo", egui_phosphor::regular::ARROW_CLOCKWISE)).is_none());
let before = current_rows(&harness);
assert_eq!(before.len(), 1);
assert_eq!(before[0].0, "Rename layer");
press(&mut harness, Key::Z);
let after = current_rows(&harness);
assert_eq!(after.len(), 1);
assert!(after[0].1 < before[0].1, "the outline moves up a row");
harness.get_by_label("Rename layer (undone)").click();
harness.run_steps(3);
assert!(harness.state().session.redo_labels().is_empty());
}
+9 -9
View File
@@ -256,19 +256,19 @@ fn display_settings_remain_reachable_in_a_short_window() {
assert!(harness.ctx.content_rect().contains_rect(setting), "the last setting must be reachable: {setting:?}");
}
/// The History panel has no Undo/Redo buttons (the Edit menu and Ctrl+Z/Ctrl+Y undo); its current step stays reachable
#[test]
fn history_actions_remain_reachable_in_a_short_window() {
fn the_current_history_step_remains_reachable_in_a_short_window() {
let mut harness = app_of_size(egui::vec2(1600.0, 400.0));
click_rail(&mut harness, "History");
for label in ["Undo", "Redo"] {
let button = harness
.get_all_by_role(Role::Button)
.find(|button| button.accesskit_node().label().is_some_and(|text| text.ends_with(label)))
.expect("the History action")
.rect();
assert!(harness.ctx.content_rect().contains_rect(button), "{label} must be reachable: {button:?}");
}
let name = harness.state().session.history_labels().last().cloned().unwrap_or_else(|| "Project opened".to_owned());
let current = harness
.get_all_by_role_and_label(Role::Button, &name)
.find(|row| row.accesskit_node().toggled() == Some(egui::accesskit::Toggled::True))
.expect("the current History step")
.rect();
assert!(harness.ctx.content_rect().contains_rect(current), "the current step must be reachable: {current:?}");
}
#[test]