mirror of
https://github.com/storytold/texturecraft.git
synced 2026-11-30 10:03:56 +01:00
Merge commit '8c4bf602e88a8fd2cfa8717840ef31c036a85654' into HEAD
This commit is contained in:
commit
00c169ed79
18 files changed
+877
-139
No files matched your search
@@ -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",
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -568,9 +568,10 @@ 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());
|
||||
if stroke.canvas.dirty.is_empty() {
|
||||
// Nothing painted: drop any mask effect the stroke created
|
||||
@@ -590,6 +591,7 @@ impl Session {
|
||||
|
||||
let mesh = self.mesh.clone();
|
||||
let mut staging = std::mem::take(&mut stroke.staging);
|
||||
|
||||
match stroke.target {
|
||||
Some(PaintTarget::Layer(id)) => {
|
||||
let pixels = &mut self.doc.pixels;
|
||||
@@ -608,10 +610,8 @@ 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, stroke.before);
|
||||
self.redo.clear();
|
||||
self.mark_modified();
|
||||
|
||||
|
||||
@@ -485,6 +485,8 @@ pub struct Session {
|
||||
pub caches: Vec<SetCache>,
|
||||
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
|
||||
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,
|
||||
@@ -595,6 +597,7 @@ impl Session {
|
||||
caches,
|
||||
undo: Vec::new(),
|
||||
redo: Vec::new(),
|
||||
steps_added: 0,
|
||||
merge_edits: false,
|
||||
tool: ToolState::default(),
|
||||
active_set: 0,
|
||||
@@ -823,7 +826,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
|
||||
@@ -833,11 +836,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)
|
||||
@@ -1056,10 +1070,27 @@ impl Session {
|
||||
|
||||
/// The undone steps, the next one to redo first.
|
||||
pub fn redo_labels(&self) -> Vec<String> {
|
||||
self.redo.iter().rev().map(|(l, _)| l.clone()).collect()
|
||||
self.iter_redo_labels().map(str::to_owned).collect()
|
||||
}
|
||||
|
||||
/// Borrow undone step labels, with the next step to redo first
|
||||
pub fn iter_redo_labels(&self) -> impl ExactSizeIterator<Item = &str> {
|
||||
self.redo.iter().rev().map(|(label, _)| label.as_str())
|
||||
}
|
||||
|
||||
/// 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<String> {
|
||||
self.undo.iter().map(|(l, _)| l.clone()).collect()
|
||||
self.iter_history_labels().map(str::to_owned).collect()
|
||||
}
|
||||
|
||||
/// Borrow the labels of completed steps, oldest first
|
||||
pub fn iter_history_labels(&self) -> impl ExactSizeIterator<Item = &str> {
|
||||
self.undo.iter().map(|(label, _)| label.as_str())
|
||||
}
|
||||
|
||||
/// Undo a point edit, cancel an uncommitted path, or restore a document snapshot, in that order
|
||||
|
||||
@@ -1507,3 +1507,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 session = session();
|
||||
for _ in 0..texturecraft_engine::session::MAX_HISTORY {
|
||||
execute(&mut session, "tool.stroke", &json!({"points": [[180, 200], [220, 200]]})).unwrap();
|
||||
}
|
||||
let (labels, added) = (session.history_labels(), session.steps_added());
|
||||
|
||||
execute(&mut session, "tool.stroke", &json!({"points": [[180, 200], [220, 200]]})).unwrap();
|
||||
|
||||
assert_eq!(session.history_labels(), labels);
|
||||
assert!(session.steps_added() > added);
|
||||
|
||||
// A path preview paints through strokes of its own, none of which is a step
|
||||
let added = session.steps_added();
|
||||
execute(&mut session, "tool.path", &json!({"uvPoints": [[0.2, 0.5], [0.8, 0.5]]})).unwrap();
|
||||
|
||||
assert_eq!(session.history_labels(), labels);
|
||||
assert_eq!(session.steps_added(), added);
|
||||
}
|
||||
@@ -585,6 +585,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
|
||||
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;
|
||||
|
||||
@@ -615,8 +618,13 @@ 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 };
|
||||
// Let panels with full-width content set their own side margins
|
||||
let margin = match panel {
|
||||
Panel::Properties => Margin::ZERO,
|
||||
Panel::History | Panel::Log => 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),
|
||||
@@ -629,7 +637,7 @@ pub(crate) fn panel_body(app: &mut TextureCraftApp, ui: &mut Ui, panel: Panel) {
|
||||
Panel::TextureSetSettings => crate::dock::texture_set_settings(app, ui),
|
||||
Panel::Properties => crate::dock::properties(app, ui),
|
||||
|
||||
// Display and Shader Settings scroll one page under their section tabs; History and Log scroll their own lists
|
||||
// Each of these panels owns its scroll area
|
||||
Panel::Display => crate::display_settings::body(app, ui),
|
||||
Panel::Shader => crate::shader_settings::body(app, ui),
|
||||
Panel::History => crate::windows::history(app, ui),
|
||||
|
||||
+187
-27
@@ -1,6 +1,8 @@
|
||||
//! The Log panel: the session's messages under a General and an Assets tab, one per channel
|
||||
|
||||
use egui::{Color32, RichText, Ui};
|
||||
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,150 @@ 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;
|
||||
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() {
|
||||
// Restrict focus reveal to vertical scrolling
|
||||
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<R>(
|
||||
ui: &mut Ui,
|
||||
area: egui::ScrollArea,
|
||||
row_height: f32,
|
||||
total_rows: usize,
|
||||
add_rows: impl FnOnce(&mut Ui, std::ops::Range<usize>) -> R,
|
||||
) -> egui::scroll_area::ScrollAreaOutput<R> {
|
||||
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;
|
||||
// Use text colors to keep the thumb distinct from the track
|
||||
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 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 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; returns the open tab's rectangle
|
||||
fn channel_tabs(app: &mut TextureCraftApp, ui: &mut Ui, tokens: &Tokens) -> Rect {
|
||||
// Count the panel margin toward the tab 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());
|
||||
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 {
|
||||
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);
|
||||
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;
|
||||
}
|
||||
}
|
||||
open_tab
|
||||
}
|
||||
|
||||
/// Flatten embedded line breaks for layout while leaving the stored message intact for copy
|
||||
fn row_text(line: String) -> String {
|
||||
if line.contains(['\r', '\n']) { line.replace(['\r', '\n'], " ") } else { line }
|
||||
}
|
||||
|
||||
/// 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());
|
||||
|
||||
// Hit testing and accessibility bounds use the visible portion of a wide row
|
||||
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(line), 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
|
||||
fn listed(app: &TextureCraftApp, channel: LogChannel) -> Vec<usize> {
|
||||
@@ -22,11 +166,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,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,16 +274,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 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 {
|
||||
@@ -148,15 +284,33 @@ pub(crate) fn body(app: &mut TextureCraftApp, ui: &mut Ui) {
|
||||
app.ui.log_anchor = None;
|
||||
}
|
||||
|
||||
// Overlap the tab border and count the panel margin toward the bottom inset
|
||||
let inset = PANEL_INSET as i8;
|
||||
let outer = egui::Margin { left: inset, right: inset, top: -1, bottom: inset - crate::docking::LIST_PANEL_MARGIN.bottom };
|
||||
|
||||
// Keep rows and scrollbars clear of the frame stroke
|
||||
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, 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 tk = Tokens::get(ui.ctx());
|
||||
let shown = app.ui.log_channel;
|
||||
let rows = listed(app, shown);
|
||||
|
||||
// The empty space under the lines has the same menu as a line; the lines sit on top of it
|
||||
// Put the background menu behind the row hit targets
|
||||
let area = ui.available_rect_before_wrap();
|
||||
let pass = ui.ctx().cumulative_pass_nr();
|
||||
ui.ctx().data_mut(|data| data.insert_temp(rect_id(), (area, ui.layer_id(), pass)));
|
||||
@@ -169,16 +323,22 @@ 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() {
|
||||
// Measure the widest line to size the horizontal scroll area
|
||||
let font = egui::FontId::proportional(LINE_TEXT_SIZE);
|
||||
let measure = |entry: &LogEntry| ui.painter().layout_no_wrap(row_text(entry.line()), 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)
|
||||
.horizontal_scroll_bar_label(tr("Log horizontal scrollbar"))
|
||||
.vertical_scroll_bar_label(tr("Log vertical scrollbar"));
|
||||
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);
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
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_entries: 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 appended_entries = 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_entries + appended_entries != 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_entries += 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);
|
||||
}
|
||||
}
|
||||
@@ -735,6 +735,15 @@ 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 (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,
|
||||
}
|
||||
|
||||
pub(crate) const MAX_RECENT_PROJECTS: u16 = 100;
|
||||
@@ -902,6 +911,9 @@ impl Default for UiState {
|
||||
log_selection: Default::default(),
|
||||
log_anchor: None,
|
||||
log_id: 0,
|
||||
history_shown: None,
|
||||
history_view: None,
|
||||
log_widths: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,47 +246,65 @@ 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 = app.session.iter_history_labels();
|
||||
let undone = app.session.iter_redo_labels();
|
||||
let done_count = done.len();
|
||||
let total_rows = 1 + done_count + undone.len();
|
||||
|
||||
// Follow document steps and moved panels while leaving tool changes alone
|
||||
let history_key = Some((ui.make_persistent_id("history"), app.session.steps_added(), done_count, undone.len()));
|
||||
|
||||
// Preserve visibility during a resize if the user was already viewing the current step
|
||||
let height = ui.available_height();
|
||||
let shrunk = app.ui.history_view.is_some_and(|(previous_height, was_in_view)| was_in_view && height < previous_height);
|
||||
let follow = app.ui.history_shown != history_key || shrunk;
|
||||
app.ui.history_shown = history_key;
|
||||
|
||||
// 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!({}));
|
||||
}
|
||||
if ui.add_enabled(app.session.can_redo(), egui::Button::new(format!("{} {}", ic::ARROW_CLOCKWISE, tr("Redo")))).clicked() {
|
||||
app.run("edit.redo", json!({}));
|
||||
}
|
||||
});
|
||||
// Update the returned offset immediately so each frame of a dragged resize sees the previous reveal
|
||||
let area = egui::ScrollArea::vertical().id_salt("history").auto_shrink([false, false]).animated(false).vertical_scroll_bar_label(tr("History scrollbar"));
|
||||
let current_row_top = done_count 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() + 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());
|
||||
}
|
||||
|
||||
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)
|
||||
};
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
let labels = std::iter::once(None).chain(done.map(|label| Some((label, false)))).chain(undone.map(|label| Some((label, true))));
|
||||
for (row, label) in labels.enumerate().skip(range.start).take(range.len()) {
|
||||
let (name, color) = history_row_name(label, &tokens);
|
||||
let steps = done_count as i64 - 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)
|
||||
};
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
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 {
|
||||
@@ -297,6 +312,43 @@ pub(crate) fn history(app: &mut TextureCraftApp, ui: &mut Ui) {
|
||||
}
|
||||
}
|
||||
|
||||
/// The name and colour of a History row, with no step label for the opened project
|
||||
fn history_row_name(step: Option<(&str, bool)>, tokens: &Tokens) -> (String, egui::Color32) {
|
||||
let Some((label, undone)) = step else { return (tr("Project opened").to_owned(), tokens.text_dim) };
|
||||
|
||||
let translated = tr_history(label);
|
||||
if undone { (trf("{action} (undone)", &[("action", &translated)]), tokens.text_dim) } else { (translated, tokens.text) }
|
||||
}
|
||||
|
||||
/// 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;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
// Inset both text edges equally from the current-step outline
|
||||
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) {
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
//! 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 craft_behavior::dock::Action;
|
||||
use egui::accesskit::Toggled;
|
||||
use egui::{Event, Key, Modifiers, Rect, pos2, vec2};
|
||||
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};
|
||||
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> {
|
||||
@@ -19,6 +22,25 @@ 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 labels and bounds of the rows marked as current
|
||||
fn current_rows(harness: &Harness<'_, TextureCraftApp>) -> Vec<(String, Rect)> {
|
||||
let session = &harness.state().session;
|
||||
let undone = session.redo_labels().into_iter().map(|label| format!("{label} (undone)"));
|
||||
let names: Vec<String> = 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())))
|
||||
.filter(|(name, _)| names.contains(name))
|
||||
.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 +71,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 +83,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 +100,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 +112,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 +148,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 +214,200 @@ 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.top() < before[0].1.top(), "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());
|
||||
}
|
||||
|
||||
/// 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 entire current row is within the History list's viewport
|
||||
fn current_shown(harness: &Harness<'_, TextureCraftApp>, name: &str) -> bool {
|
||||
let track = harness.get_by_role_and_label(egui::accesskit::Role::ScrollBar, "History scrollbar").rect();
|
||||
|
||||
current_rows(harness).iter().any(|(label, row)| label == name && track.top() <= row.top() && row.bottom() <= track.bottom())
|
||||
}
|
||||
|
||||
/// Scroll the History list back to its first rows with the mouse wheel
|
||||
fn scroll_to_top(harness: &mut Harness<'_, TextureCraftApp>) {
|
||||
let (_, row) = current_rows(harness)[0];
|
||||
harness.hover_at(row.center());
|
||||
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 and still comes 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 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 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() {
|
||||
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 (_, row) = current_rows(&harness)[0];
|
||||
harness.get_all_by_label("Rename layer").find(|node| node.rect() == row).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));
|
||||
}
|
||||
@@ -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,18 +134,105 @@ 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 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 bar = harness.get_by_role_and_label(egui::accesskit::Role::ScrollBar, "Log vertical scrollbar").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!(general.left() < bar.left() && bar.right() < frame_inside, "{bar:?} {assets:?}");
|
||||
}
|
||||
|
||||
/// How many rows each painted text containing `part` has
|
||||
fn painted_rows(harness: &Harness<'_, TextureCraftApp>, part: &str) -> Vec<usize> {
|
||||
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]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_multiline_message_scrolls_on_one_row_and_copies_verbatim() {
|
||||
let mut harness = app();
|
||||
let message = format!("broken\r\n{}end", "long ".repeat(100));
|
||||
log_behind_a_newer_line(&mut harness, &message);
|
||||
let label = format!("[Exporter] {message}");
|
||||
|
||||
let painted_left = |harness: &Harness<'_, TextureCraftApp>| {
|
||||
harness.output().shapes.iter().find_map(|clipped| match &clipped.shape {
|
||||
egui::Shape::Text(text) if text.galley.text().starts_with("[Exporter] broken") => Some(text.pos.x),
|
||||
_ => None,
|
||||
})
|
||||
};
|
||||
assert_eq!(painted_rows(&harness, "broken"), vec![1]);
|
||||
let before = painted_left(&harness).unwrap();
|
||||
let track = harness.get_by_role_and_label(egui::Role::ScrollBar, "Log horizontal scrollbar").rect();
|
||||
harness.hover_at(egui::pos2(track.right() - 1.0, track.center().y));
|
||||
harness.step();
|
||||
let at = egui::pos2(track.right() - 1.0, track.center().y);
|
||||
for pressed in [true, false] {
|
||||
harness.event(Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed, modifiers: Modifiers::NONE });
|
||||
harness.step();
|
||||
}
|
||||
harness.run_steps(3);
|
||||
|
||||
assert!(painted_left(&harness).unwrap() < before);
|
||||
key_click(&mut harness, &label, Modifiers::NONE);
|
||||
harness.event(Event::Copy);
|
||||
harness.step();
|
||||
|
||||
assert!(harness.output().platform_output.commands.contains(&OutputCommand::CopyText(label)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -209,3 +299,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));
|
||||
}
|
||||
@@ -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]
|
||||
|
||||
@@ -36,10 +36,12 @@ 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
|
||||
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");
|
||||
bar.rect().height()
|
||||
/// The named vertical track measures the visible list height
|
||||
fn list_height(harness: &Harness<'_, TextureCraftApp>, scrollbar: &str) -> f32 {
|
||||
let track = harness.get_by_role_and_label(Role::ScrollBar, scrollbar).rect();
|
||||
assert!(track.right() < LEFT_COLUMN_MAX_X, "the track must be in the left column");
|
||||
|
||||
track.height()
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -58,7 +60,7 @@ fn the_history_list_fills_a_tall_panel() {
|
||||
harness.run_steps(STARTUP_FRAMES);
|
||||
|
||||
assert!(harness.state().ui.dock.is_visible(Panel::History));
|
||||
let height = list_height(&harness);
|
||||
let height = list_height(&harness, "History scrollbar");
|
||||
assert!(height > OLD_HISTORY_HEIGHT, "the history list is {height} points tall");
|
||||
}
|
||||
|
||||
@@ -76,6 +78,6 @@ fn the_log_list_fills_a_tall_panel() {
|
||||
harness.run_steps(STARTUP_FRAMES);
|
||||
|
||||
assert!(harness.state().ui.dock.is_visible(Panel::Log));
|
||||
let height = list_height(&harness);
|
||||
let height = list_height(&harness, "Log vertical scrollbar");
|
||||
assert!(height > OLD_LOG_HEIGHT, "the log list is {height} points tall");
|
||||
}
|
||||
@@ -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),
|
||||
|
||||
Reference in new issue
Block a user