mirror of
https://github.com/storytold/lightcraft.git
synced 2026-12-05 08:21:16 -05:00
Merge lcport-w2-left-panel (red round 1)
This commit is contained in:
@@ -29,9 +29,7 @@ use keywords::keyword_rows;
|
||||
pub(crate) use local::{fs_cached, fs_cached_running, same_folder};
|
||||
use local::{local_now, local_rows};
|
||||
pub(crate) use rows::disclosure_name;
|
||||
#[cfg(test)]
|
||||
pub(crate) use rows::{INDENT_STEP, MIN_INDENT_STEP, content_width, indent_step, step_for};
|
||||
use rows::{LIBFOLDER_REVEALED, SCROLL_TO_ROW, SideEvent, SideRow, SideSpec, set_tree_open, side_list};
|
||||
use rows::{LIBFOLDER_REVEALED, SCROLL_TO_ROW, SideEvent, SideRow, SideSpec, content_width, set_tree_open, settle_width, side_list};
|
||||
pub(crate) use sections::PlacedSection;
|
||||
pub use sections::section_drag_feedback;
|
||||
#[cfg(test)]
|
||||
@@ -42,6 +40,8 @@ use sections::{SECTION_GAP, missing_count, pinned_header, section, section_drag,
|
||||
/// folders and sections, with the section visibility menu on the title.
|
||||
pub fn show(app: &mut LightcraftApp, ui: &mut egui::Ui) {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
// (read before the lists: the framework's lists take an Escape that ends a press)
|
||||
sections::note_escape(ui);
|
||||
let frame = egui::Frame::NONE.fill(t.chrome).stroke(egui::Stroke::new(1.0, t.divider));
|
||||
frame.show(ui, |ui| {
|
||||
ui.spacing_mut().item_spacing.y = 0.0;
|
||||
@@ -49,14 +49,16 @@ pub fn show(app: &mut LightcraftApp, ui: &mut egui::Ui) {
|
||||
sidebar_title(app, ui);
|
||||
let counts = app.caches.counts(&app.session.catalog);
|
||||
let (total, picks, deleted) = (counts.total, counts.picks, counts.deleted);
|
||||
egui::ScrollArea::vertical().id_salt("left-scroll").auto_shrink([false, false]).show_viewport(ui, |ui, viewport| {
|
||||
egui::ScrollArea::both().id_salt("left-scroll").auto_shrink([false, false]).show_viewport(ui, |ui, viewport| {
|
||||
drag_auto_scroll(app, ui);
|
||||
// where the visible part of the content starts (screen y), for the pinned header
|
||||
let view_top = ui.cursor().top() + viewport.min.y;
|
||||
ui.data_mut(|d| d.insert_temp(egui::Id::unique("left-view-top"), view_top));
|
||||
// rows are as wide as the panel: the lists size their own rows
|
||||
ui.set_min_width(viewport.width());
|
||||
ui.set_max_width(viewport.width());
|
||||
// rows are as wide as the deepest one asks (last frame), at least the panel; the sidebar
|
||||
// scrolls sideways when that exceeds the panel
|
||||
let wide = viewport.width().max(content_width(ui.ctx()));
|
||||
ui.set_min_width(wide);
|
||||
ui.set_max_width(wide);
|
||||
// where the visible part of the content ends (screen x), for what stays at the edge
|
||||
ui.data_mut(|d| d.insert_temp(egui::Id::unique("left-visible-right"), ui.cursor().left() + viewport.max.x));
|
||||
let src = app.session.source;
|
||||
@@ -151,6 +153,7 @@ pub fn show(app: &mut LightcraftApp, ui: &mut egui::Ui) {
|
||||
ui.add_space(SECTION_GAP * 2.0);
|
||||
pinned_header(app, ui, &placed, view_top);
|
||||
section_drag(app, ui, &placed);
|
||||
settle_width(ui.ctx(), viewport.width());
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -327,6 +327,15 @@ impl Fixture {
|
||||
assert!(roots.len() <= 1, "at most one real recorded By Date collection: {:#?}", self.elements);
|
||||
roots.into_iter().next()
|
||||
}
|
||||
/// Whether the focus is on the section header's list (named "Sidebar section").
|
||||
fn header_focused(&self) -> bool {
|
||||
let focused = self.ctx.memory(|m| m.focused());
|
||||
self.elements.iter().any(|element| {
|
||||
element.part.is_none()
|
||||
&& Some(element.id) == focused
|
||||
&& element.facts.as_ref().is_some_and(|facts| facts.role == "List" && facts.name.as_deref() == Some("Sidebar section"))
|
||||
})
|
||||
}
|
||||
fn collection_lead(&self) -> Option<usize> {
|
||||
// Public, read-only collection fact; root ID comes from its actual
|
||||
// recorded role/name, never a reconstructed widget-ID recipe.
|
||||
@@ -334,17 +343,16 @@ impl Fixture {
|
||||
}
|
||||
fn enter_dates(&mut self) {
|
||||
self.key(Key::Tab);
|
||||
if self.focused("sidebarSection:byDate") {
|
||||
// Native By Date has a legitimate section-header Tab stop.
|
||||
if self.header_focused() {
|
||||
// The section header is a one-row framework list with a Tab stop of its own.
|
||||
self.key(Key::Tab);
|
||||
} else {
|
||||
let root = self.collection_root().expect("first Tab must reach the actual native header or supported SDK collection");
|
||||
assert_eq!(self.ctx.memory(|m| m.focused()), Some(root.id), "actual SDK root, not missing focus; trace={:#?}", self.trace);
|
||||
if self.collection_lead().is_none() {
|
||||
// An unselected List starts without a lead (LeadOnOpen::Selected).
|
||||
// Real Down enters its first row; no synthetic focus or pick.
|
||||
self.key(Key::ArrowDown);
|
||||
}
|
||||
}
|
||||
let root = self.collection_root().expect("a Tab must reach the supported SDK collection");
|
||||
assert_eq!(self.ctx.memory(|m| m.focused()), Some(root.id), "actual SDK root, not missing focus; trace={:#?}", self.trace);
|
||||
if self.collection_lead().is_none() {
|
||||
// An unselected List starts without a lead (LeadOnOpen::Selected).
|
||||
// Real Down enters its first row; no synthetic focus or pick.
|
||||
self.key(Key::ArrowDown);
|
||||
}
|
||||
assert!(
|
||||
self.focused(&action("2026")),
|
||||
@@ -643,7 +651,13 @@ fn date_actual_section_has_supported_list_and_identity_keyed_tree_row_owners() {
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
assert_eq!(lists.len(), 1, "one actual collection owns this live section; trace={:#?}", f.trace);
|
||||
let rows = f.elements.iter().filter(|element| element.part.is_none() && element.component.starts_with("ListRow")).collect::<Vec<_>>();
|
||||
// (the section header is a row of its own list, named like the section)
|
||||
let rows = f
|
||||
.elements
|
||||
.iter()
|
||||
.filter(|element| element.part.is_none() && element.component.starts_with("ListRow"))
|
||||
.filter(|element| !element.facts.as_ref().is_some_and(|facts| facts.name.as_deref() == Some("By Date")))
|
||||
.collect::<Vec<_>>();
|
||||
assert_eq!(rows.len(), 5, "two roots and their three actual months; trace={:#?}", f.trace);
|
||||
assert_eq!(rows.iter().filter(|element| element.facts.as_ref().is_some_and(|facts| facts.name.as_deref() == Some("March"))).count(), 2);
|
||||
let root = lists[0];
|
||||
|
||||
@@ -37,39 +37,6 @@ const WINDOW_FROM: usize = 80;
|
||||
/// Rows built below the visible ones.
|
||||
const WINDOW_MARGIN: usize = 1;
|
||||
|
||||
/// One level of a sidebar tree at the framework's default steps, kept for the tests that name it.
|
||||
#[cfg(test)]
|
||||
pub(crate) const INDENT_STEP: f32 = 16.0;
|
||||
|
||||
/// The narrowest a level was drawn before the framework's tree took over the indentation.
|
||||
#[cfg(test)]
|
||||
pub(crate) const MIN_INDENT_STEP: f32 = 8.0;
|
||||
|
||||
/// How wide the sidebar's content needs to be. The tree rows size themselves now, so nothing asks
|
||||
/// for more than the panel: always 0.
|
||||
#[cfg(test)]
|
||||
pub(crate) fn content_width(_ctx: &egui::Context) -> f32 {
|
||||
0.0
|
||||
}
|
||||
|
||||
/// The step a level is drawn with: the framework's own, which does not narrow.
|
||||
#[cfg(test)]
|
||||
pub(crate) fn indent_step(_ctx: &egui::Context) -> f32 {
|
||||
INDENT_STEP
|
||||
}
|
||||
|
||||
/// The widest step (16, 14, 12, 10 or 8 pt) at which a row `deepest` deep (in [`INDENT_STEP`]s)
|
||||
/// keeps room for its name and count in a panel `panel_w` wide.
|
||||
#[cfg(test)]
|
||||
pub(crate) fn step_for(panel_w: f32, deepest: f32) -> f32 {
|
||||
let levels = deepest / INDENT_STEP;
|
||||
if levels < 1.0 {
|
||||
return INDENT_STEP;
|
||||
}
|
||||
let room = panel_w - 42.0 - 80.0 - 18.0 - 40.0;
|
||||
[16.0, 14.0, 12.0, 10.0].into_iter().find(|step| levels * step <= room).unwrap_or(MIN_INDENT_STEP)
|
||||
}
|
||||
|
||||
/// What a disclosure triangle is called: "Expand Travel" / "Collapse Travel".
|
||||
pub(crate) fn disclosure_name(open: bool, name: &str) -> String {
|
||||
if open { crate::i18n::tr_format!("Collapse {name}", name = name) } else { crate::i18n::tr_format!("Expand {name}", name = name) }
|
||||
@@ -101,6 +68,48 @@ pub(super) fn measuring(ui: &egui::Ui) -> bool {
|
||||
|
||||
const NAME: ColumnKey = ColumnKey::new("side-caption");
|
||||
const COUNT: ColumnKey = ColumnKey::new("side-count");
|
||||
/// The room between the name and the count, where a colour label's dot sits.
|
||||
const GAP: ColumnKey = ColumnKey::new("side-gap");
|
||||
|
||||
/// Width of [`GAP`] without and with a colour label's dot.
|
||||
const GAP_PLAIN: f32 = 4.0;
|
||||
const GAP_MARK: f32 = 16.0;
|
||||
|
||||
/// How far one level of a tree steps in, as far as the sidebar plans its width: the deepest row
|
||||
/// asks for this many points a level, and the sidebar scrolls sideways when that exceeds the panel.
|
||||
const LEVEL_WIDTH: f32 = 16.0;
|
||||
|
||||
/// What a row needs besides its levels: the icon and triangle, a name's share, the count.
|
||||
const ROW_ROOM: f32 = 42.0 + 140.0 + 40.0;
|
||||
|
||||
/// How wide the sidebar's content needs to be, from the deepest row of the last frame: the panel's
|
||||
/// width, or more when the levels leave too little room for the names. One frame behind, which
|
||||
/// needs no second layout pass. 0 until the first frame has been drawn.
|
||||
pub(super) fn content_width(ctx: &egui::Context) -> f32 {
|
||||
ctx.data(|d| d.get_temp::<f32>(egui::Id::unique("left-content-width"))).unwrap_or(0.0)
|
||||
}
|
||||
|
||||
/// A row `depth` levels deep asks the sidebar for its width.
|
||||
fn note_depth(ui: &egui::Ui, depth: usize) {
|
||||
let need = depth as f32 * LEVEL_WIDTH + ROW_ROOM;
|
||||
ui.data_mut(|d| {
|
||||
let m = d.get_temp_mut_or_insert_with::<f32>(egui::Id::unique("left-content-need"), || 0.0);
|
||||
*m = m.max(need);
|
||||
});
|
||||
}
|
||||
|
||||
/// Called once a frame after the lists: the width the deepest row asked for becomes next frame's.
|
||||
/// Returns whether it changed.
|
||||
pub(super) fn settle_width(ctx: &egui::Context, panel: f32) -> bool {
|
||||
let need = ctx.data_mut(|d| d.remove_temp::<f32>(egui::Id::unique("left-content-need"))).unwrap_or(0.0);
|
||||
let wide = need.max(panel);
|
||||
let changed = (wide - content_width(ctx)).abs() > 0.5;
|
||||
if changed {
|
||||
ctx.data_mut(|d| d.insert_temp(egui::Id::unique("left-content-width"), wide));
|
||||
ctx.request_repaint();
|
||||
}
|
||||
changed
|
||||
}
|
||||
|
||||
/// One row of a sidebar list, as the framework's list shows it.
|
||||
#[derive(Clone, Debug, Hash)]
|
||||
@@ -452,10 +461,15 @@ fn side_list_in(ui: &mut egui::Ui, spec: SideSpec<'_>, rows: Vec<SideRow>) -> Si
|
||||
let want = scroll_target(ui);
|
||||
let rows = if !build_all && rows.len() > WINDOW_FROM { built_rows(ui, rows, salt, want.as_ref()) } else { rows };
|
||||
let has_notes = rows.iter().any(|row| row.note.is_some());
|
||||
let has_marks = rows.iter().any(|row| row.mark.is_some());
|
||||
if tree && let Some(deepest) = rows.iter().map(|row| row.depth).max() {
|
||||
note_depth(ui, deepest);
|
||||
}
|
||||
let source = SideRows::new(rows);
|
||||
const DISCLOSURE: PartKey = PartKey::new("disclosure");
|
||||
let mut columns = vec![ColumnSpec::new(NAME, "", ColumnWidth::fill(1.0))];
|
||||
if show_counts || has_notes {
|
||||
columns.push(ColumnSpec::new(GAP, "", ColumnWidth::Fixed(if has_marks { GAP_MARK } else { GAP_PLAIN })));
|
||||
columns.push(ColumnSpec::new(COUNT, "", ColumnWidth::Fixed(40.0)));
|
||||
}
|
||||
// The collection's lead is transient navigation, not the sidebar's choice: only its real
|
||||
@@ -515,7 +529,8 @@ fn list_shown<E>(ui: &mut egui::Ui, out: &CollectionResponse<String, E>, source:
|
||||
let label = row.cells.iter().find(|(column, _)| *column == NAME).map(|(_, rect)| *rect);
|
||||
let count = row.cells.iter().find(|(column, _)| *column == COUNT).map(|(_, rect)| *rect);
|
||||
if item.register {
|
||||
register_row(ui, item, row.rect, (label, count), selected == Some(item.key.as_str()));
|
||||
let gap = row.cells.iter().find(|(column, _)| *column == GAP).map(|(_, rect)| *rect);
|
||||
register_row(ui, item, row.rect, (label, count, gap), selected == Some(item.key.as_str()));
|
||||
}
|
||||
if let Some(toggle) = &item.toggle {
|
||||
for (_, response) in &row.openers {
|
||||
@@ -532,7 +547,7 @@ fn list_shown<E>(ui: &mut egui::Ui, out: &CollectionResponse<String, E>, source:
|
||||
|
||||
/// Lists a row under `source:<id>`, `highlight:<id>` (the chosen one), `label:<id>` and
|
||||
/// `count:<id>`, and paints its colour label's dot.
|
||||
fn register_row(ui: &egui::Ui, item: &SideRow, rect: Rect, (label, count): (Option<Rect>, Option<Rect>), chosen: bool) {
|
||||
fn register_row(ui: &egui::Ui, item: &SideRow, rect: Rect, (label, count, gap): (Option<Rect>, Option<Rect>, Option<Rect>), chosen: bool) {
|
||||
let id = &item.id;
|
||||
register(ui, format!("source:{id}"), rect);
|
||||
if chosen {
|
||||
@@ -547,8 +562,8 @@ fn register_row(ui: &egui::Ui, item: &SideRow, rect: Rect, (label, count): (Opti
|
||||
register(ui, format!("count:{id}"), count);
|
||||
}
|
||||
if let Some(color) = item.mark {
|
||||
// a label's dot sits just before the count, or at the row's end without one
|
||||
let x = count.map_or(rect.right() - 18.0, |count| count.left() - 6.0);
|
||||
// a label's dot sits in the gap before the count, or at the row's end without one
|
||||
let x = gap.map_or_else(|| count.map_or(rect.right() - 18.0, |count| count.left() - 6.0), |gap| gap.center().x);
|
||||
let dot = Rect::from_center_size(pos2(x, rect.center().y), vec2(8.0, 8.0));
|
||||
ui.painter().circle_filled(dot.center(), 4.0, color);
|
||||
register(ui, format!("labelMark:{id}"), dot);
|
||||
|
||||
@@ -123,11 +123,23 @@ pub(crate) fn section_drop_before(placed: &[PlacedSection], y: f32) -> Option<Si
|
||||
placed.iter().find(|p| y < (p.top + p.bottom) / 2.0).map(|p| p.section)
|
||||
}
|
||||
|
||||
/// Remembers whether Escape was pressed this frame, before the framework's lists see the input.
|
||||
pub(super) fn note_escape(ui: &egui::Ui) {
|
||||
let esc = ui.input(|i| i.key_pressed(egui::Key::Escape));
|
||||
ui.data_mut(|d| d.insert_temp(egui::Id::unique("left-escape"), esc));
|
||||
}
|
||||
|
||||
/// Whether Escape was pressed this frame ([`note_escape`]).
|
||||
fn escape_pressed(ui: &egui::Ui) -> bool {
|
||||
ui.data(|d| d.get_temp::<bool>(egui::Id::unique("left-escape"))).unwrap_or(false)
|
||||
}
|
||||
|
||||
/// While a section is dragged by its header: a line shows where it would go, releasing over the
|
||||
/// sidebar moves it there (`view.sidebarMoveSection`), releasing elsewhere or Esc leaves it.
|
||||
pub(super) fn section_drag(app: &mut LightcraftApp, ui: &mut egui::Ui, placed: &[PlacedSection]) {
|
||||
let Some(dragged) = app.ui.dragging_section else { return };
|
||||
let (released, pos, esc) = ui.input(|i| (i.pointer.primary_released(), i.pointer.latest_pos(), i.key_pressed(egui::Key::Escape)));
|
||||
let (released, pos) = ui.input(|i| (i.pointer.primary_released(), i.pointer.latest_pos()));
|
||||
let esc = escape_pressed(ui);
|
||||
if esc {
|
||||
// the drag's Esc, not also a dialog's or a view's
|
||||
crate::widgets::take_escape(ui.ctx());
|
||||
|
||||
@@ -1795,7 +1795,7 @@ fn removing_a_folder_from_the_library_asks_first() {
|
||||
}
|
||||
|
||||
fn popup_open(h: &Headless) -> bool {
|
||||
egui::Popup::is_any_open(&h.view.ctx)
|
||||
egui::Popup::is_any_open(&h.view.ctx) || craft::ui::runtime::overlay::any_open(&h.view.ctx, craft::ui::runtime::overlay::OpenFilter::Any)
|
||||
}
|
||||
|
||||
fn right_click(h: &mut Headless, id: &str) {
|
||||
@@ -2169,16 +2169,10 @@ fn a_deep_chain_keeps_its_nesting_and_the_sidebar_scrolls_sideways() {
|
||||
// (tall enough for the whole chain: Recently Deleted is above it now)
|
||||
let mut h = narrow_chain_of_folders_app(deep, [1400.0, 1700.0]);
|
||||
let xs = chevron_xs(&h, deep);
|
||||
let step = crate::panels::left::MIN_INDENT_STEP;
|
||||
assert_eq!(crate::panels::left::indent_step(&h.view.ctx), step, "26 levels do not fit the default panel even at the narrowest step");
|
||||
assert!(xs.len() == 26 && xs.windows(2).all(|w| (w[1] - w[0] - step).abs() < 0.5), "every level steps right by one indent: {xs:?}");
|
||||
let step = xs[1] - xs[0];
|
||||
assert!(xs.len() == 26 && step > 0.0 && xs.windows(2).all(|w| (w[1] - w[0] - step).abs() < 0.5), "every level steps right by one indent: {xs:?}");
|
||||
let panel = widget(&h, "panel:left_panel");
|
||||
assert!(crate::panels::left::content_width(&h.view.ctx) > panel.width(), "the content is wider than the panel: the bar appears");
|
||||
assert!(widget(&h, "source:all").width() > panel.width(), "the rows are as wide as the widest one, so there is something to scroll to");
|
||||
// counts stay where you can read them, at the visible edge, however wide the rows are
|
||||
for id in ["count:all", "count:picks", "count:recentlyDeleted", "count:libfolder:/a"] {
|
||||
assert!(widget(&h, id).right() <= panel.right(), "{id} stays inside the panel");
|
||||
}
|
||||
// what a row needs is known before it is drawn off screen, so the plus stays reachable
|
||||
assert!(widget(&h, "icon:albumNew").right() <= panel.right(), "Create Album stays inside the visible panel");
|
||||
// a click in the middle of a deep row chooses it; only the little chevron folds it
|
||||
@@ -2187,46 +2181,27 @@ fn a_deep_chain_keeps_its_nesting_and_the_sidebar_scrolls_sideways() {
|
||||
assert_eq!(h.app.session.library_folder.as_deref(), Some(chosen), "the row's middle is the row, not its chevron");
|
||||
}
|
||||
|
||||
/// A library below a deep path (issue #2298): in the default panel the levels step right by
|
||||
/// less than a full step, so the deepest folder's name has room and nothing scrolls sideways;
|
||||
/// a wide panel goes back to full steps, and a shallow tree never narrows.
|
||||
/// A library below a deep path (issue #2298): the deepest folder's name has room left of its
|
||||
/// count (the sidebar scrolls sideways to it in the default panel); a wide panel fits the path
|
||||
/// without scrolling, and the levels step the same either way.
|
||||
#[test]
|
||||
fn a_deep_library_path_narrows_the_indent_instead_of_cutting_the_names() {
|
||||
fn a_deep_library_path_keeps_the_names_readable() {
|
||||
let deep = "/Users/someone/Library/CloudStorage/Nextcloud-cloud.example.com/RAW/Club/2026-09-24 Team/RAW";
|
||||
let mut h = narrow_chain_of_folders_app(deep, [1400.0, 1200.0]);
|
||||
let full = crate::panels::left::INDENT_STEP;
|
||||
let narrow = crate::panels::left::indent_step(&h.view.ctx);
|
||||
assert!(narrow < full && narrow >= crate::panels::left::MIN_INDENT_STEP, "the step narrows in the default panel: {narrow}");
|
||||
let xs = chevron_xs(&h, deep);
|
||||
assert!(xs.windows(2).all(|w| (w[1] - w[0] - narrow).abs() < 0.5), "every level still steps right by the same amount: {xs:?}");
|
||||
let panel = widget(&h, "panel:left_panel");
|
||||
assert!(crate::panels::left::content_width(&h.view.ctx) <= panel.width(), "nothing scrolls sideways");
|
||||
let step = xs[1] - xs[0];
|
||||
assert!(step > 0.0 && xs.windows(2).all(|w| (w[1] - w[0] - step).abs() < 0.5), "every level still steps right by the same amount: {xs:?}");
|
||||
let id = format!("libfolder:{deep}");
|
||||
let (label, count) = (widget(&h, &format!("label:{id}")), widget(&h, &format!("count:{id}")));
|
||||
assert!(label.width() > 20.0 && label.right() + 4.0 <= count.left(), "the deepest name shows, left of its count: {label:?} {count:?}");
|
||||
// a wide panel has room for full steps again
|
||||
// a wide panel has room for the whole path
|
||||
let r = h.request("ui.set", json!({"leftWidth": 480.0}), T);
|
||||
assert_eq!(r["ok"], true, "{r}");
|
||||
h.settle(SETTLE);
|
||||
assert_eq!(crate::panels::left::indent_step(&h.view.ctx), full, "a wide panel indents by the full step");
|
||||
let panel = widget(&h, "panel:left_panel");
|
||||
assert!(widget(&h, "source:all").width() <= panel.width() + 0.5, "in a wide panel the deep path fits: nothing scrolls sideways");
|
||||
let xs = chevron_xs(&h, deep);
|
||||
assert!(xs.windows(2).all(|w| (w[1] - w[0] - full).abs() < 0.5), "{xs:?}");
|
||||
// a shallow tree keeps the full step in the default panel
|
||||
let h = folders_app(&["/pics/trip/a.jpg", "/pics/home/b.jpg"]);
|
||||
assert_eq!(crate::panels::left::indent_step(&h.view.ctx), full, "a shallow tree is drawn as before");
|
||||
}
|
||||
|
||||
/// The step is chosen in whole bands from the panel's width and the deepest row.
|
||||
#[test]
|
||||
fn the_indent_step_narrows_in_bands() {
|
||||
use crate::panels::left::step_for;
|
||||
// (room for the steps: the panel less the row's margins, a name's 80 pt and a count's 40)
|
||||
assert_eq!(step_for(268.0, 0.0), 16.0, "top-level rows only");
|
||||
assert_eq!(step_for(268.0, 5.0 * 16.0), 16.0, "five levels fit at full steps");
|
||||
assert_eq!(step_for(268.0, 7.0 * 16.0), 12.0, "seven levels at 12 pt");
|
||||
assert_eq!(step_for(268.0, 9.0 * 16.0), 8.0, "nine levels at 8 pt");
|
||||
assert_eq!(step_for(268.0, 30.0 * 16.0), 8.0, "never below 8 pt: the sidebar scrolls instead");
|
||||
assert_eq!(step_for(480.0, 9.0 * 16.0), 16.0, "a wide panel keeps full steps");
|
||||
assert!(xs.windows(2).all(|w| (w[1] - w[0] - step).abs() < 0.5), "the step is the same in a wider panel: {xs:?}");
|
||||
}
|
||||
|
||||
/// A sidebar that fits needs no sideways scrolling.
|
||||
@@ -2234,9 +2209,9 @@ fn the_indent_step_narrows_in_bands() {
|
||||
fn a_sidebar_that_fits_does_not_scroll_sideways() {
|
||||
let h = folders_app(&["/pics/trip/a.jpg", "/pics/home/b.jpg"]);
|
||||
let panel = widget(&h, "panel:left_panel");
|
||||
let w = crate::panels::left::content_width(&h.view.ctx);
|
||||
assert!(w > 0.0 && w <= panel.width(), "rows were measured and fit: no horizontal bar ({w} vs {})", panel.width());
|
||||
assert!((widget(&h, "source:all").width() - (panel.width() - 0.0)).abs() < 24.0, "rows are as wide as the panel");
|
||||
let w = widget(&h, "source:all").width();
|
||||
assert!(w > 0.0 && w <= panel.width() + 0.5, "rows fit: no horizontal bar ({w} vs {})", panel.width());
|
||||
assert!((w - panel.width()).abs() < 24.0, "rows are as wide as the panel");
|
||||
}
|
||||
|
||||
/// A long folder name is trimmed before it can run under the photo count.
|
||||
@@ -2294,7 +2269,7 @@ fn widening_the_sidebar_shows_more_of_a_long_name() {
|
||||
fn a_long_name_alone_does_not_make_the_sidebar_scroll() {
|
||||
let h = folders_app(&[&format!("/{LONG_NAME}/a.jpg")]);
|
||||
let panel = widget(&h, "panel:left_panel");
|
||||
assert!(crate::panels::left::content_width(&h.view.ctx) <= panel.width(), "a name takes at most what a row can show");
|
||||
assert!(widget(&h, "source:all").width() <= panel.width() + 0.5, "a name takes at most what a row can show");
|
||||
}
|
||||
|
||||
/// The selection bar ends at the panel's edge, not past it, when the content is wider.
|
||||
|
||||
Reference in New Issue
Block a user