diff --git a/crates/ui-egui/src/shelf_panes.rs b/crates/ui-egui/src/shelf_panes.rs index b643d21f..d9480d70 100644 --- a/crates/ui-egui/src/shelf_panes.rs +++ b/crates/ui-egui/src/shelf_panes.rs @@ -5,7 +5,7 @@ use egui_phosphor::regular as ic; use serde::{Deserialize, Serialize}; use crate::TextureCraftApp; -use crate::i18n::tr; +use crate::i18n::{n_, tr}; use crate::saved_search::SavedSearch; use crate::shelf::TABS; use crate::theme::Tokens; @@ -14,8 +14,16 @@ use crate::widgets::icon_button; /// The panes' column width as a fraction of the panel, and its least width in points const COLUMN_FRACTION: f32 = 0.45; const COLUMN_MIN_WIDTH: f32 = 110.0; -/// Maximum share of the column used by saved searches while both panes are open -const SAVED_SEARCHES_HEIGHT_FRACTION: f32 = 0.45; +/// The splitter's height between the two panes in points +const SPLITTER_HEIGHT: f32 = 6.0; +/// The least height either pane keeps while the splitter moves, in points +const PANE_MIN_HEIGHT: f32 = 40.0; +/// The hint on rows whose function TextureCraft lacks +pub(crate) const NOT_AVAILABLE: &str = n_("Not available yet"); +/// The reference's built-in saved searches after "All", shown greyed until they work +const BUILT_IN_SEARCHES: [&str; 3] = [n_("Favorites"), n_("3D Assets"), n_("Flattened layers")]; +/// The reference's font libraries after the asset libraries, shown greyed until they work +const FONT_LIBRARIES: [&str; 2] = [n_("System fonts"), n_("User fonts")]; /// The pane header's caption size in points const HEADER_SIZE: f32 = 10.0; @@ -45,20 +53,60 @@ pub(crate) fn column_width(app: &TextureCraftApp, width: f32) -> Option { (panes.saved_searches || panes.filter_by_path).then(|| (width * COLUMN_FRACTION).max(COLUMN_MIN_WIDTH).min(width)) } -/// The open panes, top to bottom; the tree shows `paths`, or `applicable` while it hides folders with nothing matching +/// The open panes, top to bottom, with a splitter between them; the tree shows `paths`, or `applicable` while it hides folders with nothing matching pub(crate) fn column(app: &mut TextureCraftApp, ui: &mut Ui, paths: &[Vec], applicable: &[Vec]) { // Names past the narrow column end in "…" rather than breaking mid-word ui.style_mut().wrap_mode = Some(egui::TextWrapMode::Truncate); - if app.ui.shelf_panes.saved_searches { - saved_searches(app, ui); - } - if app.ui.shelf_panes.filter_by_path { - if app.ui.shelf_panes.saved_searches { - ui.separator(); + let shown = if app.ui.shelf_panes.hide_non_applicable { applicable } else { paths }; + let panes = &app.ui.shelf_panes; + if !(panes.saved_searches && panes.filter_by_path) { + // One pane open takes the whole column + if panes.saved_searches { + saved_searches(app, ui); + } else if panes.filter_by_path { + filter_by_path(app, ui, shown); } - let shown = if app.ui.shelf_panes.hide_non_applicable { applicable } else { paths }; - filter_by_path(app, ui, shown); + return; } + + let rect = ui.available_rect_before_wrap(); + let splitter = splitter(app, ui, rect); + let top = egui::Rect::from_min_max(rect.min, egui::pos2(rect.right(), splitter.top())); + let bottom = egui::Rect::from_min_max(egui::pos2(rect.left(), splitter.bottom()), rect.max); + ui.scope_builder(egui::UiBuilder::new().max_rect(top), |ui| { + ui.set_clip_rect(top.intersect(ui.clip_rect())); + saved_searches(app, ui); + }); + ui.scope_builder(egui::UiBuilder::new().max_rect(bottom), |ui| { + ui.set_clip_rect(bottom.intersect(ui.clip_rect())); + filter_by_path(app, ui, shown); + }); + ui.allocate_rect(rect, egui::Sense::hover()); +} + +/// The splitter between the panes in `rect`: a drag moves it and keeps both panes at least [`PANE_MIN_HEIGHT`] high +fn splitter(app: &mut TextureCraftApp, ui: &mut Ui, rect: egui::Rect) -> egui::Rect { + let usable = (rect.height() - SPLITTER_HEIGHT).max(0.0); + let clamp = |share: f32| { + let least = (PANE_MIN_HEIGHT / usable.max(1.0)).min(0.5); + share.clamp(least, 1.0 - least) + }; + let top_of = |share: f32| rect.top() + usable * clamp(share); + let handle = egui::Rect::from_min_size(egui::pos2(rect.left(), top_of(app.ui.shelf_panes_split)), egui::vec2(rect.width(), SPLITTER_HEIGHT)); + + let response = ui.interact(handle, ui.scope_id().with("shelf_panes_splitter"), egui::Sense::drag()).on_hover_cursor(egui::CursorIcon::ResizeVertical); + if response.dragged() + && let Some(pointer) = response.interact_pointer_pos() + && usable > 0.0 + { + app.ui.shelf_panes_split = clamp((pointer.y - SPLITTER_HEIGHT / 2.0 - rect.top()) / usable); + } + + let handle = handle.translate(egui::vec2(0.0, top_of(app.ui.shelf_panes_split) - handle.top())); + let visuals = ui.visuals(); + let stroke = if response.hovered() || response.dragged() { visuals.widgets.hovered.fg_stroke } else { visuals.widgets.noninteractive.bg_stroke }; + ui.painter().hline(handle.x_range(), handle.center().y, stroke); + handle } /// "All libraries", then each library's folders as a tree; a click shows that folder @@ -77,6 +125,12 @@ fn filter_by_path(app: &mut TextureCraftApp, ui: &mut Ui, paths: &[Vec]) picked = Some(Vec::new()); } folders(ui, paths, &[], &app.ui.shelf_path, &mut picked); + // Nothing is ever in them yet, so hiding non-applicable folders hides them too + if !app.ui.shelf_panes.hide_non_applicable { + for library in FONT_LIBRARIES { + ui.add_enabled(false, egui::Button::selectable(false, tr(library))).on_disabled_hover_text(tr(NOT_AVAILABLE)); + } + } }); if let Some(path) = picked { app.ui.shelf_path = path; @@ -130,16 +184,25 @@ fn saved_searches(app: &mut TextureCraftApp, ui: &mut Ui) { }); let everything = current.filter.is_empty() && current.path.is_empty() && current.tab == crate::shelf_tabs::NO_TYPE; - if ui.selectable_label(everything, tr("All")).clicked() { - crate::shelf_toolbar::reset_query(app); - } - + // "All" and the built-in searches come first, in the list so a short pane scrolls them too + let fixed_rows = 1 + BUILT_IN_SEARCHES.len(); let mut deleted = None; - let max_height = if app.ui.shelf_panes.filter_by_path { ui.available_height() * SAVED_SEARCHES_HEIGHT_FRACTION } else { ui.available_height() }; let row_height = ui.spacing().interact_size.y; - let total_rows = app.ui.shelf_saved_searches.len(); - egui::ScrollArea::vertical().id_salt("shelf_saved_searches").max_height(max_height).show_rows(ui, row_height, total_rows, |ui, visible_rows| { - for i in visible_rows { + let total_rows = fixed_rows + app.ui.shelf_saved_searches.len(); + egui::ScrollArea::vertical().id_salt("shelf_saved_searches").auto_shrink([false, true]).show_rows(ui, row_height, total_rows, |ui, visible_rows| { + for row in visible_rows { + if row == 0 { + if ui.selectable_label(everything, tr("All")).clicked() { + crate::shelf_toolbar::reset_query(app); + } + continue; + } + if let Some(name) = BUILT_IN_SEARCHES.get(row - 1) { + ui.add_enabled(false, egui::Button::selectable(false, tr(name))).on_disabled_hover_text(tr(NOT_AVAILABLE)); + continue; + } + + let i = row - fixed_rows; let Some(saved) = app.ui.shelf_saved_searches.get(i) else { continue }; let same = saved.filter == current.filter && saved.tab == current.tab && saved.path == current.path; diff --git a/crates/ui-egui/src/shelf_tabs.rs b/crates/ui-egui/src/shelf_tabs.rs index 5898a943..919cd245 100644 --- a/crates/ui-egui/src/shelf_tabs.rs +++ b/crates/ui-egui/src/shelf_tabs.rs @@ -3,7 +3,7 @@ use egui::{Ui, vec2}; use crate::TextureCraftApp; -use crate::i18n::tr; +use crate::i18n::{n_, tr}; use crate::shelf::{TABS, Tab}; use crate::widgets::{icon_button, icon_dropdown_button}; @@ -12,6 +12,11 @@ const ICON_GAP: f32 = 2.0; /// The size of the dot that marks the collapsed row's dropdown while a type is picked, in points const FILTER_DOT_RADIUS: f32 = 2.5; +/// The dropdown's entry after the types, greyed until fonts are assets +const FONTS: &str = n_("Fonts"); +/// The dropdown's last entry: no type picked +const SHOW_ALL: &str = n_("Show all"); + /// `app.ui.shelf_tab` while no type is picked: every type shows pub(crate) const NO_TYPE: usize = TABS.len(); @@ -56,13 +61,20 @@ fn collapsed(ui: &mut Ui, picked: &mut usize, counts: &[usize], size: f32) { } egui::Popup::menu(&response).show(|ui| { - for (i, (_, icon, label)) in TABS.iter().enumerate() { + for (i, (_, _, label)) in TABS.iter().enumerate() { let empty = i != *picked && counts.get(i).is_none_or(|count| *count == 0); - if ui.add_enabled(!empty, egui::Button::selectable(i == *picked, format!("{icon} {}", tr(label)))).clicked() { + if ui.add_enabled(!empty, egui::Button::selectable(i == *picked, tr(label))).clicked() { *picked = if i == *picked { NO_TYPE } else { i }; ui.close(); } } + // The reference also lists fonts, which TextureCraft has no assets for yet + ui.add_enabled(false, egui::Button::selectable(false, tr(FONTS))).on_disabled_hover_text(tr(crate::shelf_panes::NOT_AVAILABLE)); + ui.separator(); + if ui.button(tr(SHOW_ALL)).clicked() { + *picked = NO_TYPE; + ui.close(); + } }); } diff --git a/crates/ui-egui/src/state.rs b/crates/ui-egui/src/state.rs index 3b7d7a83..b808a70f 100644 --- a/crates/ui-egui/src/state.rs +++ b/crates/ui-egui/src/state.rs @@ -272,6 +272,11 @@ fn default_export_dir() -> String { fn default_split_ratio() -> f32 { 0.5 } + +/// Saved searches start with this share of the Assets panel's pane column while Filter by path is open too +fn default_shelf_panes_split() -> f32 { + 0.45 +} /// The bake layout's version: saved bake docks from an older one load as `Dock::for_baking` const BAKE_LAYOUT_VERSION: u32 = 2; @@ -321,6 +326,9 @@ pub struct UiState { /// The asset shelf's saved queries, in the order they were saved #[serde(default)] pub shelf_saved_searches: Vec, + /// Saved searches' share of the pane column above Filter by path, set by the splitter between them + #[serde(default = "default_shelf_panes_split")] + pub shelf_panes_split: f32, pub props_tab: PropsTab, #[serde(default)] pub text: TextUi, @@ -419,6 +427,7 @@ impl Default for UiState { shelf_view: ShelfView::default(), shelf_panes: ShelfPanes::default(), shelf_saved_searches: Vec::new(), + shelf_panes_split: default_shelf_panes_split(), props_tab: PropsTab::Brush, text: TextUi::default(), rename: None, diff --git a/crates/ui-egui/tests/it/shelf_panel.rs b/crates/ui-egui/tests/it/shelf_panel.rs index ac6ea916..bea5298e 100644 --- a/crates/ui-egui/tests/it/shelf_panel.rs +++ b/crates/ui-egui/tests/it/shelf_panel.rs @@ -348,3 +348,110 @@ fn procedurals_are_in_the_textures_type() { assert!(harness.query_by_label(ProceduralKind::ALL[0].label()).is_some()); } + +/// The reference's type dropdown, top to bottom +const TYPE_DROPDOWN: [&str; 10] = + ["Materials", "Smart materials", "Smart masks", "Filters", "Brushes", "Alphas", "Textures", "Environments", "Fonts", "Show all"]; + +/// The node labelled `label` added last (a popup's entry is newer than any other with its label) +fn newest<'a>(harness: &'a Harness<'_, TextureCraftApp>, label: &'a str) -> egui_kittest::Node<'a> { + harness.get_all_by_label(label).last().unwrap_or_else(|| panic!("no {label}")) +} + +/// Hover `label` long enough for its tooltip and tell whether the "Not available yet" hint shows +fn shows_not_available(harness: &mut Harness<'_, TextureCraftApp>, label: &str) -> bool { + let center = newest(harness, label).rect().center(); + harness.hover_at(center); + harness.run_steps(30); + harness.query_by_label("Not available yet").is_some() +} + +#[test] +fn the_type_dropdown_lists_the_reference_entries_in_order() { + let mut harness = shelf(NARROW_WINDOW); + button(&harness, "Filter by type").click(); + harness.run_steps(3); + + let tops: Vec = TYPE_DROPDOWN.iter().map(|label| newest(&harness, label).rect().top()).collect(); + assert!(tops.windows(2).all(|pair| pair[0] < pair[1]), "the entries run top to bottom in the reference order: {tops:?}"); + for label in TYPE_DROPDOWN { + let disabled = newest(&harness, label).accesskit_node().is_disabled(); + assert_eq!(disabled, label == "Fonts", "only Fonts is greyed: {label}"); + } + assert!(shows_not_available(&mut harness, "Fonts"), "Fonts explains why it is greyed"); +} + +#[test] +fn show_all_unpicks_the_type() { + let mut harness = shelf(NARROW_WINDOW); + button(&harness, "Filter by type").click(); + harness.run_steps(3); + + newest(&harness, "Show all").click(); + harness.run_steps(3); + + assert_eq!(harness.state().ui.shelf_tab, TYPE_DROPDOWN.len() - 2, "no type is picked"); +} + +#[test] +fn the_panes_list_the_reference_rows_and_grey_the_missing_ones() { + let mut harness = shelf(REFERENCE_WINDOW); + harness.state_mut().ui.shelf_panes.saved_searches = true; + harness.state_mut().ui.shelf_panes.filter_by_path = true; + harness.run_steps(3); + + let saved = ["SAVED SEARCHES", "All", "Favorites", "3D Assets", "Flattened layers"]; + let paths = ["FILTER BY PATH", "All libraries", "Project", "Starter assets", "Your assets", "System fonts", "User fonts"]; + for rows in [&saved[..], &paths[..]] { + let tops: Vec = rows.iter().map(|label| newest(&harness, label).rect().top()).collect(); + assert!(tops.windows(2).all(|pair| pair[0] < pair[1]), "{rows:?} run top to bottom: {tops:?}"); + } + for label in ["Favorites", "3D Assets", "Flattened layers", "System fonts", "User fonts"] { + assert!(newest(&harness, label).accesskit_node().is_disabled(), "{label} is greyed"); + } + for label in ["All", "All libraries", "Project", "Starter assets", "Your assets"] { + assert!(!newest(&harness, label).accesskit_node().is_disabled(), "{label} works"); + } + assert!(shows_not_available(&mut harness, "Flattened layers"), "a greyed saved search explains itself"); + assert!(shows_not_available(&mut harness, "User fonts"), "a greyed library explains itself"); +} + +#[test] +fn the_splitter_resizes_both_panes_and_the_split_is_saved() { + let mut harness = shelf(REFERENCE_WINDOW); + harness.state_mut().ui.shelf_panes.saved_searches = true; + harness.state_mut().ui.shelf_panes.filter_by_path = true; + harness.run_steps(3); + let split = harness.state().ui.shelf_panes_split; + let heading = harness.get_by_label("FILTER BY PATH").rect(); + let save_button = harness.get_by_label("Save the current search").rect().top(); + assert!(heading.top() > save_button, "the path pane sits below the saved searches"); + + // The splitter is the strip right above the path pane's heading + let from = egui::pos2(heading.left() + 20.0, heading.top() - 8.0); + let to = from + egui::vec2(0.0, 120.0); + harness.hover_at(from); + harness.run_steps(1); + harness.event(egui::Event::PointerButton { pos: from, button: egui::PointerButton::Primary, pressed: true, modifiers: egui::Modifiers::NONE }); + harness.run_steps(2); + for step in 1..=4 { + harness.hover_at(from + (to - from) * (step as f32 / 4.0)); + harness.run_steps(1); + } + harness.event(egui::Event::PointerButton { pos: to, button: egui::PointerButton::Primary, pressed: false, modifiers: egui::Modifiers::NONE }); + harness.run_steps(3); + + let moved = harness.get_by_label("FILTER BY PATH").rect(); + assert!((moved.top() - heading.top() - 120.0).abs() < 2.0, "the path pane starts 120 points lower: {heading:?} to {moved:?}"); + assert!(harness.state().ui.shelf_panes_split > split, "saved searches take a larger share"); + assert!(harness.query_by_label("User fonts").is_some(), "the shorter path pane still lists its rows"); + + // The split is part of the saved UI state, and a state saved before the splitter loads the default + let saved = serde_json::to_value(&harness.state().ui).unwrap(); + let restored: texturecraft_ui_egui::state::UiState = serde_json::from_value(saved.clone()).unwrap(); + assert_eq!(restored.shelf_panes_split, harness.state().ui.shelf_panes_split); + let mut older = saved; + assert!(older.as_object_mut().unwrap().remove("shelf_panes_split").is_some(), "the saved state names the split"); + let restored: texturecraft_ui_egui::state::UiState = serde_json::from_value(older).unwrap(); + assert_eq!(restored.shelf_panes_split, split); +} diff --git a/docs/ui-parity.md b/docs/ui-parity.md index e8d6f0bb..746ae939 100644 --- a/docs/ui-parity.md +++ b/docs/ui-parity.md @@ -58,6 +58,7 @@ The relevant implementations are [layer rows, menus and fill/brush editors](../c |---|---|---|---| | 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 | +| 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 two boxes with a splitter whose position is saved 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 | Broader properties/filter work remains tracked in [#433](https://github.com/storytold/texturecraft/issues/433). Its individual rows need checking