From 178e2d192834403e674de1455d2189a1b60d87d3 Mon Sep 17 00:00:00 2001 From: Rebornim <250083243+Rebornim@users.noreply.github.com> Date: Sat, 28 Nov 2026 06:27:35 +0000 Subject: [PATCH 1/8] 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. --- crates/ui-egui/src/docking.rs | 11 ++- crates/ui-egui/src/windows.rs | 92 ++++++++++++++---------- crates/ui-egui/tests/it/history_panel.rs | 60 +++++++++++++--- crates/ui-egui/tests/it/rail.rs | 18 ++--- 4 files changed, 124 insertions(+), 57 deletions(-) diff --git a/crates/ui-egui/src/docking.rs b/crates/ui-egui/src/docking.rs index f6a7928f..d9e02747 100644 --- a/crates/ui-egui/src/docking.rs +++ b/crates/ui-egui/src/docking.rs @@ -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), diff --git a/crates/ui-egui/src/windows.rs b/crates/ui-egui/src/windows.rs index b8eff6e8..c19c89c5 100644 --- a/crates/ui-egui/src/windows.rs +++ b/crates/ui-egui/src/windows.rs @@ -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) { diff --git a/crates/ui-egui/tests/it/history_panel.rs b/crates/ui-egui/tests/it/history_panel.rs index 889b3df7..3c138c28 100644 --- a/crates/ui-egui/tests/it/history_panel.rs +++ b/crates/ui-egui/tests/it/history_panel.rs @@ -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()); +} diff --git a/crates/ui-egui/tests/it/rail.rs b/crates/ui-egui/tests/it/rail.rs index 7dbd97f2..260b1c93 100644 --- a/crates/ui-egui/tests/it/rail.rs +++ b/crates/ui-egui/tests/it/rail.rs @@ -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] From 7f9ee780a22502ebf7851d04cc69834091a84f76 Mon Sep 17 00:00:00 2001 From: Rebornim <250083243+Rebornim@users.noreply.github.com> Date: Sat, 28 Nov 2026 06:31:38 +0000 Subject: [PATCH 2/8] Keep the current History step in view, with the scrollbar always shown The History list opens at the newest step and scrolls the current step into view when the history changes (a new step, undo, redo or a jump); a tool, camera or selection change leaves a list the user scrolled where it is. Rows are laid out only while visible. The list's scrollbar is a solid 8 px bar in the theme's colours, shown even when the list fits. Part of #890. --- crates/ui-egui/src/log_panel.rs | 53 +++++++++ crates/ui-egui/src/state.rs | 4 + crates/ui-egui/src/windows.rs | 37 +++++-- crates/ui-egui/tests/it/history_panel.rs | 132 ++++++++++++++++++++++- 4 files changed, 216 insertions(+), 10 deletions(-) diff --git a/crates/ui-egui/src/log_panel.rs b/crates/ui-egui/src/log_panel.rs index b6df68af..d9376397 100644 --- a/crates/ui-egui/src/log_panel.rs +++ b/crates/ui-egui/src/log_panel.rs @@ -11,6 +11,59 @@ mod log_channel; pub use log_channel::LogChannel; +/// The width of the History and Log lists' scrollbars +const LIST_SCROLLBAR_WIDTH: f32 = 8.0; +const LIST_SCROLLBAR_RADIUS: u8 = 3; +/// The air between a list's scrollbar and the list's edge, and between the rows and the scrollbar +const LIST_SCROLLBAR_OUTER_MARGIN: f32 = 2.0; +const LIST_SCROLLBAR_INNER_MARGIN: f32 = 1.0; + +/// A newly focused row of a list scrolls in with a neighbour on each side: only shown rows are laid out, so Tab needs the next one there +pub(crate) fn reveal_focused_row(ui: &Ui, response: &egui::Response, row: egui::Rect) { + if response.gained_focus() { + // The shown width, so the list never moves sideways + let around = egui::Rect::from_x_y_ranges(ui.clip_rect().x_range(), row.y_range()).expand2(egui::vec2(0.0, row.height())); + ui.scroll_to_rect_animation(around, None, egui::style::ScrollAnimation::none()); + } +} + +/// Show `total_rows` rows of `row_height` in `area` under a solid, always shown, themed scrollbar +pub(crate) fn panel_rows( + ui: &mut Ui, + area: egui::ScrollArea, + row_height: f32, + total_rows: usize, + add_rows: impl FnOnce(&mut Ui, std::ops::Range) -> R, +) -> egui::scroll_area::ScrollAreaOutput { + let tokens = Tokens::get(ui.ctx()); + let row_visuals = ui.visuals().clone(); + ui.scope(|ui| { + ui.spacing_mut().item_spacing.y = 0.0; + ui.spacing_mut().scroll = egui::style::ScrollStyle { + bar_width: LIST_SCROLLBAR_WIDTH, + bar_outer_margin: LIST_SCROLLBAR_OUTER_MARGIN, + bar_inner_margin: LIST_SCROLLBAR_INNER_MARGIN, + ..egui::style::ScrollStyle::solid() + }; + + let visuals = ui.visuals_mut(); + visuals.extreme_bg_color = tokens.field; + // The thumb stands 3:1 or more off its track in every theme, brighter under the pointer + visuals.widgets.inactive.bg_fill = tokens.text_dim; + visuals.widgets.hovered.bg_fill = tokens.text; + visuals.widgets.active.bg_fill = tokens.text; + for widget in [&mut visuals.widgets.inactive, &mut visuals.widgets.hovered, &mut visuals.widgets.active] { + widget.corner_radius = egui::CornerRadius::same(LIST_SCROLLBAR_RADIUS); + } + + area.scroll_bar_visibility(egui::scroll_area::ScrollBarVisibility::AlwaysVisible).show_rows(ui, row_height, total_rows, |ui, rows| { + *ui.visuals_mut() = row_visuals; + add_rows(ui, rows) + }) + }) + .inner +} + /// The entries a tab lists, as indices into the session log fn listed(app: &TextureCraftApp, channel: LogChannel) -> Vec { app.session.log.iter().enumerate().filter(|(_, entry)| channel_of(entry) == channel).map(|(index, _)| index).collect() diff --git a/crates/ui-egui/src/state.rs b/crates/ui-egui/src/state.rs index 1ea83ab4..b40bf69c 100644 --- a/crates/ui-egui/src/state.rs +++ b/crates/ui-egui/src/state.rs @@ -744,6 +744,9 @@ pub struct UiState { /// Identity of the log that owns the selected rows. #[serde(skip)] pub log_id: u64, + /// The History panel's last shown container and steps (done, undone, newest name): a change scrolls to the current step + #[serde(skip)] + pub history_shown: Option<(egui::Id, usize, usize, Option)>, } pub(crate) const MAX_RECENT_PROJECTS: u16 = 100; @@ -912,6 +915,7 @@ impl Default for UiState { log_selection: Default::default(), log_anchor: None, log_id: 0, + history_shown: None, } } } diff --git a/crates/ui-egui/src/windows.rs b/crates/ui-egui/src/windows.rs index c19c89c5..dbf29eeb 100644 --- a/crates/ui-egui/src/windows.rs +++ b/crates/ui-egui/src/windows.rs @@ -260,15 +260,28 @@ 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))); + let total_rows = 1 + done.len() + undone.len(); + + // Only new steps or a new container (with its own scroll) bring the current one into view; a tool change keeps the user's scroll + let shown = Some((ui.make_persistent_id("history"), done.len(), undone.len(), done.last().cloned())); + let follow = app.ui.history_shown != shown; + app.ui.history_shown = shown; // A click on a step goes back (or forward) to it: steps to undo, or to redo when negative let mut jump = 0i64; - 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() { + + let area = egui::ScrollArea::vertical().id_salt("history").auto_shrink([false, false]); + crate::log_panel::panel_rows(ui, area, HISTORY_ROW_HEIGHT, total_rows, |ui, range| { + if follow { + let top = ui.max_rect().top() + (done.len() as f32 - range.start as f32) * HISTORY_ROW_HEIGHT; + let current = egui::Rect::from_x_y_ranges(ui.max_rect().x_range(), top..=top + HISTORY_ROW_HEIGHT); + ui.scroll_to_rect_animation(current, None, egui::style::ScrollAnimation::none()); + } + + // Only the shown rows are translated + for row in range { + let Some((name, color)) = history_row_name(&done, &undone, row, &tokens) else { continue }; + // 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() { @@ -289,10 +302,22 @@ pub(crate) fn history(app: &mut TextureCraftApp, ui: &mut Ui) { } } +/// The name and colour of History row `row`: the opened project, then the done steps, then the undone ones +fn history_row_name(done: &[String], undone: &[String], row: usize, tokens: &Tokens) -> Option<(String, egui::Color32)> { + let Some(step) = row.checked_sub(1) else { return Some((tr("Project opened").to_owned(), tokens.text_dim)) }; + if let Some(label) = done.get(step) { + return Some((tr_history(label), tokens.text)); + } + + let label = undone.get(step - done.len())?; + Some((trf("{action} (undone)", &[("action", &tr_history(label))]), tokens.text_dim)) +} + /// 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)); + crate::log_panel::reveal_focused_row(ui, &response, rect); if !ui.is_rect_visible(rect) { return response; } diff --git a/crates/ui-egui/tests/it/history_panel.rs b/crates/ui-egui/tests/it/history_panel.rs index 3c138c28..f9a82b9a 100644 --- a/crates/ui-egui/tests/it/history_panel.rs +++ b/crates/ui-egui/tests/it/history_panel.rs @@ -1,7 +1,7 @@ -//! A click on a step of the History panel goes back or forward to it. +//! The History panel: a click on a step goes back or forward to it, the current step is marked and kept in view use egui::accesskit::Toggled; -use egui::{Key, Modifiers}; +use egui::{Event, Key, Modifiers, vec2}; use egui_kittest::Harness; use egui_kittest::kittest::{NodeT, Queryable}; use serde_json::json; @@ -27,13 +27,16 @@ fn press(harness: &mut Harness<'_, TextureCraftApp>, key: Key) { harness.run_steps(3); } -/// The rows the panel shows as the current step: name and top edge +/// The History rows shown as the current step: name and top edge fn current_rows(harness: &Harness<'_, TextureCraftApp>) -> Vec<(String, f32)> { + let session = &harness.state().session; + let undone = session.redo_labels().into_iter().map(|label| format!("{label} (undone)")); + let names: Vec = session.history_labels().into_iter().chain(undone).chain(["Project opened".to_owned()]).collect(); 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") + .filter(|(name, _)| names.contains(name)) .collect() } @@ -233,3 +236,124 @@ fn only_the_current_step_is_marked_selected() { harness.run_steps(3); assert!(harness.state().session.redo_labels().is_empty()); } + +/// Enough steps that the History cannot show them all at once +const STEPS_PAST_THE_PANEL: usize = 100; + +/// A session `steps` renames long, so its History list is taller than the panel +fn long_session(steps: usize) -> Session { + let mut session = texturecraft_engine::sample_session(256, 64).unwrap(); + for step in 0..steps { + execute(&mut session, "layer.rename", &json!({"name": format!("Step {step}")})).unwrap(); + } + session +} + +/// Whether the current step's row named `name` is on screen +fn current_shown(harness: &Harness<'_, TextureCraftApp>, name: &str) -> bool { + let screen = harness.ctx.content_rect(); + current_rows(harness).iter().any(|(row, top)| row == name && screen.y_range().contains(*top)) +} + +/// Scroll the History list back to its first rows with the mouse wheel +fn scroll_to_top(harness: &mut Harness<'_, TextureCraftApp>) { + // Exactly one row is the current step; its top finds the row under the wheel + let (_, top) = current_rows(harness)[0]; + let over = harness.get_all_by_label("Rename layer").find(|node| node.rect().top() == top).unwrap().rect().center(); + harness.hover_at(over); + harness.event(Event::MouseWheel { + unit: egui::MouseWheelUnit::Point, + delta: vec2(0.0, 100_000.0), + phase: egui::TouchPhase::Move, + source: egui::MouseWheelSource::Wheel, + modifiers: Modifiers::NONE, + }); + harness.run_steps(12); +} + +/// A History list longer than the panel opens at its newest step, not at "Project opened" +#[test] +fn a_long_history_shows_the_newest_step() { + let harness = history_harness(long_session(STEPS_PAST_THE_PANEL)); + + assert!(current_shown(&harness, "Rename layer")); + assert!(harness.query_by_label("Project opened").is_none_or(|row| !harness.ctx.content_rect().y_range().contains(row.rect().top()))); +} + +/// A list the user scrolled up stays there when a tool changes but the history doesn't +#[test] +fn scrolling_up_is_not_pulled_back() { + let mut harness = history_harness(long_session(STEPS_PAST_THE_PANEL)); + scroll_to_top(&mut harness); + assert!(!current_shown(&harness, "Rename layer")); + + execute(&mut harness.state_mut().session, "tool.select", &json!({"tool": "path"})).unwrap(); + harness.run_steps(4); + + assert!(!current_shown(&harness, "Rename layer")); +} + +/// Once the history is full, a new step keeps the step count; its new name still brings it into view +#[test] +fn the_newest_step_shows_past_the_history_cap() { + let steps = texturecraft_engine::session::MAX_HISTORY + 60; + let mut harness = history_harness(long_session(steps)); + let capped = harness.state().session.history_labels().len(); + assert!(capped < steps, "the history is full"); + scroll_to_top(&mut harness); + assert!(!current_shown(&harness, "Rename layer")); + + execute(&mut harness.state_mut().session, "layer.add.paint", &json!({})).unwrap(); + harness.run_steps(4); + + let newest = harness.state().session.history_labels().last().cloned().unwrap(); + assert_eq!(harness.state().session.history_labels().len(), capped); + assert!(current_shown(&harness, &newest)); +} + +/// A History list that moves to another container (rail popup to floating window) still shows the current step +#[test] +fn an_undocked_history_shows_the_newest_step() { + let session = long_session(STEPS_PAST_THE_PANEL); + let mut harness = Harness::builder() + .with_size(egui::vec2(1600.0, 960.0)) + .with_context_setup(texturecraft_ui_egui::framework::install_headless) + .build_eframe(|context| TextureCraftApp::new(context, session)); + harness.run_steps(4); + let icon = harness.get_all_by_role(egui::accesskit::Role::Button).find(|button| { + let label = button.accesskit_node().label().unwrap_or_default(); + label == "History" || label.starts_with("History (") + }); + icon.expect("the History icon on the rail").click(); + harness.run_steps(4); + assert!(current_shown(&harness, "Rename layer")); + + harness.get_by_label("Undock").click(); + harness.run_steps(4); + + assert!(current_shown(&harness, "Rename layer")); +} + +/// Shift+Tab walks from the current step up to the first row, past the rows on screen when the panel opened +#[test] +fn the_keyboard_reaches_rows_scrolled_out_of_view() { + let mut harness = history_harness(long_session(STEPS_PAST_THE_PANEL)); + let (_, top) = current_rows(&harness)[0]; + harness.get_all_by_label("Rename layer").find(|node| node.rect().top() == top).unwrap().focus(); + harness.run_steps(2); + + let first_row_focused = |harness: &Harness<'_, TextureCraftApp>| { + let screen = harness.ctx.content_rect(); + harness.query_by_label("Project opened").is_some_and(|row| row.accesskit_node().is_focused() && screen.y_range().contains(row.rect().top())) + }; + // One press per step is enough to reach the first row + for _ in 0..harness.state().session.history_labels().len() + 1 { + if first_row_focused(&harness) { + break; + } + harness.key_press_modifiers(Modifiers::SHIFT, Key::Tab); + harness.run_steps(2); + } + + assert!(first_row_focused(&harness)); +} From 6754228e64c21d38bb0796ced21d1e9a624bc2e9 Mon Sep 17 00:00:00 2001 From: Rebornim <250083243+Rebornim@users.noreply.github.com> Date: Sat, 28 Nov 2026 06:33:39 +0000 Subject: [PATCH 3/8] Split the Log panel's width between its General and Assets tabs The two channel tabs fill the panel's width in equal halves, in small bold capitals: the open tab on the list's field colour with no line under it, the other on the row band with dim text. Each tab is a focusable control with the tab role and its selected state. The Log's lines keep a small inset from the panel's edges. Part of #890. --- crates/ui-egui/src/docking.rs | 6 +-- crates/ui-egui/src/log_panel.rs | 63 +++++++++++++++++++----- crates/ui-egui/tests/it/log_panel_680.rs | 10 ++++ 3 files changed, 63 insertions(+), 16 deletions(-) diff --git a/crates/ui-egui/src/docking.rs b/crates/ui-egui/src/docking.rs index d9e02747..66bab1aa 100644 --- a/crates/ui-egui/src/docking.rs +++ b/crates/ui-egui/src/docking.rs @@ -584,7 +584,7 @@ struct Panels<'a> { 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); +pub(crate) 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; @@ -616,10 +616,10 @@ pub(crate) fn panel_body(app: &mut TextureCraftApp, ui: &mut Ui, panel: Panel) { return; } - // Properties draws full-width bands and tabs and History full-width rows, so they draw their own side margins + // Properties draws full-width bands and tabs and History and Log full-width rows, so they draw their own side margins let margin = match panel { Panel::Properties => Margin::ZERO, - Panel::History => LIST_PANEL_MARGIN, + Panel::History | Panel::Log => LIST_PANEL_MARGIN, _ => PANEL_BODY_MARGIN, }; egui::Frame::new().inner_margin(margin).show(ui, |ui| match panel { diff --git a/crates/ui-egui/src/log_panel.rs b/crates/ui-egui/src/log_panel.rs index d9376397..86e8d489 100644 --- a/crates/ui-egui/src/log_panel.rs +++ b/crates/ui-egui/src/log_panel.rs @@ -1,6 +1,6 @@ //! The Log panel: the session's messages under a General and an Assets tab, one per channel -use egui::{Color32, RichText, Ui}; +use egui::{Align2, Color32, Rect, RichText, Sense, Stroke, StrokeKind, Ui, vec2}; use texturecraft_engine::log::{LogEntry, LogLevel}; use crate::TextureCraftApp; @@ -64,6 +64,46 @@ pub(crate) fn panel_rows( .inner } +/// The tab strip's and the list's inset from the panel's edges +const PANEL_INSET: f32 = 6.0; +const TAB_HEIGHT: f32 = 24.0; +const TAB_NAME_SIZE: f32 = 11.0; + +/// The General and Assets tabs, splitting the panel's width; the open one joins the list under it +fn channel_tabs(app: &mut TextureCraftApp, ui: &mut Ui, tokens: &Tokens) { + // The panel's own margin is above the tabs; the strip adds the rest of the inset + ui.add_space(PANEL_INSET - f32::from(crate::docking::LIST_PANEL_MARGIN.top)); + let (strip, _) = ui.allocate_exact_size(vec2(ui.available_width(), TAB_HEIGHT), Sense::hover()); + let strip = strip.shrink2(vec2(PANEL_INSET, 0.0)); + let tab_width = strip.width() / LogChannel::ALL.len() as f32; + let outline = Stroke::new(1.0, tokens.field_border); + for (slot, channel) in LogChannel::ALL.into_iter().enumerate() { + let rect = Rect::from_min_size(strip.min + vec2(slot as f32 * tab_width, 0.0), vec2(tab_width, TAB_HEIGHT)); + let response = ui.interact(rect, ui.make_persistent_id(("log-tab", channel.name())), Sense::click()); + let open = app.ui.log_channel == channel; + let name = tr(channel.name()); + response.widget_info(|| egui::WidgetInfo::selected(egui::Role::Tab, true, open, name)); + + let painter = ui.painter(); + painter.rect(rect, 0.0, if open { tokens.field } else { tokens.row }, outline, StrokeKind::Inside); + if open { + let joint = Rect::from_min_max(rect.left_bottom() + vec2(1.0, -1.0), rect.right_bottom() + vec2(-1.0, 0.0)); + painter.rect_filled(joint, 0.0, tokens.field); + } + let color = if open || response.hovered() { tokens.text } else { tokens.text_dim }; + painter.text(rect.center(), Align2::CENTER_CENTER, name, crate::theme::semibold(TAB_NAME_SIZE), color); + if response.has_focus() { + crate::property_sheet::paint_focus_outline(painter, rect, tokens.text_strong); + } + + if response.clicked() { + app.ui.log_channel = channel; + app.ui.log_selection.clear(); + app.ui.log_anchor = None; + } + } +} + /// The entries a tab lists, as indices into the session log fn listed(app: &TextureCraftApp, channel: LogChannel) -> Vec { app.session.log.iter().enumerate().filter(|(_, entry)| channel_of(entry) == channel).map(|(index, _)| index).collect() @@ -183,16 +223,8 @@ pub(crate) fn takes_copy(app: &TextureCraftApp, ctx: &egui::Context) -> bool { /// The Log panel body (a dock tab or rail popup) pub(crate) fn body(app: &mut TextureCraftApp, ui: &mut Ui) { - ui.horizontal(|ui| { - for channel in LogChannel::ALL { - if ui.selectable_label(app.ui.log_channel == channel, tr(channel.name())).clicked() { - app.ui.log_channel = channel; - app.ui.log_selection.clear(); - app.ui.log_anchor = None; - } - } - }); - ui.separator(); + let tk = Tokens::get(ui.ctx()); + channel_tabs(app, ui, &tk); // A new session has a new log: indices chosen in the old one point at other lines if app.ui.log_id != app.session.log_id { @@ -201,11 +233,16 @@ pub(crate) fn body(app: &mut TextureCraftApp, ui: &mut Ui) { app.ui.log_anchor = None; } + let inset = PANEL_INSET as i8; + egui::Frame::new().inner_margin(egui::Margin::symmetric(inset, 0)).show(ui, |ui| entries(app, ui, &tk)); +} + +/// The shown tab's lines, under the Assets tab's filter button +fn entries(app: &mut TextureCraftApp, ui: &mut Ui, tk: &Tokens) { if shown_assets_filter(app) { crate::unavailable::greyed(ui, |ui| ui.add(egui::Button::new(egui_phosphor::regular::WARNING).selected(false))); } - let tk = Tokens::get(ui.ctx()); let shown = app.ui.log_channel; let rows = listed(app, shown); @@ -225,7 +262,7 @@ pub(crate) fn body(app: &mut TextureCraftApp, ui: &mut Ui) { egui::ScrollArea::vertical().id_salt(("log", shown.name())).auto_shrink([false, false]).stick_to_bottom(true).show(ui, |ui| { for index in rows.iter().copied() { let Some(entry) = app.session.log.get(index) else { continue }; - let text = RichText::new(entry.line()).color(level_color(&tk, entry.level)); + let text = RichText::new(entry.line()).color(level_color(tk, entry.level)); let band = ui.painter().add(egui::Shape::Noop); let response = ui.add(egui::Label::new(text).selectable(false).sense(egui::Sense::click())); if app.ui.log_selection.contains(&index) { diff --git a/crates/ui-egui/tests/it/log_panel_680.rs b/crates/ui-egui/tests/it/log_panel_680.rs index eba3e084..62fbe967 100644 --- a/crates/ui-egui/tests/it/log_panel_680.rs +++ b/crates/ui-egui/tests/it/log_panel_680.rs @@ -145,6 +145,16 @@ fn assets_has_a_greyed_filter_button_with_the_hint() { assert!(h.query_by_label(texturecraft_ui_egui::unavailable::NOT_AVAILABLE).is_some()); } +/// The two tabs share the panel's width equally, side by side +#[test] +fn the_log_tabs_split_the_panel_width() { + let h = app(); + let (general, assets) = (h.get_by_label("GENERAL").rect(), h.get_by_label("ASSETS").rect()); + + assert!((general.width() - assets.width()).abs() < 1.0, "{general:?} {assets:?}"); + assert!((general.right() - assets.left()).abs() < 1.0, "{general:?} {assets:?}"); +} + #[test] fn renderer_settings_stays_open_when_opened_in_rendering_mode() { let mut h = app(); From 5e132ba903c9db99957a6ee5b294d5fc6c39f718 Mon Sep 17 00:00:00 2001 From: Rebornim <250083243+Rebornim@users.noreply.github.com> Date: Sat, 28 Nov 2026 06:35:46 +0000 Subject: [PATCH 4/8] Show the Log as a framed list of one-line entries The Log's lines sit in a sunken box joined to the open tab: one row per line, never wrapped, with vertical and horizontal scrollbars and the whole row banded while selected. The widest line of each tab is measured once per new line, so a long log doesn't lay out every line each frame; rows are laid out only while visible. The Assets tab's greyed warnings filter sits in a strip above the list and has the accessible name "Warnings". Part of #890. --- crates/ui-egui/src/log_panel.rs | 107 +++++++++++++---- .../ui-egui/src/log_panel/log_width_cache.rs | 88 ++++++++++++++ crates/ui-egui/src/state.rs | 4 + crates/ui-egui/tests/it/log_panel_680.rs | 109 ++++++++++++++++-- crates/ui-egui/tests/list_panels.rs | 5 +- 5 files changed, 276 insertions(+), 37 deletions(-) create mode 100644 crates/ui-egui/src/log_panel/log_width_cache.rs diff --git a/crates/ui-egui/src/log_panel.rs b/crates/ui-egui/src/log_panel.rs index 86e8d489..06134c0e 100644 --- a/crates/ui-egui/src/log_panel.rs +++ b/crates/ui-egui/src/log_panel.rs @@ -1,6 +1,8 @@ //! The Log panel: the session's messages under a General and an Assets tab, one per channel -use egui::{Align2, Color32, Rect, RichText, Sense, Stroke, StrokeKind, Ui, vec2}; +use std::hash::{Hash, Hasher}; + +use egui::{Align2, Color32, Rect, Sense, Stroke, StrokeKind, Ui, vec2}; use texturecraft_engine::log::{LogEntry, LogLevel}; use crate::TextureCraftApp; @@ -8,8 +10,10 @@ use crate::i18n::tr; use crate::theme::Tokens; mod log_channel; +mod log_width_cache; pub use log_channel::LogChannel; +pub use log_width_cache::LogWidthCache; /// The width of the History and Log lists' scrollbars const LIST_SCROLLBAR_WIDTH: f32 = 8.0; @@ -68,15 +72,22 @@ pub(crate) fn panel_rows( const PANEL_INSET: f32 = 6.0; const TAB_HEIGHT: f32 = 24.0; const TAB_NAME_SIZE: f32 = 11.0; +/// The Assets tab's strip with its filter button, above the list +const FILTER_STRIP_HEIGHT: f32 = 30.0; +const LINE_HEIGHT: f32 = 19.0; +const LINE_TEXT_SIZE: f32 = 12.0; +/// Where a line's text starts in the list, and the air after the widest line +const LINE_TEXT_LEFT: f32 = 6.0; -/// The General and Assets tabs, splitting the panel's width; the open one joins the list under it -fn channel_tabs(app: &mut TextureCraftApp, ui: &mut Ui, tokens: &Tokens) { +/// The General and Assets tabs, splitting the panel's width; returns the open tab's rectangle +fn channel_tabs(app: &mut TextureCraftApp, ui: &mut Ui, tokens: &Tokens) -> Rect { // The panel's own margin is above the tabs; the strip adds the rest of the inset ui.add_space(PANEL_INSET - f32::from(crate::docking::LIST_PANEL_MARGIN.top)); let (strip, _) = ui.allocate_exact_size(vec2(ui.available_width(), TAB_HEIGHT), Sense::hover()); let strip = strip.shrink2(vec2(PANEL_INSET, 0.0)); let tab_width = strip.width() / LogChannel::ALL.len() as f32; let outline = Stroke::new(1.0, tokens.field_border); + let mut open_tab = strip; for (slot, channel) in LogChannel::ALL.into_iter().enumerate() { let rect = Rect::from_min_size(strip.min + vec2(slot as f32 * tab_width, 0.0), vec2(tab_width, TAB_HEIGHT)); let response = ui.interact(rect, ui.make_persistent_id(("log-tab", channel.name())), Sense::click()); @@ -87,8 +98,7 @@ fn channel_tabs(app: &mut TextureCraftApp, ui: &mut Ui, tokens: &Tokens) { let painter = ui.painter(); painter.rect(rect, 0.0, if open { tokens.field } else { tokens.row }, outline, StrokeKind::Inside); if open { - let joint = Rect::from_min_max(rect.left_bottom() + vec2(1.0, -1.0), rect.right_bottom() + vec2(-1.0, 0.0)); - painter.rect_filled(joint, 0.0, tokens.field); + open_tab = rect; } let color = if open || response.hovered() { tokens.text } else { tokens.text_dim }; painter.text(rect.center(), Align2::CENTER_CENTER, name, crate::theme::semibold(TAB_NAME_SIZE), color); @@ -102,6 +112,46 @@ fn channel_tabs(app: &mut TextureCraftApp, ui: &mut Ui, tokens: &Tokens) { app.ui.log_anchor = None; } } + open_tab +} + +/// A line as its row shows it: a message's line breaks become spaces, so it stays on its one row +fn row_text(entry: &LogEntry) -> String { + entry.line().replace(['\r', '\n'], " ") +} + +/// One Log line across the list: one row, never wrapped, banded while selected +fn log_line(ui: &mut Ui, tokens: &Tokens, index: usize, entry: &LogEntry, selected: bool) -> egui::Response { + let (rect, _) = ui.allocate_exact_size(vec2(ui.available_width(), LINE_HEIGHT), Sense::hover()); + + // A row is as wide as the widest line: only its shown part takes clicks, so its middle is on screen + let response = ui.interact(rect.intersect(ui.clip_rect()), ui.make_persistent_id(("log-line", index)), Sense::click()); + let line = entry.line(); + response.widget_info(|| egui::WidgetInfo::selected(egui::Role::ListItem, true, selected, &line)); + reveal_focused_row(ui, &response, rect); + if !ui.is_rect_visible(rect) { + return response; + } + + let painter = ui.painter(); + if selected { + painter.rect_filled(rect, 0.0, tokens.accent_dim); + } + let text_at = egui::pos2(rect.left() + LINE_TEXT_LEFT, rect.center().y); + painter.text(text_at, Align2::LEFT_CENTER, row_text(entry), egui::FontId::proportional(LINE_TEXT_SIZE), level_color(tokens, entry.level)); + if response.has_focus() { + crate::property_sheet::paint_focus_outline(painter, rect, tokens.text_strong); + } + response +} + +/// Changes when the installed fonts do: fallback fonts arrive while the app runs, and widths change with them +fn font_key(ui: &Ui) -> u64 { + ui.fonts(|fonts| { + let mut hasher = std::hash::DefaultHasher::new(); + fonts.definitions().families.get(&egui::FontFamily::Proportional).hash(&mut hasher); + hasher.finish() + }) } /// The entries a tab lists, as indices into the session log @@ -115,11 +165,11 @@ pub fn channel_of(entry: &LogEntry) -> LogChannel { } /// The line colour of a level: light grey for info, yellow-orange for warnings, red for errors -fn level_color(tk: &Tokens, level: LogLevel) -> Color32 { +fn level_color(tokens: &Tokens, level: LogLevel) -> Color32 { match level { - LogLevel::Info => tk.text, - LogLevel::Warning => tk.warning, - LogLevel::Error => tk.danger, + LogLevel::Info => tokens.text, + LogLevel::Warning => tokens.warning, + LogLevel::Error => tokens.danger, } } @@ -223,8 +273,8 @@ pub(crate) fn takes_copy(app: &TextureCraftApp, ctx: &egui::Context) -> bool { /// The Log panel body (a dock tab or rail popup) pub(crate) fn body(app: &mut TextureCraftApp, ui: &mut Ui) { - let tk = Tokens::get(ui.ctx()); - channel_tabs(app, ui, &tk); + let tokens = Tokens::get(ui.ctx()); + let open_tab = channel_tabs(app, ui, &tokens); // A new session has a new log: indices chosen in the old one point at other lines if app.ui.log_id != app.session.log_id { @@ -233,14 +283,25 @@ pub(crate) fn body(app: &mut TextureCraftApp, ui: &mut Ui) { app.ui.log_anchor = None; } + // The list's box overlaps the tabs' bottom line, which is then cleared under the open tab; the panel's own margin is below it let inset = PANEL_INSET as i8; - egui::Frame::new().inner_margin(egui::Margin::symmetric(inset, 0)).show(ui, |ui| entries(app, ui, &tk)); + let outer = egui::Margin { left: inset, right: inset, top: -1, bottom: inset - crate::docking::LIST_PANEL_MARGIN.bottom }; + // The 1 px inner margin keeps the rows and scrollbars off the frame's line + let frame = egui::Frame::new().fill(tokens.field).stroke(Stroke::new(1.0, tokens.field_border)).inner_margin(1).outer_margin(outer); + frame.show(ui, |ui| entries(app, ui, &tokens)); + let joint = Rect::from_min_max(open_tab.left_bottom() + vec2(1.0, -1.0), open_tab.right_bottom() + vec2(-1.0, 0.0)); + ui.painter().rect_filled(joint, 0.0, tokens.field); } /// The shown tab's lines, under the Assets tab's filter button -fn entries(app: &mut TextureCraftApp, ui: &mut Ui, tk: &Tokens) { +fn entries(app: &mut TextureCraftApp, ui: &mut Ui, tokens: &Tokens) { if shown_assets_filter(app) { - crate::unavailable::greyed(ui, |ui| ui.add(egui::Button::new(egui_phosphor::regular::WARNING).selected(false))); + let (strip, _) = ui.allocate_exact_size(vec2(ui.available_width(), FILTER_STRIP_HEIGHT), Sense::hover()); + let layout = egui::Layout::left_to_right(egui::Align::Center); + let mut strip_ui = ui.new_child(egui::UiBuilder::new().max_rect(strip.shrink2(vec2(PANEL_INSET, 0.0))).layout(layout)); + let filter = crate::unavailable::greyed(&mut strip_ui, |ui| ui.add(egui::Button::new(egui_phosphor::regular::WARNING).selected(false))); + filter.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Button, false, tr("Warnings"))); + ui.painter().hline(strip.x_range(), strip.bottom(), Stroke::new(1.0, tokens.field_border)); } let shown = app.ui.log_channel; @@ -259,16 +320,16 @@ fn entries(app: &mut TextureCraftApp, ui: &mut Ui, tk: &Tokens) { } } - egui::ScrollArea::vertical().id_salt(("log", shown.name())).auto_shrink([false, false]).stick_to_bottom(true).show(ui, |ui| { - for index in rows.iter().copied() { + // Lines never wrap: the list is as wide as its widest line and scrolls sideways + let font = egui::FontId::proportional(LINE_TEXT_SIZE); + let measure = |entry: &LogEntry| ui.painter().layout_no_wrap(row_text(entry), font.clone(), tokens.text).size().x; + let widest = app.ui.log_widths.widest(&app.session.log, app.session.log_id, ui.ctx().pixels_per_point(), font_key(ui), shown, measure); + let scroll_area = egui::ScrollArea::both().id_salt(("log", shown.name())).auto_shrink([false, false]).stick_to_bottom(true); + panel_rows(ui, scroll_area, LINE_HEIGHT, rows.len(), |ui, range| { + ui.set_min_width(widest + 2.0 * LINE_TEXT_LEFT); + for index in rows[range].iter().copied() { let Some(entry) = app.session.log.get(index) else { continue }; - let text = RichText::new(entry.line()).color(level_color(tk, entry.level)); - let band = ui.painter().add(egui::Shape::Noop); - let response = ui.add(egui::Label::new(text).selectable(false).sense(egui::Sense::click())); - if app.ui.log_selection.contains(&index) { - let rect = response.rect.expand2(egui::vec2(ui.spacing().item_spacing.x, 0.0)).intersect(ui.max_rect()); - ui.painter().set(band, egui::Shape::rect_filled(rect, 0.0, tk.accent_dim)); - } + let response = log_line(ui, tokens, index, entry, app.ui.log_selection.contains(&index)); if response.clicked() || response.secondary_clicked() && !app.ui.log_selection.contains(&index) { let modifiers = ui.input(|input| input.modifiers); select(app, &rows, index, modifiers); diff --git a/crates/ui-egui/src/log_panel/log_width_cache.rs b/crates/ui-egui/src/log_panel/log_width_cache.rs new file mode 100644 index 00000000..808dd651 --- /dev/null +++ b/crates/ui-egui/src/log_panel/log_width_cache.rs @@ -0,0 +1,88 @@ +use texturecraft_engine::log::{LogEntry, SessionLog}; + +use super::{LogChannel, channel_of}; + +/// The widest line of each Log tab, measuring each line once, when it is new +#[derive(Clone, Debug, Default, PartialEq)] +pub struct LogWidthCache { + log_id: u64, + pixels_per_point: f32, + /// Identifies the fonts the lines were measured with + font_key: u64, + /// The newest measured line's occurrence id (ids are never reused within a log) + last_occurrence: u64, + /// How many lines of both tabs were measured: fewer lines in the log means some were cleared + measured: usize, + widest: [f32; LogChannel::ALL.len()], +} + +impl LogWidthCache { + /// The widest line of `channel`: new lines are measured, a cleared line or a new log, scale or font set measures all again + pub fn widest( + &mut self, + log: &SessionLog, + log_id: u64, + pixels_per_point: f32, + font_key: u64, + channel: LogChannel, + measure: impl Fn(&LogEntry) -> f32, + ) -> f32 { + let added = log.entries_after(self.last_occurrence).count(); + let same_measure = self.pixels_per_point == pixels_per_point && self.font_key == font_key; + if self.log_id != log_id || !same_measure || self.measured + added != log.len() { + *self = LogWidthCache { log_id, pixels_per_point, font_key, ..LogWidthCache::default() }; + } + + for (occurrence, entry) in log.entries_after(self.last_occurrence) { + let widest = &mut self.widest[channel_of(entry) as usize]; + *widest = widest.max(measure(entry)); + self.last_occurrence = occurrence; + self.measured += 1; + } + self.widest[channel as usize] + } +} + +#[cfg(test)] +mod tests { + use super::*; + + fn width(entry: &LogEntry) -> f32 { + entry.line().len() as f32 + } + + #[test] + fn clearing_the_widest_line_narrows_the_tab() { + let mut log = SessionLog::new(); + log.info("Project", "short"); + log.info("Project", "a much longer line than the other one"); + let mut cache = LogWidthCache::default(); + let wide = cache.widest(&log, 1, 1.0, 1, LogChannel::General, width); + + log.retain(|entry| !entry.line().contains("longer")); + assert!(cache.widest(&log, 1, 1.0, 1, LogChannel::General, width) < wide); + } + + #[test] + fn a_new_log_is_measured_again() { + let mut log = SessionLog::new(); + log.info("Project", "a much longer line than the other one"); + let mut cache = LogWidthCache::default(); + let wide = cache.widest(&log, 1, 1.0, 1, LogChannel::General, width); + + let mut next = SessionLog::new(); + next.info("Project", "short"); + assert!(cache.widest(&next, 2, 1.0, 1, LogChannel::General, width) < wide); + } + + #[test] + fn new_fonts_measure_the_lines_again() { + let mut log = SessionLog::new(); + log.info("Project", "a line"); + let mut cache = LogWidthCache::default(); + let narrow = cache.widest(&log, 1, 1.0, 1, LogChannel::General, width); + + let wider = |entry: &LogEntry| 2.0 * width(entry); + assert!(cache.widest(&log, 1, 1.0, 2, LogChannel::General, wider) > narrow); + } +} diff --git a/crates/ui-egui/src/state.rs b/crates/ui-egui/src/state.rs index b40bf69c..d3a053d2 100644 --- a/crates/ui-egui/src/state.rs +++ b/crates/ui-egui/src/state.rs @@ -747,6 +747,9 @@ pub struct UiState { /// The History panel's last shown container and steps (done, undone, newest name): a change scrolls to the current step #[serde(skip)] pub history_shown: Option<(egui::Id, usize, usize, Option)>, + /// The widest line of each Log tab, measured once per line + #[serde(skip)] + pub log_widths: crate::log_panel::LogWidthCache, } pub(crate) const MAX_RECENT_PROJECTS: u16 = 100; @@ -916,6 +919,7 @@ impl Default for UiState { log_anchor: None, log_id: 0, history_shown: None, + log_widths: Default::default(), } } } diff --git a/crates/ui-egui/tests/it/log_panel_680.rs b/crates/ui-egui/tests/it/log_panel_680.rs index 62fbe967..3fa9764d 100644 --- a/crates/ui-egui/tests/it/log_panel_680.rs +++ b/crates/ui-egui/tests/it/log_panel_680.rs @@ -7,6 +7,9 @@ use egui_kittest::kittest::{NodeT, Queryable}; use texturecraft_ui_egui::TextureCraftApp; use texturecraft_ui_egui::docking::Panel; +/// Enough lines that the Log cannot show them all at once +const LINES_PAST_THE_PANEL: usize = 100; + fn app() -> Harness<'static, TextureCraftApp> { let session = texturecraft_engine::sample_session(256, 64).unwrap(); let mut h = Harness::builder() @@ -131,30 +134,85 @@ fn mesh_reimport_clears_log_selection_within_the_same_project() { #[test] fn assets_has_a_greyed_filter_button_with_the_hint() { - let mut h = app(); - assert!(h.query_by_label(egui_phosphor::regular::WARNING).is_none(), "GENERAL has no filter button"); - h.get_by_label("ASSETS").click(); - h.run_steps(3); - let button = h.get_by_label(egui_phosphor::regular::WARNING); + let mut harness = app(); + assert!(harness.query_by_label("Warnings").is_none(), "GENERAL has no filter button"); + + harness.get_by_label("ASSETS").click(); + harness.run_steps(3); + + let button = harness.get_by_label("Warnings"); assert!(button.accesskit_node().is_disabled()); + let at = button.rect().center(); - h.hover_at(egui::pos2(1.0, 1.0)); - h.run_steps(2); - h.hover_at(at); - h.run_steps(30); - assert!(h.query_by_label(texturecraft_ui_egui::unavailable::NOT_AVAILABLE).is_some()); + harness.hover_at(egui::pos2(1.0, 1.0)); + harness.run_steps(2); + harness.hover_at(at); + harness.run_steps(30); + assert!(harness.query_by_label(texturecraft_ui_egui::unavailable::NOT_AVAILABLE).is_some()); } /// The two tabs share the panel's width equally, side by side #[test] fn the_log_tabs_split_the_panel_width() { - let h = app(); - let (general, assets) = (h.get_by_label("GENERAL").rect(), h.get_by_label("ASSETS").rect()); + let harness = app(); + let (general, assets) = (harness.get_by_label("GENERAL").rect(), harness.get_by_label("ASSETS").rect()); assert!((general.width() - assets.width()).abs() < 1.0, "{general:?} {assets:?}"); assert!((general.right() - assets.left()).abs() < 1.0, "{general:?} {assets:?}"); } +/// The list's scrollbar keeps a gap to the list's frame, which ends where the tabs end +#[test] +fn the_log_scroll_bar_stands_clear_of_the_list_frame() { + let harness = app(); + let (general, assets) = (harness.get_by_label("GENERAL").rect(), harness.get_by_label("ASSETS").rect()); + let bars = + harness.get_all_by_role(egui::accesskit::Role::ScrollBar).filter(|bar| bar.rect().left() > general.left() && bar.rect().right() <= assets.right()); + let bar = bars.max_by(|a, b| a.rect().height().total_cmp(&b.rect().height())).expect("the list's scroll bar").rect(); + + // The frame ends where the tab strip ends; its 1 point line and 1 point padding come before its inside + let frame_inside = assets.right() - 2.0; + assert!(bar.right() < frame_inside, "{bar:?} {assets:?}"); +} + +/// How many rows each painted text containing `part` has +fn painted_rows(harness: &Harness<'_, TextureCraftApp>, part: &str) -> Vec { + harness + .output() + .shapes + .iter() + .filter_map(|clipped| match &clipped.shape { + egui::Shape::Text(text) if text.galley.text().contains(part) => Some(text.galley.rows.len()), + _ => None, + }) + .collect() +} + +/// Log `message` and show it painted: the status bar repeats the newest message, so another follows it +fn log_behind_a_newer_line(harness: &mut Harness<'_, TextureCraftApp>, message: &str) { + harness.state_mut().session.log.info("Exporter", message.to_owned()); + harness.state_mut().session.log.info("Exporter", "newest"); + harness.run_steps(3); +} + +/// A line longer than the panel stays on one row +#[test] +fn a_long_line_stays_one_row() { + let mut harness = app(); + log_behind_a_newer_line(&mut harness, &"long ".repeat(400)); + + assert_eq!(painted_rows(&harness, "long long"), vec![1]); +} + +/// A message with a line break is painted on its row, not over the lines around it +#[test] +fn a_message_with_a_line_break_is_painted_on_one_row() { + let mut harness = app(); + log_behind_a_newer_line(&mut harness, "broken\nmessage"); + + assert_eq!(painted_rows(&harness, "broken"), vec![1]); +} + #[test] fn renderer_settings_stays_open_when_opened_in_rendering_mode() { let mut h = app(); @@ -219,3 +277,30 @@ fn the_assets_menu_clears_all_or_only_the_selected_lines() { assert!(h.state().session.log.iter().all(|entry| !entry.is_asset())); assert_eq!(h.state().session.log.len(), 3, "the GENERAL lines stay"); } + +/// Shift+Tab walks from the newest line to the first one, past the lines on screen when the panel opened +#[test] +fn the_keyboard_reaches_lines_scrolled_out_of_view() { + let mut harness = app(); + for number in 0..LINES_PAST_THE_PANEL { + harness.state_mut().session.log.info("Exporter", format!("line {number}")); + } + harness.run_steps(4); + line(&harness, &format!("[Exporter] line {}", LINES_PAST_THE_PANEL - 1)).focus(); + harness.run_steps(2); + + let first_line_focused = |harness: &Harness<'_, TextureCraftApp>| { + let screen = harness.ctx.content_rect(); + harness.query_all_by_label("[Exporter] first").any(|row| row.accesskit_node().is_focused() && screen.y_range().contains(row.rect().top())) + }; + // One press per line is enough to reach the first one + for _ in 0..harness.state().session.log.len() { + if first_line_focused(&harness) { + break; + } + harness.key_press_modifiers(Modifiers::SHIFT, egui::Key::Tab); + harness.run_steps(2); + } + + assert!(first_line_focused(&harness)); +} diff --git a/crates/ui-egui/tests/list_panels.rs b/crates/ui-egui/tests/list_panels.rs index 872215fe..27700d8b 100644 --- a/crates/ui-egui/tests/list_panels.rs +++ b/crates/ui-egui/tests/list_panels.rs @@ -36,9 +36,10 @@ fn dock_in_left_column(harness: &mut Harness<'_, TextureCraftApp>, panel: &str) harness.state_mut().ui.dock = Dock::from_value(serde_json::from_str(&swapped).unwrap()); } -/// The height of the list's scroll bar, which runs the visible height of the list +/// The height of the list's vertical scroll bar (the taller one, as the Log also scrolls sideways), which runs the visible height of the list fn list_height(harness: &Harness<'_, TextureCraftApp>) -> f32 { - let bar = harness.get_all_by_role(Role::ScrollBar).find(|bar| bar.rect().max.x < LEFT_COLUMN_MAX_X).expect("a scroll bar in the left column"); + let bars = harness.get_all_by_role(Role::ScrollBar).filter(|bar| bar.rect().max.x < LEFT_COLUMN_MAX_X); + let bar = bars.max_by(|a, b| a.rect().height().total_cmp(&b.rect().height())).expect("a scroll bar in the left column"); bar.rect().height() } From 0b0a5337f6bbf01ccfaabe79a8c6aedcd8769c0b Mon Sep 17 00:00:00 2001 From: Rebornim <250083243+Rebornim@users.noreply.github.com> Date: Sun, 29 Nov 2026 09:49:35 +0000 Subject: [PATCH 5/8] Bring the current History step into view when a full history repeats a name --- crates/engine/src/painting.rs | 7 ++---- crates/engine/src/session.rs | 27 +++++++++++++++++++++--- crates/engine/tests/session.rs | 22 +++++++++++++++++++ crates/ui-egui/src/state.rs | 4 ++-- crates/ui-egui/src/windows.rs | 2 +- crates/ui-egui/tests/it/history_panel.rs | 17 ++++++++++++++- 6 files changed, 67 insertions(+), 12 deletions(-) diff --git a/crates/engine/src/painting.rs b/crates/engine/src/painting.rs index f2395365..6d26d432 100644 --- a/crates/engine/src/painting.rs +++ b/crates/engine/src/painting.rs @@ -555,7 +555,7 @@ impl Session { self.stroke.is_some() } - /// Commit the active stroke (one undo step). + /// Commit the active stroke as one undo step pub fn end_stroke(&mut self) -> Result<()> { let Some(mut stroke) = self.stroke.take() else { return Ok(()) }; let size = (stroke.canvas.alpha.width(), stroke.canvas.alpha.height()); @@ -586,10 +586,7 @@ impl Session { return Ok(()); } } - self.undo.push((stroke.label.clone(), stroke.before)); - if self.undo.len() > crate::session::MAX_HISTORY { - self.undo.remove(0); - } + self.add_step(stroke.label.clone(), stroke.before); self.redo.clear(); self.mark_modified(); diff --git a/crates/engine/src/session.rs b/crates/engine/src/session.rs index faf91c9a..9388a3ec 100644 --- a/crates/engine/src/session.rs +++ b/crates/engine/src/session.rs @@ -440,6 +440,8 @@ pub struct Session { pub caches: Vec, pub(crate) undo: Vec<(String, Document)>, pub(crate) redo: Vec<(String, Document)>, + /// New undo steps so far: it moves even when a full history keeps its length + pub(crate) steps_added: u64, /// Set by [`crate::execute`] from a command's `merge` param: its edits continue the previous /// undo step with the same label (a slider drag is one step however many values it applies). pub(crate) merge_edits: bool, @@ -548,6 +550,7 @@ impl Session { caches, undo: Vec::new(), redo: Vec::new(), + steps_added: 0, merge_edits: false, tool: ToolState::default(), active_set: 0, @@ -757,7 +760,7 @@ impl Session { if !self.painting_paths && let Some(draft) = self.path_draft.take() { - self.undo.push((crate::path_tool::NEW_PATH_LABEL.to_string(), draft.base)); + self.add_step(crate::path_tool::NEW_PATH_LABEL.to_string(), draft.base); } // Point changes of an edited path undo only until another step lands @@ -767,11 +770,22 @@ impl Session { self.mark_modified(); if !(merge && self.undo.last().is_some_and(|(l, _)| l == label)) { - self.undo.push((label.to_string(), before)); + self.add_step(label.to_string(), before); } + + self.redo.clear(); + } + + /// Append an undo step, dropping the oldest ones from a full history + pub(crate) fn add_step(&mut self, label: String, before: Document) { + self.undo.push((label, before)); let over = self.undo.len().saturating_sub(MAX_HISTORY); self.undo.drain(..over); - self.redo.clear(); + + // A repaint of paths runs strokes on a temporary history, none of which is a step + if !self.painting_paths { + self.steps_added = self.steps_added.wrapping_add(1); + } } /// A change from `other` to the current document that is not an undo step (a path preview) @@ -975,6 +989,13 @@ impl Session { pub fn redo_labels(&self) -> Vec { self.redo.iter().rev().map(|(l, _)| l.clone()).collect() } + + /// Changes with every new undo step, not when a merged edit continues one + pub fn steps_added(&self) -> u64 { + self.steps_added + } + + /// The done steps, the oldest first pub fn history_labels(&self) -> Vec { self.undo.iter().map(|(l, _)| l.clone()).collect() } diff --git a/crates/engine/tests/session.rs b/crates/engine/tests/session.rs index 0fc0b848..d95c4358 100644 --- a/crates/engine/tests/session.rs +++ b/crates/engine/tests/session.rs @@ -1155,3 +1155,25 @@ fn interleaved_sessions_render_depth_from_their_own_mesh() { assert!((hidden[0] - hidden[1]).abs() < 0.05, "the rear surface is occluded: {hidden:?}"); assert!(visible[0] > visible[1] + 0.5, "the rear surface is exposed: {visible:?}"); } + +/// A full history keeps its length and may repeat its newest name, so views follow the count of steps added +#[test] +fn a_full_history_still_counts_each_new_step() { + let mut s = session(); + for _ in 0..texturecraft_engine::session::MAX_HISTORY { + execute(&mut s, "tool.stroke", &json!({"points": [[180, 200], [220, 200]]})).unwrap(); + } + let (labels, added) = (s.history_labels(), s.steps_added()); + + execute(&mut s, "tool.stroke", &json!({"points": [[180, 200], [220, 200]]})).unwrap(); + + assert_eq!(s.history_labels(), labels); + assert!(s.steps_added() > added); + + // A path preview paints through strokes of its own, none of which is a step + let added = s.steps_added(); + execute(&mut s, "tool.path", &json!({"uvPoints": [[0.2, 0.5], [0.8, 0.5]]})).unwrap(); + + assert_eq!(s.history_labels(), labels); + assert_eq!(s.steps_added(), added); +} diff --git a/crates/ui-egui/src/state.rs b/crates/ui-egui/src/state.rs index d3a053d2..d52bca3f 100644 --- a/crates/ui-egui/src/state.rs +++ b/crates/ui-egui/src/state.rs @@ -744,9 +744,9 @@ pub struct UiState { /// Identity of the log that owns the selected rows. #[serde(skip)] pub log_id: u64, - /// The History panel's last shown container and steps (done, undone, newest name): a change scrolls to the current step + /// The History panel's last shown container and steps (added so far, done, undone): a change scrolls to the current step #[serde(skip)] - pub history_shown: Option<(egui::Id, usize, usize, Option)>, + pub history_shown: Option<(egui::Id, u64, usize, usize)>, /// The widest line of each Log tab, measured once per line #[serde(skip)] pub log_widths: crate::log_panel::LogWidthCache, diff --git a/crates/ui-egui/src/windows.rs b/crates/ui-egui/src/windows.rs index dbf29eeb..31299e0f 100644 --- a/crates/ui-egui/src/windows.rs +++ b/crates/ui-egui/src/windows.rs @@ -263,7 +263,7 @@ pub(crate) fn history(app: &mut TextureCraftApp, ui: &mut Ui) { let total_rows = 1 + done.len() + undone.len(); // Only new steps or a new container (with its own scroll) bring the current one into view; a tool change keeps the user's scroll - let shown = Some((ui.make_persistent_id("history"), done.len(), undone.len(), done.last().cloned())); + let shown = Some((ui.make_persistent_id("history"), app.session.steps_added(), done.len(), undone.len())); let follow = app.ui.history_shown != shown; app.ui.history_shown = shown; diff --git a/crates/ui-egui/tests/it/history_panel.rs b/crates/ui-egui/tests/it/history_panel.rs index f9a82b9a..2880feac 100644 --- a/crates/ui-egui/tests/it/history_panel.rs +++ b/crates/ui-egui/tests/it/history_panel.rs @@ -293,7 +293,7 @@ fn scrolling_up_is_not_pulled_back() { assert!(!current_shown(&harness, "Rename layer")); } -/// Once the history is full, a new step keeps the step count; its new name still brings it into view +/// Once the history is full, a new step keeps the step count and still comes into view #[test] fn the_newest_step_shows_past_the_history_cap() { let steps = texturecraft_engine::session::MAX_HISTORY + 60; @@ -311,6 +311,21 @@ fn the_newest_step_shows_past_the_history_cap() { assert!(current_shown(&harness, &newest)); } +/// A full history with a new step named like the newest one keeps its counts and names, and still comes into view +#[test] +fn a_repeated_step_shows_past_the_history_cap() { + let mut harness = history_harness(long_session(texturecraft_engine::session::MAX_HISTORY)); + let capped = harness.state().session.history_labels(); + scroll_to_top(&mut harness); + assert!(!current_shown(&harness, "Rename layer")); + + execute(&mut harness.state_mut().session, "layer.rename", &json!({"name": "Once more"})).unwrap(); + harness.run_steps(4); + + assert_eq!(harness.state().session.history_labels(), capped); + assert!(current_shown(&harness, "Rename layer")); +} + /// A History list that moves to another container (rail popup to floating window) still shows the current step #[test] fn an_undocked_history_shows_the_newest_step() { From 226e2de43a60719fd007035bcfc72dd66ad2f80f Mon Sep 17 00:00:00 2001 From: Rebornim <250083243+Rebornim@users.noreply.github.com> Date: Sun, 29 Nov 2026 12:49:21 +0000 Subject: [PATCH 6/8] Keep the current History step on screen when the list gets shorter --- crates/ui-egui/src/state.rs | 4 +++ crates/ui-egui/src/windows.rs | 19 +++++++--- crates/ui-egui/tests/it/history_panel.rs | 44 ++++++++++++++++++++++-- 3 files changed, 60 insertions(+), 7 deletions(-) diff --git a/crates/ui-egui/src/state.rs b/crates/ui-egui/src/state.rs index d52bca3f..7429a617 100644 --- a/crates/ui-egui/src/state.rs +++ b/crates/ui-egui/src/state.rs @@ -747,6 +747,9 @@ pub struct UiState { /// The History panel's last shown container and steps (added so far, done, undone): a change scrolls to the current step #[serde(skip)] pub history_shown: Option<(egui::Id, u64, usize, usize)>, + /// The History list's last height in points and whether the current step was on screen in it + #[serde(skip)] + pub history_view: Option<(f32, bool)>, /// The widest line of each Log tab, measured once per line #[serde(skip)] pub log_widths: crate::log_panel::LogWidthCache, @@ -919,6 +922,7 @@ impl Default for UiState { log_anchor: None, log_id: 0, history_shown: None, + history_view: None, log_widths: Default::default(), } } diff --git a/crates/ui-egui/src/windows.rs b/crates/ui-egui/src/windows.rs index 31299e0f..6078a4c7 100644 --- a/crates/ui-egui/src/windows.rs +++ b/crates/ui-egui/src/windows.rs @@ -262,18 +262,23 @@ pub(crate) fn history(app: &mut TextureCraftApp, ui: &mut Ui) { let done_count = done.len() as i64; let total_rows = 1 + done.len() + undone.len(); - // Only new steps or a new container (with its own scroll) bring the current one into view; a tool change keeps the user's scroll + // New steps or a new container (with its own scroll) bring the current one into view; a tool change keeps the user's scroll let shown = Some((ui.make_persistent_id("history"), app.session.steps_added(), done.len(), undone.len())); - let follow = app.ui.history_shown != shown; + // A list made shorter keeps the current step on screen if it was there; one the user scrolled away from it stays put + let height = ui.available_height(); + let shrunk = app.ui.history_view.is_some_and(|(height_before, was_in_view)| was_in_view && height < height_before); + let follow = app.ui.history_shown != shown || shrunk; app.ui.history_shown = shown; // A click on a step goes back (or forward) to it: steps to undo, or to redo when negative let mut jump = 0i64; - let area = egui::ScrollArea::vertical().id_salt("history").auto_shrink([false, false]); - crate::log_panel::panel_rows(ui, area, HISTORY_ROW_HEIGHT, total_rows, |ui, range| { + // Not animated: a scroll request then shows in the offset returned this frame, which a resize by dragging relies on + let area = egui::ScrollArea::vertical().id_salt("history").auto_shrink([false, false]).animated(false); + let current_row_top = done.len() as f32 * HISTORY_ROW_HEIGHT; + let list = crate::log_panel::panel_rows(ui, area, HISTORY_ROW_HEIGHT, total_rows, |ui, range| { if follow { - let top = ui.max_rect().top() + (done.len() as f32 - range.start as f32) * HISTORY_ROW_HEIGHT; + let top = ui.max_rect().top() + current_row_top - range.start as f32 * HISTORY_ROW_HEIGHT; let current = egui::Rect::from_x_y_ranges(ui.max_rect().x_range(), top..=top + HISTORY_ROW_HEIGHT); ui.scroll_to_rect_animation(current, None, egui::style::ScrollAnimation::none()); } @@ -295,6 +300,10 @@ pub(crate) fn history(app: &mut TextureCraftApp, ui: &mut Ui) { } }); + let current_top_in_view = current_row_top - list.state.clamped_offset().y; + let current_in_view = current_top_in_view < list.inner_rect.height() && current_top_in_view + HISTORY_ROW_HEIGHT > 0.0; + app.ui.history_view = Some((height, current_in_view)); + if jump > 0 { app.run("edit.undo", json!({ "steps": jump })); } else if jump < 0 { diff --git a/crates/ui-egui/tests/it/history_panel.rs b/crates/ui-egui/tests/it/history_panel.rs index 2880feac..ade144d7 100644 --- a/crates/ui-egui/tests/it/history_panel.rs +++ b/crates/ui-egui/tests/it/history_panel.rs @@ -1,14 +1,15 @@ //! The History panel: a click on a step goes back or forward to it, the current step is marked and kept in view +use craft_behavior::dock::Action; use egui::accesskit::Toggled; -use egui::{Event, Key, Modifiers, vec2}; +use egui::{Event, Key, Modifiers, Rect, pos2, vec2}; use egui_kittest::Harness; use egui_kittest::kittest::{NodeT, Queryable}; use serde_json::json; use texturecraft_engine::geom::glam::Vec3; use texturecraft_engine::{Session, execute}; use texturecraft_ui_egui::TextureCraftApp; -use texturecraft_ui_egui::docking::Panel; +use texturecraft_ui_egui::docking::{Dock, Panel, permissions}; /// Show document history so row clicks exercise the same command dispatch as the application fn history_harness(session: Session) -> Harness<'static, TextureCraftApp> { @@ -326,6 +327,45 @@ fn a_repeated_step_shows_past_the_history_cap() { assert!(current_shown(&harness, "Rename layer")); } +/// A History window short enough to cut many rows off the list +const SHORT_HEIGHT: f32 = 220.0; + +/// Show History in a floating window `height` points tall, as dragging its bottom edge does +fn set_history_height(harness: &mut Harness<'_, TextureCraftApp>, height: f32) { + let rect = Rect::from_min_size(pos2(960.0, 190.0), vec2(300.0, height)); + let mut workspace = harness.state().ui.dock.workspace().clone(); + workspace.apply_all([Action::float(Panel::History, rect)], false, permissions).unwrap(); + harness.state_mut().ui.dock = Dock::from_value(serde_json::to_value(workspace).unwrap()); +} + +/// A list shortened on every frame, as a resize by dragging does, keeps the current step on screen without a new step +#[test] +fn a_history_shortened_over_several_frames_keeps_the_current_step_on_screen() { + let mut harness = history_harness(long_session(STEPS_PAST_THE_PANEL)); + + // Each height is more than a row shorter than the one before, from the 380 points the window opens at + for height in [340.0, 300.0, 260.0, SHORT_HEIGHT] { + set_history_height(&mut harness, height); + harness.step(); + } + harness.run_steps(4); + + assert!(current_shown(&harness, "Rename layer")); +} + +/// A list the user scrolled away from the current step stays there when it is made shorter +#[test] +fn shortening_a_scrolled_up_history_keeps_the_scroll() { + let mut harness = history_harness(long_session(STEPS_PAST_THE_PANEL)); + scroll_to_top(&mut harness); + + set_history_height(&mut harness, SHORT_HEIGHT); + harness.run_steps(4); + + assert!(!current_shown(&harness, "Rename layer")); + assert!(harness.query_by_label("Project opened").is_some()); +} + /// A History list that moves to another container (rail popup to floating window) still shows the current step #[test] fn an_undocked_history_shows_the_newest_step() { From a42d053c3e68a8ccac3de282e716de958ed06c53 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 29 Nov 2026 15:29:32 -0500 Subject: [PATCH 7/8] test(nightly): retain exact launcher query and profile coverage (#913) --- apps/texturecraft/src/launch_profile.rs | 24 ++++++++++++++++-------- apps/texturecraft/src/profile_root.rs | 4 +++- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/apps/texturecraft/src/launch_profile.rs b/apps/texturecraft/src/launch_profile.rs index 9e29c559..b75287fd 100644 --- a/apps/texturecraft/src/launch_profile.rs +++ b/apps/texturecraft/src/launch_profile.rs @@ -110,14 +110,22 @@ mod tests { let plain = craft_nightly::parse_startup(BuildFlavor::NightlyV1, &spec, args(&[flag]), &StartupOptions::new()).unwrap(); assert!(plain.is_version_query(), "plain {flag}"); - let launcher = craft_nightly::parse_startup( - BuildFlavor::NightlyV1, - &spec, - args(&["--launch-profile", craft_nightly::NIGHTLY_V1_CONTRACT, "--profile-root", absolute(), flag]), - &StartupOptions::new(), - ) - .unwrap(); - assert!(launcher.is_version_query(), "launcher {flag}"); + for header in [ + ["--launch-profile", craft_nightly::NIGHTLY_V1_CONTRACT, "--profile-root", absolute()], + ["--profile-root", absolute(), "--launch-profile", craft_nightly::NIGHTLY_V1_CONTRACT], + ] { + let mut query = args(&header); + query.push(flag.into()); + assert!( + craft_nightly::parse_startup(BuildFlavor::NightlyV1, &spec, query, &StartupOptions::new()).unwrap().is_version_query(), + "launcher {flag}" + ); + let mut gpu = args(&header); + gpu.extend(args(&["--gpu", "nvidia", flag])); + let launch = craft_nightly::parse_startup(BuildFlavor::NightlyV1, &spec, gpu, &StartupOptions::new()).unwrap(); + assert!(!launch.is_version_query()); + assert_eq!(launch.passthrough_args, args(&["--gpu", "nvidia", flag])); + } } let file_named_version = craft_nightly::parse_startup(BuildFlavor::NightlyV1, &spec, args(&["--", "--version"]), &StartupOptions::new()).unwrap(); diff --git a/apps/texturecraft/src/profile_root.rs b/apps/texturecraft/src/profile_root.rs index 7ab39c60..b2c53f2b 100644 --- a/apps/texturecraft/src/profile_root.rs +++ b/apps/texturecraft/src/profile_root.rs @@ -198,7 +198,9 @@ mod tests { } assert_eq!(validate_and_prepare_root(&private, &spec).expect("reopen populated profile"), private); - assert_eq!(std::fs::read(private.join("app.ron")).unwrap(), b"saved profile data"); + for name in ["app.ron", "ui.json", "errors.log", "nightly-session.lock", "nightly-session.json"] { + assert_eq!(std::fs::read(private.join(name)).unwrap(), b"saved profile data", "{name} remains intact after reopen"); + } for name in PROFILE_FOLDERS { let path = private.join(name); From 8c4bf602e88a8fd2cfa8717840ef31c036a85654 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 29 Nov 2026 16:16:21 -0500 Subject: [PATCH 8/8] ci(nightly): enable automated 06:00 UTC schedule and signer dispatch (#898) --- .github/nightly-signing-policy.json | 4 ++- .github/workflows/nightly-dispatch.yml | 4 +-- .github/workflows/nightly.yml | 5 ++-- packaging/nightly-release-tests.py | 35 +++++++++++++++++--------- 4 files changed, 31 insertions(+), 17 deletions(-) diff --git a/.github/nightly-signing-policy.json b/.github/nightly-signing-policy.json index 61714f01..58445c26 100644 --- a/.github/nightly-signing-policy.json +++ b/.github/nightly-signing-policy.json @@ -88,7 +88,9 @@ } }, "max_artifact_bytes": 2147483648, - "automatic_signer_actors": [], + "automatic_signer_actors": [ + "github-actions[bot]" + ], "platforms": { "windows-x86_64": { "unsigned_artifact_name": "nightly-unsigned-windows-x86_64", diff --git a/.github/workflows/nightly-dispatch.yml b/.github/workflows/nightly-dispatch.yml index bd40f765..2445bdd2 100644 --- a/.github/workflows/nightly-dispatch.yml +++ b/.github/workflows/nightly-dispatch.yml @@ -11,9 +11,9 @@ permissions: {} jobs: dispatch: - # SOURCE PREPARATION: literal off until immutable shared tooling and policy qualification. + # Exact context guard only; admission belongs to the protected signer branch. if: >- - false && github.repository == 'storytold/texturecraft' && + github.repository == 'storytold/texturecraft' && github.event_name == 'workflow_run' runs-on: ubuntu-latest timeout-minutes: 5 diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index c05c2e31..173ba6cc 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -1,8 +1,9 @@ name: TextureCraft unsigned nightly -# Enabled for supervised manual runs by the reviewed manual actor only; no schedule yet. -# A later explicit opt-in may add a cadence (and turn on nightly-dispatch.yml with it). +# Automated daily schedule at 06:00 UTC plus supervised manual runs by reviewed manual actors. on: + schedule: + - cron: '0 6 * * *' workflow_dispatch: permissions: diff --git a/packaging/nightly-release-tests.py b/packaging/nightly-release-tests.py index 55c08d86..840110b8 100755 --- a/packaging/nightly-release-tests.py +++ b/packaging/nightly-release-tests.py @@ -217,15 +217,21 @@ class TrustedSourcePreparation(unittest.TestCase): (indicator, expression), = job_conditions(jobs) self.assertFalse(indicator == ">-" and " ".join(expression.split()) == expected) - def test_no_nightly_schedule_is_registered(self): - for name, event in (("nightly.yml", "workflow_dispatch"), - ("nightly-sign.yml", "workflow_dispatch")): + def test_nightly_triggers_match_reviewed_schedule_and_dispatch(self): + expected = { + "nightly.yml": [" schedule:", " workflow_dispatch:"], + "nightly-sign.yml": [" workflow_dispatch:"], + } + for name, expected_triggers in expected.items(): source = (ROOT / ".github/workflows" / name).read_text() events = source.split("\non:\n", 1)[1].split("\npermissions:", 1)[0] triggers = [line for line in events.splitlines() if line.startswith(" ") and not line.startswith(" ") and line.strip() and not line.lstrip().startswith("#")] with self.subTest(workflow=name): - self.assertEqual(triggers, [f" {event}:"], "schedule/activation needs explicit review") + self.assertEqual(triggers, expected_triggers, "schedule/activation needs explicit review") + producer = (ROOT / ".github/workflows/nightly.yml").read_text() + self.assertEqual(re.findall(r"(?m)^ - cron: '([^']+)'$", producer), ["0 6 * * *"], + "nightly schedule must remain pinned to the reviewed 06:00 UTC cron") def test_signer_serialization_contract_is_enforced(self): assert_nightly_serialization((ROOT / ".github/workflows/nightly-sign.yml").read_text()) @@ -360,7 +366,8 @@ class NightlyEnabledCallers(unittest.TestCase): source = (ROOT / ".github/workflows/nightly.yml").read_text() policy = json.loads(INSTALLED_POLICY.read_text()) self.assertEqual(reviewed_manual_actors(source, policy), RELEASE_MANAGERS) - self.assertEqual(policy["automatic_signer_actors"], [], "no automatic signer without a schedule") + self.assertEqual(policy["automatic_signer_actors"], ["github-actions[bot]"], + "automatic signer is limited to github-actions[bot]") def test_an_actor_outside_the_release_managers_is_refused(self): source = (ROOT / ".github/workflows/nightly.yml").read_text() @@ -824,19 +831,23 @@ def dispatch_triggers(source): class NightlyDispatchTransport(unittest.TestCase): - """The scheduled transport stays literally off and can only reach the signer branch.""" + """The scheduled transport runs only in its exact context and can only reach the signer branch.""" + + DISPATCH_GUARD = "github.repository == 'storytold/texturecraft' && github.event_name == 'workflow_run'" def setUp(self): self.source = (ROOT / ".github/workflows/nightly-dispatch.yml").read_text() - def test_every_dispatch_job_is_literal_off(self): + def test_dispatch_job_keeps_exact_context_guard(self): jobs = self.source.split("\njobs:\n", 1)[1] - headers = re.findall(r"(?m)^ (?![\s#])[^\n]+", jobs) + self.assertEqual(re.findall(r"(?m)^ ([^\s#][^:]*):", jobs), ["dispatch"]) conditions = job_conditions(jobs) - self.assertTrue(headers) - self.assertEqual(len(conditions), len(headers), "every job needs a literal-off condition") - for _, expression in conditions: - self.assertTrue(literal_off(expression), "nightly activation requires reviewed test update") + self.assertEqual(len(conditions), 1) + indicator, expression = conditions[0] + self.assertEqual(indicator, ">-") + self.assertFalse(literal_off(expression), "scheduled dispatch transport must be enabled") + self.assertEqual(" ".join(expression.split()), self.DISPATCH_GUARD, + "dispatch guard may only change with review") def test_only_a_completed_scheduled_producer_is_transported(self): self.assertEqual(re.findall(r"(?m)^ workflows: (.+)$", self.source),