diff --git a/crates/ui-egui/src/control.rs b/crates/ui-egui/src/control.rs index 79050e12..ab03dc37 100644 --- a/crates/ui-egui/src/control.rs +++ b/crates/ui-egui/src/control.rs @@ -111,6 +111,12 @@ fn refresh_draft_preferences(draft: &mut Prefs, previous: &Prefs, current: &Pref gpu_raytracing, libraries, background, + show_world_axes, + show_keyboard_helper, + only_selected_material_when_painting, + save_preprocessed_scene_files, + live_preview_baking, + local_cache_directory, ); } diff --git a/crates/ui-egui/src/keymap.rs b/crates/ui-egui/src/keymap.rs index ee29ac48..17f8acec 100644 --- a/crates/ui-egui/src/keymap.rs +++ b/crates/ui-egui/src/keymap.rs @@ -36,7 +36,14 @@ pub struct Binding { /// /// They are not in [`bindings`], so no key runs them, but another item given their key is reported /// as sharing it. -pub static NOT_AVAILABLE_ACTIONS: [(&str, Binding); 2] = [ +pub static NOT_AVAILABLE_ACTIONS: [(&str, Binding); 9] = [ + ("file.reimportMesh", Binding { id: "ui.manipulator.toggle", group: "Viewport", label: "Show/Hide manipulator", default: Some("Q") }), + ("file.reimportMesh", Binding { id: "ui.manipulator.grow", group: "Viewport", label: "Increase the manipulator size", default: None }), + ("file.reimportMesh", Binding { id: "ui.manipulator.shrink", group: "Viewport", label: "Decrease the manipulator size", default: Some("-") }), + ("file.reimportMesh", Binding { id: "ui.manipulator.space", group: "Viewport", label: "Cycle through manipulation spaces", default: Some("T") }), + ("file.reimportMesh", Binding { id: "ui.warpEdit", group: "Viewport", label: "Toggle warp edition mode", default: Some("Shift+V") }), + ("file.reimportMesh", Binding { id: "ui.manipulator.translate", group: "Viewport", label: "Translate tool", default: Some("W") }), + ("file.reimportMesh", Binding { id: "ui.manipulator.rotate", group: "Viewport", label: "Rotate tool", default: Some("E") }), ("file.reimportMesh", Binding { id: "ui.pauseEngine", group: "Commands", label: "Pause Engine Computation", default: Some("Shift+Esc") }), ("viewport.frame", Binding { id: "ui.toggleAnimation", group: "Viewport", label: "Toggle animation", default: Some("Space") }), ]; diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 47259f2b..f6b25a0f 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -342,11 +342,8 @@ pub(crate) fn start_ui(saved: Option, session: &mut Session) -> UiState ui.tool_settings.apply(&mut session.tool); ui } - None => { - let mut ui = UiState::default(); - ui.prefs.language = i18n::SYSTEM_LANGUAGE.into(); - ui - } + // The default language follows the operating system + None => UiState::default(), } } @@ -1228,13 +1225,25 @@ pub fn data_folder(pref: &str) -> std::path::PathBuf { std::path::Path::new(&home).join("Documents").join("TextureCraft") } -/// The data folder in use (Settings › Folders › Data folder). +/// The folder for a `Prefs::local_cache_directory` value: that path when it is absolute, +/// otherwise the system's temporary folder. +#[cfg(not(target_arch = "wasm32"))] +pub fn local_cache_folder(pref: &str) -> std::path::PathBuf { + let chosen = std::path::Path::new(pref.trim()); + if chosen.is_absolute() { + return chosen.to_path_buf(); + } + + std::env::temp_dir() +} + +/// The data folder in use (Settings › Files › Data folder). #[cfg(not(target_arch = "wasm32"))] pub fn data_dir() -> std::path::PathBuf { DATA_FOLDER.get().cloned().unwrap_or_else(|| data_folder("")) } -/// `` in the data folder in use (Settings › Folders › Data folder). +/// `` in the data folder in use (Settings › Files › Data folder). #[cfg(not(target_arch = "wasm32"))] pub fn user_dir(sub: &str) -> std::path::PathBuf { data_dir().join(sub) diff --git a/crates/ui-egui/src/settings_window.rs b/crates/ui-egui/src/settings_window.rs index 8fda17b0..7da312bc 100644 --- a/crates/ui-egui/src/settings_window.rs +++ b/crates/ui-egui/src/settings_window.rs @@ -9,7 +9,7 @@ use crate::TextureCraftApp; use crate::file_dialogs::{Bound, FileDialog}; use crate::i18n::{LANGUAGES, SYSTEM_LANGUAGE, n_, tr, trf}; use crate::state::{CAMERA_SPEED_RANGE, LibraryLocation, MAX_RECENT_PROJECTS, Prefs}; -use crate::theme::{Accent, Brightness, Tokens, caption}; +use crate::theme::{Tokens, caption}; use crate::unavailable::NOT_AVAILABLE; use crate::widgets::icon_button; @@ -274,9 +274,17 @@ fn section(ui: &mut Ui, title: &str) { ui.add_space(2.0); } -/// A disabled check box in the right column of a row labelled `label`. -fn disabled_check(ui: &mut Ui, label: egui::Id, mut checked: bool) { - not_available(ui.add_enabled(false, egui::Checkbox::without_text(&mut checked)).labelled_by(label)); +/// A check box in the right column of a row labelled `label`. +fn check(ui: &mut Ui, label: egui::Id, checked: &mut bool) { + ui.add(egui::Checkbox::without_text(checked)).labelled_by(label); +} + +/// A check box with its text. +fn text_check(ui: &mut Ui, text: &str, checked: &mut bool) { + ui.horizontal(|ui| { + ui.add_space(12.0); + ui.checkbox(checked, tr(text)); + }); } /// A disabled check box with its text. @@ -306,6 +314,35 @@ pub fn gpu_note_shown(adapter: Option<&str>) -> bool { adapter.is_none() || cfg!(target_arch = "wasm32") } +/// The Enable GPU raytracing check box for the hardware and the stored choice: whether it can be +/// changed and whether it shows ticked. Without a GPU to trace on it is off and disabled; the +/// stored choice is kept for a machine that has one. +pub fn gpu_raytracing_check(adapter: Option<&str>, stored: bool) -> (bool, bool) { + let supported = !gpu_note_shown(adapter); + (supported, supported && stored) +} + +/// The Max CPU threads slider's position for a stored `work_threads`: 0 (every thread) is the +/// slider's end, the core count. +#[cfg(not(target_arch = "wasm32"))] +fn work_threads_shown(work_threads: u32, cores: u32) -> u32 { + if work_threads == 0 { cores } else { work_threads.min(cores).max(1) } +} + +/// The stored `work_threads` for the slider at `threads`: its end keeps 0, so every thread works +/// on any machine. +#[cfg(not(target_arch = "wasm32"))] +fn work_threads_stored(threads: u32, cores: u32) -> u32 { + if threads >= cores { 0 } else { threads } +} + +/// The note right of a core slider: how many cores this machine has. +#[cfg(not(target_arch = "wasm32"))] +fn cores_in_total(ui: &mut Ui, cores: u32) { + let tk = Tokens::get(ui.ctx()); + ui.label(RichText::new(trf("{count} cores in total", &[("count", &cores)])).color(tk.text_dim)); +} + /// The General page. fn general( ui: &mut Ui, @@ -339,8 +376,8 @@ fn general( .response .labelled_by(label); }); - row(ui, tr("Show keyboard helper"), |ui, label| disabled_check(ui, label, true)); - row(ui, tr("Show world axes"), |ui, label| disabled_check(ui, label, true)); + row(ui, tr("Show keyboard helper"), |ui, label| check(ui, label, &mut p.show_keyboard_helper)); + row(ui, tr("Show world axes"), |ui, label| check(ui, label, &mut p.show_world_axes)); row(ui, tr("Background color"), |ui, _| { for (index, side, name) in [(0, "top", "Top background"), (1, "bottom", "Bottom background")] { let id = format!("settings_background_{side}"); @@ -352,20 +389,17 @@ fn general( ui.add_space(10.0); } }); - row(ui, tr("Only display the selected material when painting"), |ui, label| disabled_check(ui, label, false)); + row(ui, tr("Only display the selected material when painting"), |ui, label| check(ui, label, &mut p.only_selected_material_when_painting)); row(ui, tr("Viewport Scaling"), |ui, label| { - ui.add_enabled_ui(false, |ui| { - not_available( - egui::ComboBox::from_id_salt("settings_viewport_scaling").width(CONTROL_WIDTH).selected_text(tr("Auto")).show_ui(ui, |_| {}).response, - ) + // Auto is the one scaling the views have + egui::ComboBox::from_id_salt("settings_viewport_scaling") + .width(CONTROL_WIDTH) + .selected_text(tr("Auto")) + .show_ui(ui, |ui| { + ui.add(egui::Button::selectable(true, tr("Auto"))); + }) + .response .labelled_by(label); - }); - }); - - row(ui, tr("Recent projects limit"), |ui, label| { - ui.add(egui::DragValue::new(&mut p.recent_projects_limit).range(0..=MAX_RECENT_PROJECTS)) - .labelled_by(label) - .on_hover_text(tr("Number of recent projects to remember. 0 disables recent-project history.")); }); section(ui, n_("LAYER STACK OPTIONS")); @@ -397,12 +431,17 @@ fn general( } section(ui, n_("BAKING OPTIONS")); - disabled_text_check(ui, n_("Save preprocessed scene files"), true); - disabled_text_check(ui, n_("Enable live preview baking process"), true); + text_check(ui, n_("Save preprocessed scene files"), &mut p.save_preprocessed_scene_files); + text_check(ui, n_("Enable live preview baking process"), &mut p.live_preview_baking); + let (gpu_raytracing_enabled, mut gpu_raytracing_ticked) = gpu_raytracing_check(gpu, p.gpu_raytracing); ui.horizontal(|ui| { ui.add_space(12.0); - ui.checkbox(&mut p.gpu_raytracing, tr("Enable GPU raytracing")) + let gpu_raytracing = ui + .add_enabled(gpu_raytracing_enabled, egui::Checkbox::new(&mut gpu_raytracing_ticked, tr("Enable GPU raytracing"))) .on_hover_text(tr("Bakes cast their rays on the graphics card when one is available. Off, they run on the CPU.")); + if gpu_raytracing.changed() { + p.gpu_raytracing = gpu_raytracing_ticked; + } }); if gpu_note_shown(gpu) { ui.horizontal(|ui| { @@ -413,6 +452,17 @@ fn general( section(ui, n_("PREVIEW OPTIONS")); row(ui, tr("Local cache directory"), |ui, label| { + #[cfg(not(target_arch = "wasm32"))] + { + let default = crate::local_cache_folder("").display().to_string(); + ui.add(egui::TextEdit::singleline(&mut p.local_cache_directory).hint_text(default).desired_width(CONTROL_WIDTH - 24.0)).labelled_by(label); + if ui.add(egui::Button::new("R").frame(false)).on_hover_text(tr("Reset to the default folder")).clicked() { + p.local_cache_directory.clear(); + } + } + + // The browser has no folders + #[cfg(target_arch = "wasm32")] ui.add_enabled_ui(false, |ui| { let mut path = String::new(); not_available(ui.add(egui::TextEdit::singleline(&mut path).desired_width(CONTROL_WIDTH - 24.0))).labelled_by(label); @@ -431,7 +481,7 @@ fn general( not_available(ui.add_enabled(false, egui::Button::new(text).min_size(vec2(CONTROL_WIDTH, 40.0)))); }); - section(ui, n_("TEMPORARY FILES")); + section(ui, n_("FILES")); row(ui, tr("Cache directory"), |ui, label| { #[cfg(not(target_arch = "wasm32"))] let mut path = std::env::temp_dir().display().to_string(); @@ -442,57 +492,19 @@ fn general( not_available(ui.add(egui::Button::new("R").frame(false))); }); }); + #[cfg(not(target_arch = "wasm32"))] + row(ui, tr("Data folder"), |ui, label| { + let default = crate::data_folder("").display().to_string(); + ui.add(egui::TextEdit::singleline(&mut p.data_folder).hint_text(default).desired_width(CONTROL_WIDTH - 30.0)).labelled_by(label); + if ui.button("...").on_hover_text(tr("Choose the data folder")).clicked() { + *pick = Some(SettingsFolder::DataFolder); + } + }); section(ui, n_("SPARSE VIRTUAL TEXTURE")); disabled_text_check(ui, n_("Hardware support acceleration"), true); - section(ui, n_("IRAY HARDWARE")); - disabled_text_check(ui, gpu.unwrap_or(n_("no GPU")), true); - disabled_text_check(ui, n_("CPU"), false); - // TextureCraft's own settings, after the reference sections - section(ui, n_("APPEARANCE")); - row(ui, tr("Interface scale"), |ui, label| { - ui.add(egui::Slider::new(&mut p.ui_scale, 0.75..=2.0).fixed_decimals(2)).labelled_by(label); - }); - row(ui, tr("Brightness"), |ui, label| { - egui::ComboBox::from_id_salt("settings_brightness") - .width(140.0) - .selected_text(tr(p.brightness.label())) - .show_ui(ui, |ui| { - for b in Brightness::ALL { - ui.selectable_value(&mut p.brightness, b, tr(b.label())); - } - }) - .response - .labelled_by(label); - }); - row(ui, tr("Accent color"), |ui, _| { - for a in Accent::ALL { - let (rect, resp) = ui.allocate_exact_size(vec2(20.0, 20.0), egui::Sense::click()); - resp.widget_info(|| egui::WidgetInfo::selected(egui::Role::RadioButton, true, p.accent == a, tr(a.label()))); - let ring = if p.accent == a { - tk.text_strong - } else if resp.hovered() { - tk.text_dim - } else { - Color32::TRANSPARENT - }; - ui.painter().circle(rect.center(), 6.5, a.colors(tk.dark).0, egui::Stroke::NONE); - ui.painter().circle_stroke(rect.center(), 9.0, egui::Stroke::new(1.5, ring)); - if resp.on_hover_text(tr(a.label())).clicked() { - p.accent = a; - } - } - }); - #[cfg(not(target_arch = "wasm32"))] - { - row(ui, tr("Title bar"), |ui, _| { - ui.checkbox(&mut p.system_title_bar, tr("System title bar (applies on restart)")) - .on_hover_text(tr("Use the operating system's window frame and buttons instead of TextureCraft's own title bar")); - }); - } - section(ui, n_("VIEWPORT")); row(ui, tr("Texture resolution"), |ui, _| { ui.horizontal(|ui| { @@ -510,15 +522,22 @@ fn general( #[cfg(not(target_arch = "wasm32"))] { row(ui, tr("Max CPU threads for work"), |ui, label| { - ui.add(egui::DragValue::new(&mut p.work_threads).range(0..=available_cores)) + let mut threads = work_threads_shown(p.work_threads, available_cores); + let slider = ui + .add(egui::Slider::new(&mut threads, 1..=available_cores.max(1)).step_by(1.0)) .labelled_by(label) - .on_hover_text(tr("Threads that paint, bake and export. 0 uses every CPU thread. Applies on restart.")); + .on_hover_text(tr("Threads that paint, bake and export. Applies on restart.")); + if slider.changed() { + p.work_threads = work_threads_stored(threads, available_cores); + } + cores_in_total(ui, available_cores); }); row(ui, tr("Cores kept for the UI"), |ui, label| { - ui.add(egui::DragValue::new(&mut p.reserved_cores).range(0..=available_cores)).labelled_by(label); + ui.add(egui::Slider::new(&mut p.reserved_cores, 0..=available_cores).step_by(1.0)).labelled_by(label); + cores_in_total(ui, available_cores); }); row(ui, tr("Max RAM while saving"), |ui, label| { - ui.add(egui::DragValue::new(&mut p.save_ram_percent).range(1..=100).suffix(" %")).labelled_by(label); + ui.add(egui::Slider::new(&mut p.save_ram_percent, 0..=100).step_by(1.0).suffix(" %")).labelled_by(label); let budget_bytes = texturecraft_engine::formats::save_ram_budget(available_ram_bytes, p.save_ram_percent); ui.label(format!("≈ {:.2} GiB", budget_bytes as f64 / (1_u64 << 30) as f64)); }); @@ -528,10 +547,11 @@ fn general( .labelled_by(label) .on_hover_text(tr("Maximum decompressed project data. Increase this limit to open larger projects.")); }); - #[cfg(not(target_arch = "wasm32"))] - { - note(ui, tr("Saving uses the other cores and at most this share of the free RAM. At least one core always works.")); - } + row(ui, tr("Recent projects limit"), |ui, label| { + ui.add(egui::DragValue::new(&mut p.recent_projects_limit).range(0..=MAX_RECENT_PROJECTS)) + .labelled_by(label) + .on_hover_text(tr("Number of recent projects to remember. 0 disables recent-project history.")); + }); #[cfg(not(target_arch = "wasm32"))] { @@ -539,38 +559,9 @@ fn general( row(ui, tr("Autosave every"), |ui, label| { ui.add(egui::DragValue::new(&mut p.autosave_minutes).range(0..=120).suffix(format!(" {}", tr("min")))).labelled_by(label); }); - note(ui, &trf("0 turns autosave off. Copies go to {folder}", &[("folder", &crate::user_dir("autosave").display())])); - - section(ui, n_("FOLDERS")); - row(ui, tr("Data folder"), |ui, label| { - let default = crate::data_folder("").display().to_string(); - ui.add(egui::TextEdit::singleline(&mut p.data_folder).hint_text(default).desired_width(CONTROL_WIDTH - 30.0)).labelled_by(label); - if ui.button("...").on_hover_text(tr("Choose the data folder")).clicked() { - *pick = Some(SettingsFolder::DataFolder); - } - }); - for (label, dir) in [(tr("Smart materials"), crate::library_dir()), (tr("UI layouts"), crate::user_dir("layouts"))] { - row(ui, label, |ui, _| ui.label(RichText::new(dir.display().to_string()).small().color(tk.text_dim))); - } - note( - ui, - tr( - "Autosaves, smart materials, presets, templates and UI layouts go to the data folder. A new folder applies on restart; files already saved stay where they are.", - ), - ); } } -/// A small dim note under a section's rows. -#[cfg(not(target_arch = "wasm32"))] -fn note(ui: &mut Ui, text: &str) { - let tk = Tokens::get(ui.ctx()); - ui.horizontal(|ui| { - ui.add_space(12.0); - ui.add(egui::Label::new(RichText::new(text).small().color(tk.text_dim)).wrap()); - }); -} - /// The built-in library locations as (name, path): the user's assets in the data folder, the /// assets built into TextureCraft, and the font folders text alphas read. pub fn built_in_locations() -> Vec<(String, String)> { @@ -797,6 +788,16 @@ mod tests { assert_eq!(app.next_autosave, 70.0, "an unchanged interval keeps the deadline"); } + #[test] + fn max_cpu_threads_shows_every_thread_at_the_slider_end_and_keeps_it_as_every_thread() { + let cores = 8; + + assert_eq!(work_threads_shown(0, cores), cores, "every thread is the slider's end"); + assert_eq!(work_threads_shown(64, cores), cores, "a larger machine's choice stays inside this one"); + assert_eq!(work_threads_stored(cores, cores), 0, "the end follows any machine's core count"); + assert_eq!(work_threads_stored(work_threads_shown(3, cores), cores), 3); + } + #[test] fn a_folder_answer_cannot_edit_a_reopened_settings_window() { let session = texturecraft_engine::Session::closed().unwrap(); diff --git a/crates/ui-egui/src/state.rs b/crates/ui-egui/src/state.rs index 0c767e1b..9d97f54d 100644 --- a/crates/ui-egui/src/state.rs +++ b/crates/ui-egui/src/state.rs @@ -187,6 +187,22 @@ pub struct Prefs { /// The plain background of the 3D and 2D views at Environment Opacity 0 (Settings > General > /// Background color): the color at the top and at the bottom, linear RGB. pub background: [[f32; 3]; 2], + /// The 3D view draws the X, Y and Z axes in its corner. + pub show_world_axes: bool, + /// Settings > General > Show keyboard helper. Stored only: TextureCraft has no keyboard helper yet. + pub show_keyboard_helper: bool, + /// Settings > General > Only display the selected material when painting. Stored only: the + /// views always show every texture set. + pub only_selected_material_when_painting: bool, + /// Settings > Baking options > Save preprocessed scene files. Stored only: bakes keep no + /// preprocessed scene files. + pub save_preprocessed_scene_files: bool, + /// Settings > Baking options > Enable live preview baking process. Stored only: the live bake + /// preview always runs. + pub live_preview_baking: bool, + /// Settings > Preview options > Local cache directory (desktop). Empty or relative: the + /// system's temporary folder. Stored only: TextureCraft writes no preview cache yet. + pub local_cache_directory: String, } /// The orbit speed the built-in navigation runs at. @@ -200,7 +216,7 @@ impl Default for Prefs { ui_scale: 1.0, autosave_minutes: 10, recent_projects_limit: 10, - language: "en".into(), + language: crate::i18n::SYSTEM_LANGUAGE.into(), viewport_texture: 0, brightness: crate::theme::Brightness::default(), accent: crate::theme::Accent::default(), @@ -218,6 +234,12 @@ impl Default for Prefs { gpu_raytracing: true, libraries: Vec::new(), background: texturecraft_render::DEFAULT_BACKGROUND, + show_world_axes: true, + show_keyboard_helper: true, + only_selected_material_when_painting: false, + save_preprocessed_scene_files: true, + live_preview_baking: true, + local_cache_directory: String::new(), } } } diff --git a/crates/ui-egui/src/viewport.rs b/crates/ui-egui/src/viewport.rs index 3c5a3d7e..7a83ccf6 100644 --- a/crates/ui-egui/src/viewport.rs +++ b/crates/ui-egui/src/viewport.rs @@ -1101,7 +1101,9 @@ fn view_3d(app: &mut TextureCraftApp, ui: &mut Ui, rect: Rect, sync: &mut Pendin solo_notice(app, ui, rect); view_header(app, ui, rect, "v3d"); mask_view_badge(app, ui, rect); - axis_gizmo(ui, rect, app, None); + if app.ui.prefs.show_world_axes { + axis_gizmo(ui, rect, app, None); + } crate::nav_buttons::show(app, ui, rect, crate::nav_buttons::NavView::Scene); } diff --git a/crates/ui-egui/tests/it/settings_window.rs b/crates/ui-egui/tests/it/settings_window.rs index 4e8508b1..7ca014c9 100644 --- a/crates/ui-egui/tests/it/settings_window.rs +++ b/crates/ui-egui/tests/it/settings_window.rs @@ -4,8 +4,10 @@ use egui::{Event, Key, Modifiers, Role}; use egui_kittest::Harness; use egui_kittest::kittest::{NodeT, Queryable}; use texturecraft_engine::Session; -use texturecraft_ui_egui::settings_window::{DEFAULT_LIBRARY_NOTE, GPU_RAYTRACING_UNAVAILABLE, PROJECT_OPEN_NOTE, SHORTCUT_ERRORS, SettingsPage}; -use texturecraft_ui_egui::state::{LibraryLocation, UiState}; +use texturecraft_ui_egui::settings_window::{ + DEFAULT_LIBRARY_NOTE, GPU_RAYTRACING_UNAVAILABLE, PROJECT_OPEN_NOTE, SHORTCUT_ERRORS, SettingsPage, gpu_raytracing_check, +}; +use texturecraft_ui_egui::state::{LibraryLocation, Prefs, UiState}; use texturecraft_ui_egui::unavailable::NOT_AVAILABLE; use texturecraft_ui_egui::{TextureCraftApp, menus}; @@ -84,47 +86,126 @@ fn the_left_column_switches_between_the_three_pages() { fn the_general_page_starts_at_the_reference_defaults() { let mut h = harness(texturecraft_engine::sample_session(128, 32).unwrap()); open_settings(&mut h); - h.state_mut().ui.windows.settings_draft.as_mut().unwrap().prefs.language = texturecraft_ui_egui::i18n::SYSTEM_LANGUAGE.into(); + + // A reset puts the defaults in the window; the app itself keeps English for the exact-text checks + h.state_mut().ui.windows.settings_draft.as_mut().unwrap().prefs = Prefs::default(); h.run_steps(3); + assert_eq!(h.get_by_role_and_label(Role::ComboBox, "Language").value().as_deref(), Some("Default (System Language)")); - assert_eq!(h.get_by_role_and_label(Role::ComboBox, "Viewport Scaling").value().as_deref(), Some("Auto")); + let scaling = h.get_by_role_and_label(Role::ComboBox, "Viewport Scaling"); + assert_eq!(scaling.value().as_deref(), Some("Auto")); + assert!(!scaling.accesskit_node().is_disabled(), "Viewport Scaling can be opened"); assert_eq!(h.get_by_role_and_label(Role::SpinButton, "Local cache budget (in MB)").accesskit_node().numeric_value(), Some(4000.0)); - for label in [ - "Show keyboard helper", - "Show world axes", - "Use simplified thumbnails (improves performance)", - "Save preprocessed scene files", - "Enable live preview baking process", - "Enable GPU raytracing", - "Hardware support acceleration", - ] { + for label in ["Show keyboard helper", "Show world axes", "Save preprocessed scene files", "Enable live preview baking process"] { + assert!(toggled(&h, label), "{label} is ticked"); + assert!(!h.get_by_label(label).accesskit_node().is_disabled(), "{label} can be changed"); + } + for label in ["Use simplified thumbnails (improves performance)", "Hardware support acceleration"] { assert!(toggled(&h, label), "{label} is ticked"); } - for label in ["Only display the selected material when painting", "CPU"] { - assert!(!toggled(&h, label), "{label} is not ticked"); - } + let only_selected = "Only display the selected material when painting"; + assert!(!toggled(&h, only_selected) && !h.get_by_label(only_selected).accesskit_node().is_disabled()); assert!(h.query_all_by_label("Inverse direction").all(|node| node.accesskit_node().toggled() == Some(egui::accesskit::Toggled::False))); - let prefs = texturecraft_ui_egui::state::Prefs::default(); + let local_cache = h.get_by_role_and_label(Role::TextInput, "Local cache directory"); + assert!(!local_cache.accesskit_node().is_disabled(), "the local cache directory can be edited"); + assert_eq!(texturecraft_ui_egui::local_cache_folder(&Prefs::default().local_cache_directory), std::env::temp_dir()); + + let prefs = Prefs::default(); + assert_eq!(prefs.language, texturecraft_ui_egui::i18n::SYSTEM_LANGUAGE, "a reset follows the system language"); assert_eq!((prefs.rotation_speed, prefs.zoom_speed, prefs.wheel_speed), (2.0, 1.0, 1.0)); } +#[test] +fn the_general_page_keeps_the_reference_sections_and_moves_data_folder_and_recent_projects() { + let mut h = harness(Session::closed().unwrap()); + open_settings(&mut h); + + for gone in ["TEMPORARY FILES", "IRAY HARDWARE", "APPEARANCE", "FOLDERS", "PRIVACY", "Interface scale", "Accent color"] { + assert!(h.query_by_label(gone).is_none(), "{gone} is not on the page"); + } + for hint in ["Saving uses the other cores", "0 turns autosave off", "A new folder applies on restart"] { + assert!(h.query_by_label_contains(hint).is_none(), "the hint \"{hint}\" is gone"); + } + + let top = |h: &Harness<'_, TextureCraftApp>, label: &str| h.get_by_label(label).rect().top(); + let data_folder = h.get_by_role_and_label(Role::TextInput, "Data folder").rect().top(); + assert!(top(&h, "FILES") < data_folder && data_folder < top(&h, "SPARSE VIRTUAL TEXTURE"), "Data folder is in Files"); + let recent = h.get_by_role_and_label(Role::SpinButton, "Recent projects limit").rect().top(); + assert!(top(&h, "RESOURCES") < recent && recent < top(&h, "AUTOSAVE"), "Recent projects limit is in Resources"); + assert!(top(&h, "INTERFACE OPTIONS") < top(&h, "RESOURCES")); +} + +#[test] +fn the_resource_sliders_step_by_one_and_follow_the_arrow_keys() { + let mut h = harness(Session::closed().unwrap()); + open_settings(&mut h); + + let threads = h.get_by_role_and_label(Role::Slider, "Max CPU threads for work").accesskit_node(); + let cores = threads.max_numeric_value().unwrap(); + assert_eq!(threads.numeric_value(), Some(cores), "every thread works by default"); + assert_eq!(threads.min_numeric_value(), Some(1.0)); + let reserved = h.get_by_role_and_label(Role::Slider, "Cores kept for the UI").accesskit_node(); + assert_eq!((reserved.min_numeric_value(), reserved.max_numeric_value()), (Some(0.0), Some(cores))); + let ram = h.get_by_role_and_label(Role::Slider, "Max RAM while saving").accesskit_node(); + assert_eq!((ram.min_numeric_value(), ram.max_numeric_value()), (Some(0.0), Some(100.0))); + for label in ["Max CPU threads for work", "Cores kept for the UI", "Max RAM while saving"] { + assert_eq!(h.get_by_role_and_label(Role::Slider, label).accesskit_node().numeric_value_step(), Some(1.0), "{label} moves in steps of 1"); + } + assert_eq!(h.query_all_by_label(&format!("{cores} cores in total")).count(), 2, "both core sliders name the total"); + + let ram_percent = |h: &Harness<'_, TextureCraftApp>| h.state().ui.windows.settings_draft.as_ref().unwrap().prefs.save_ram_percent; + let before = ram_percent(&h); + h.get_by_role_and_label(Role::Slider, "Max RAM while saving").focus(); + h.run_steps(2); + press_key(&mut h, Key::ArrowRight); + assert_eq!(ram_percent(&h), before + 1, "the right arrow adds one percent"); + press_key(&mut h, Key::ArrowLeft); + press_key(&mut h, Key::ArrowLeft); + assert_eq!(ram_percent(&h), before - 1, "the left arrow takes one percent"); +} + +#[test] +fn the_enabled_interface_options_answer_the_keyboard() { + let mut h = harness(Session::closed().unwrap()); + open_settings(&mut h); + let draft = |h: &Harness<'_, TextureCraftApp>| h.state().ui.windows.settings_draft.as_ref().unwrap().prefs.clone(); + let before = draft(&h); + + for label in ["Show keyboard helper", "Show world axes", "Only display the selected material when painting"] { + h.get_by_label(label).focus(); + h.run_steps(2); + press_key(&mut h, Key::Space); + } + + let after = draft(&h); + assert_ne!(after.show_keyboard_helper, before.show_keyboard_helper); + assert_ne!(after.show_world_axes, before.show_world_axes); + assert_ne!(after.only_selected_material_when_painting, before.only_selected_material_when_painting); +} + +#[test] +fn the_local_cache_directory_takes_a_folder_and_r_goes_back_to_the_default() { + let mut h = harness(Session::closed().unwrap()); + open_settings(&mut h); + let folder = std::env::temp_dir().join("tc-settings-local-cache").display().to_string(); + let stored = |h: &Harness<'_, TextureCraftApp>| h.state().ui.windows.settings_draft.as_ref().unwrap().prefs.local_cache_directory.clone(); + + type_into(&mut h, "Local cache directory", &folder); + assert_eq!(stored(&h), folder); + + h.query_all_by_label("R").find(|node| !node.accesskit_node().is_disabled()).unwrap().click(); + h.run_steps(3); + assert!(stored(&h).is_empty(), "R goes back to the default folder"); +} + #[test] fn a_control_the_app_lacks_is_disabled_and_says_so_on_hover() { let mut h = harness(texturecraft_engine::sample_session(128, 32).unwrap()); h.ctx.all_styles_mut(|style| style.interaction.tooltip_delay = 0.0); open_settings(&mut h); let away = h.get_by_role_and_label(Role::Tab, "Libraries").rect().center(); - for label in [ - "Show keyboard helper", - "Show world axes", - "Only display the selected material when painting", - "Use simplified thumbnails (improves performance)", - "Save preprocessed scene files", - "Enable live preview baking process", - "Hardware support acceleration", - "CPU", - ] { + for label in ["Use simplified thumbnails (improves performance)", "Hardware support acceleration"] { h.hover_at(away); h.run_steps(3); assert!(h.query_by_label(NOT_AVAILABLE).is_none(), "no hint before hovering {label}"); @@ -139,7 +220,6 @@ fn a_control_the_app_lacks_is_disabled_and_says_so_on_hover() { for step in ["−", "+"] { assert!(h.query_all_by_label(step).any(|node| node.accesskit_node().is_disabled()), "the cache budget's {step} is disabled"); } - assert!(!h.get_by_label("Enable GPU raytracing").accesskit_node().is_disabled(), "GPU raytracing switches bakes to the CPU"); for label in ["Rotation speed", "Zoom speed", "Wheel speed"] { assert!(h.query_by_label(label).is_some(), "{label} is shown"); } @@ -151,7 +231,7 @@ fn cancel_drops_the_changes_and_ok_applies_and_keeps_them() { let before = h.state().ui.prefs.clone(); open_settings(&mut h); h.get_by_role_and_label(Role::SpinButton, "Autosave every").set_value_accesskit(25.0); - click(&mut h, "Enable GPU raytracing"); + click(&mut h, "Show world axes"); h.run_steps(2); assert_eq!(h.state().ui.prefs, before, "edits wait for OK"); click(&mut h, "Cancel"); @@ -165,20 +245,20 @@ fn cancel_drops_the_changes_and_ok_applies_and_keeps_them() { "a new window starts from the settings in use" ); h.get_by_role_and_label(Role::SpinButton, "Autosave every").set_value_accesskit(25.0); - h.get_by_role_and_label(Role::SpinButton, "Max CPU threads for work").set_value_accesskit(1.0); + h.get_by_role_and_label(Role::Slider, "Max CPU threads for work").set_value_accesskit(1.0); h.get_by_role_and_label(Role::SpinButton, "Max project size on open").set_value_accesskit(12.0); h.run_steps(2); h.query_all_by_label("Inverse direction").next().unwrap().scroll_to_me(); h.run_steps(3); h.query_all_by_label("Inverse direction").next().unwrap().click(); h.run_steps(2); - click(&mut h, "Enable GPU raytracing"); + click(&mut h, "Show world axes"); click(&mut h, "OK"); let prefs = h.state().ui.prefs.clone(); assert!(!h.state().ui.windows.settings, "OK closes the window"); assert_eq!((prefs.autosave_minutes, prefs.work_threads, prefs.project_open_limit_gib), (25, 1, 12)); - assert!(prefs.zoom_inverse && !prefs.wheel_inverse && !prefs.gpu_raytracing); + assert!(prefs.zoom_inverse && !prefs.wheel_inverse && !prefs.show_world_axes); assert!(prefs.drag_zoom_scale() < 0.0, "inverted zoom runs the other way"); let mut storage = MemoryStorage::default(); @@ -434,16 +514,22 @@ fn the_libraries_page_hides_the_add_row_with_a_project_open_and_explains_the_def } #[test] -fn the_baking_options_say_when_there_is_no_gpu_to_trace_on() { - // The condition, with and without an adapter (the harness's own adapter is not under test) +fn gpu_raytracing_is_on_and_checkable_with_a_gpu_and_off_and_disabled_without() { + let with_gpu = !cfg!(target_arch = "wasm32"); + assert_eq!(gpu_raytracing_check(Some("Some GPU"), true), (with_gpu, with_gpu), "a GPU keeps it on and checkable"); + assert_eq!(gpu_raytracing_check(Some("Some GPU"), false), (with_gpu, false), "a GPU shows the stored choice"); + assert_eq!(gpu_raytracing_check(None, true), (false, false), "without a GPU it is off and disabled"); assert!(texturecraft_ui_egui::settings_window::gpu_note_shown(None)); - assert_eq!(texturecraft_ui_egui::settings_window::gpu_note_shown(Some("Some GPU")), cfg!(target_arch = "wasm32")); - // The page shows the note exactly when the harness has no adapter (the IRAY HARDWARE row says "no GPU") + // The page follows the harness's own adapter, whichever it has let mut h = harness(texturecraft_engine::sample_session(128, 32).unwrap()); open_settings(&mut h); - let no_gpu = h.query_by_label("no GPU").is_some(); - assert_eq!(h.query_by_label(GPU_RAYTRACING_UNAVAILABLE).is_some(), no_gpu, "the note shows with no GPU and only then"); + let supported = h.state().render_state.is_some() && with_gpu; + let check = h.get_by_label("Enable GPU raytracing"); + assert_eq!(!check.accesskit_node().is_disabled(), supported, "it can be changed exactly when there is a GPU"); + assert_eq!(toggled(&h, "Enable GPU raytracing"), supported, "it is on exactly when there is a GPU"); + assert_eq!(h.query_by_label(GPU_RAYTRACING_UNAVAILABLE).is_some(), !supported, "the note shows with no GPU and only then"); + assert!(h.state().ui.prefs.gpu_raytracing, "the stored choice stays for a machine with a GPU"); } #[test] diff --git a/crates/ui-egui/tests/it/shortcut_list.rs b/crates/ui-egui/tests/it/shortcut_list.rs index c603cbde..0be5b044 100644 --- a/crates/ui-egui/tests/it/shortcut_list.rs +++ b/crates/ui-egui/tests/it/shortcut_list.rs @@ -29,7 +29,7 @@ fn no_two_default_shortcuts_are_the_same() { } } for (_, row) in &NOT_AVAILABLE_ACTIONS { - let key = row.default.unwrap(); + let Some(key) = row.default else { continue }; assert!(!seen.contains_key(key), "{} shows {key}, which another item has", row.label); } } @@ -83,3 +83,28 @@ fn a_key_listed_for_a_missing_function_is_reported_as_shared() { assert!(h.query_by_label_contains("One or several errors").is_some(), "Space is Toggle animation's"); assert!(h.get_by_label("OK").accesskit_node().is_disabled()); } + +#[test] +fn the_manipulator_rows_follow_export_textures_in_the_reference_order() { + let mut h = harness(); + let ctx = h.ctx.clone(); + menus::invoke(h.state_mut(), &ctx, "ui.settings"); + h.run_steps(4); + h.get_by_role_and_label(Role::Tab, "Shortcuts").click(); + h.run_steps(4); + + let rows = [ + "Export Textures...", + "Show/Hide manipulator", + "Increase the manipulator size", + "Decrease the manipulator size", + "Cycle through manipulation spaces", + "Toggle warp edition mode", + "Translate tool", + "Rotate tool", + "Reimport mesh", + ]; + let tops: Vec = rows.iter().map(|label| h.get_by_label(label).rect().top()).collect(); + + assert!(tops.windows(2).all(|pair| pair[0] < pair[1]), "{rows:?} run top to bottom: {tops:?}"); +} diff --git a/crates/ui-egui/tests/project_limits.rs b/crates/ui-egui/tests/project_limits.rs index c6c3e34a..69e67067 100644 --- a/crates/ui-egui/tests/project_limits.rs +++ b/crates/ui-egui/tests/project_limits.rs @@ -33,11 +33,11 @@ fn resource_settings_follow_hardware_persist_and_apply_before_control_requests() harness.run_steps(3); let edited = |harness: &Harness<'_, TextureCraftApp>| harness.state().ui.windows.settings_draft.as_ref().unwrap().prefs.clone(); assert_eq!(edited(&harness).reserved_cores, available_cores, "preferences from a larger machine are clamped"); - harness.get_by_role_and_label(egui::Role::SpinButton, "Cores kept for the UI").set_value_accesskit(f64::from(u32::MAX)); + harness.get_by_role_and_label(egui::Role::Slider, "Cores kept for the UI").set_value_accesskit(f64::from(u32::MAX)); harness.run_steps(3); assert_eq!(edited(&harness).reserved_cores, available_cores, "editing cannot exceed this machine's CPU count"); assert!(harness.query_by_label("≈ 8.00 GiB").is_some(), "50% of 16 GiB is shown beside the percentage"); - harness.get_by_role_and_label(egui::Role::SpinButton, "Max RAM while saving").set_value_accesskit(25.0); + harness.get_by_role_and_label(egui::Role::Slider, "Max RAM while saving").set_value_accesskit(25.0); harness.run_steps(3); assert!(harness.query_by_label("≈ 4.00 GiB").is_some(), "the byte estimate follows the edited percentage"); diff --git a/docs/ui-parity.md b/docs/ui-parity.md index 1e45c49d..1bd95040 100644 --- a/docs/ui-parity.md +++ b/docs/ui-parity.md @@ -154,7 +154,7 @@ that closes it back onto the bar; the float is saved with the UI state. | UI-12 | Generator depth and property coverage | **UI + source.** The picker contains seven kinds. Switching to Position, changing Global balance and duplicating the effect worked. Shared global adjustments, resolution and input slots already exist; that does not establish the richer generator/control inventory in [#374](https://github.com/storytold/texturecraft/issues/374) | Audit each generator's inputs, micro-detail behavior and controls against the reference; do not count seven shared implementations as equivalent to its whole catalog | | UI-13 | Narrow workspace readability | **UI.** At 1280 × 800 the app rendered, both views stayed visible and the toolbar exposed scroll arrows. Layer names/types became heavily truncated, the layer toolbar wrapped, and Properties needed scrolling. This was not an input-failure or docking-persistence test | Repeat the editing tasks at smaller sizes, widen/rearrange panels, check full-name tooltips and keyboard access, and retain the layout after restart. Since then: the Layers toolbar stays on one row at 1280 × 800 (its channel box shrinks), and a cut-short layer name or type shows in full on hover. Properties scrolling and restart persistence are unchanged | | UI-14 | Assets panel filters | **UI + source.** The type dropdown lists the reference entries in its order, Fonts and Show all included. Saved searches and Filter by path are separate scrollable panes with a divider that supports pointer and keyboard resizing and saves its position with the UI state ([#640](https://github.com/storytold/texturecraft/issues/640)). Fonts, the built-in saved searches Favorites, 3D Assets and Flattened layers, and the System fonts and User fonts libraries are listed but greyed with "Not available yet" | Give fonts, favorites, 3D assets and flattened layers real assets, then enable those rows and check that each one filters the grid | -| UI-15 | Edit > Settings ([#637](https://github.com/storytold/texturecraft/issues/637)) | **Source + headless UI tests.** The window has the reference's General, Shortcuts and Libraries pages with OK and Cancel, and the General sections in its order (no Privacy section: TextureCraft sends no usage data). Language (with Default (System Language)), the camera rotation, zoom and wheel speeds with Inverse direction, Enable GPU raytracing, the Shortcuts page and adding or removing library locations work. Show keyboard helper, Show world axes, Background color, Only display the selected material when painting, Viewport Scaling, Default UV scale for materials, simplified thumbnails, the other baking options, the preview cache and shader, the temporary cache directory, sparse virtual texture and the IRAY HARDWARE choices are shown disabled with "Not available yet". A location's Default choice is fixed to your_assets. The Shortcuts page has the sections Actions, Mouse shortcuts and Modifiers shortcuts and a Reset all to default button; Delete clears a binding; a shared shortcut shows a warning naming the other action, a warning on the page icon and the footer "One or several errors have been found in Shortcuts settings", and OK stays disabled until it is gone (the mouse and modifier rows are shown disabled, the viewports read those gestures from code). The shortcut list uses the reference's action names, order and default keys ("Open project", "Save as project", "Switch to baking mode" Ctrl+Shift+B, "Switch to edition mode" F9, "Camera projection: Perspective view" F5, "Show entire mesh/path", "Select next camera" `>`, "Select previous camera" `<`, "Viewers layout: 3D/2D" F1 to "Viewers layout: Swap 3D/2D" F4 and so on); Quit keeps Ctrl+Q and the menus keep their own texts. "Show mesh wireframe" is a new bindable command without a key; "Pause Engine Computation" (Shift+Esc) and "Toggle animation" (Space) are listed disabled with "Not available yet". The window reopens on the page it was closed on. With a project open the Libraries page hides the add row and shows "Library locations can't be added/removed when a project is opened."; the default library's "−" says "Cannot remove the default library.". "GPU raytracing not available for your hardware." shows under the Baking options when there is no GPU. TextureCraft's own settings (appearance, viewport textures, resources, autosave, folders) follow the reference sections | Run the window in the native app; wire each disabled control as its function lands | +| UI-15 | Edit > Settings ([#637](https://github.com/storytold/texturecraft/issues/637)) | **Source + headless UI tests.** The window has the reference's General, Shortcuts and Libraries pages with OK and Cancel, and the General sections in its order (no Privacy section: TextureCraft sends no usage data). Language (Default (System Language) by default and after a reset), the camera rotation, zoom and wheel speeds with Inverse direction, Show world axes (the 3D view's X, Y and Z corner), the Shortcuts page and adding or removing library locations work. Enable GPU raytracing is on and can be changed when there is a GPU, and off and disabled without one ([#823](https://github.com/storytold/texturecraft/issues/823)). Show keyboard helper and Save preprocessed scene files (on), Only display the selected material when painting (off), Enable live preview baking process (on), Viewport Scaling (only Auto) and the Local cache directory (empty is the system's temporary folder; R goes back to it) can be changed and are kept, but have no effect yet. Default UV scale for materials, simplified thumbnails, the preview cache budget and shader, the Files cache directory and sparse virtual texture are shown disabled with "Not available yet". There is no IRAY HARDWARE section. A location's Default choice is fixed to your_assets. The Shortcuts page has the sections Actions, Mouse shortcuts and Modifiers shortcuts and a Reset all to default button; Delete clears a binding; a shared shortcut shows a warning naming the other action, a warning on the page icon and the footer "One or several errors have been found in Shortcuts settings", and OK stays disabled until it is gone (the mouse and modifier rows are shown disabled, the viewports read those gestures from code). The shortcut list uses the reference's action names, order and default keys ("Open project", "Show/Hide manipulator" Q to "Rotate tool" E after "Export Textures...", "Save as project", "Switch to baking mode" Ctrl+Shift+B, "Switch to edition mode" F9, "Camera projection: Perspective view" F5, "Show entire mesh/path", "Select next camera" `>`, "Select previous camera" `<`, "Viewers layout: 3D/2D" F1 to "Viewers layout: Swap 3D/2D" F4 and so on); Quit keeps Ctrl+Q and the menus keep their own texts. "Show mesh wireframe" is a new bindable command without a key; "Show/Hide manipulator", "Increase the manipulator size", "Decrease the manipulator size", "Cycle through manipulation spaces", "Toggle warp edition mode", "Translate tool", "Rotate tool", "Pause Engine Computation" (Shift+Esc) and "Toggle animation" (Space) are listed disabled with "Not available yet". The window reopens on the page it was closed on. With a project open the Libraries page hides the add row and shows "Library locations can't be added/removed when a project is opened."; the default library's "−" says "Cannot remove the default library.". "GPU raytracing not available for your hardware." shows under the Baking options when there is no GPU. The reference's TEMPORARY FILES section is called FILES and also holds the Data folder. TextureCraft's own settings follow the reference sections: VIEWPORT (texture resolution), RESOURCES (Max CPU threads for work, default every thread, and Cores kept for the UI as sliders in steps of 1 with the core count beside them, Max RAM while saving as a 0-100% slider, Max project size on open, Recent projects limit) and AUTOSAVE. There is no appearance, folders or analytics section: interface scale, brightness, accent colour and the system title bar stay in the saved settings and `ui.set` | Run the window in the native app; wire each disabled control as its function lands | Bake workflow (issue [#651](https://github.com/storytold/texturecraft/issues/651)): Mesh Map Bakers has a Presets menu (save, load, delete named bake settings; Apply to All Texture Sets) and a finished