diff --git a/README.md b/README.md index 5ba0538..9c0fa91 100644 --- a/README.md +++ b/README.md @@ -688,18 +688,28 @@ The chevrons, drive, server, lock, speaker and scissors icons are [Lucide](https ## Larger targets -Back, Forward and Up take clicks over 44 × 44 px, and the eject, stop and close buttons over -44 px across their row, however small their icons. For everything else at least 44 px each -way, for a pointer that's hard to aim or a touch screen, put this in +By default, these targets are at least 44 px: + +- Back, Forward and Up, 44 × 44 px; +- the eject, stop and close buttons, 44 px across their row, however small their icons; +- dialog buttons, 44 px tall and at least 44 px wide, and the buttons in the Open, Save and + Open With windows' bottom bars; +- menu items and the folders or servers suggested under the path bar, 44 px tall. A menu or + list of suggestions taller than the window scrolls, with an arrow at each edge it goes on + past. + +Other controls, such as the list's and sidebar's rows, column headings, crumbs, fields and +checkboxes, keep their denser sizes. For those at least 44 px each way too, for a pointer +that's hard to aim or a touch screen, put this in `$XDG_CONFIG_HOME/gannet/config.toml` (usually `~/.config/gannet/config.toml`): ```toml targets = "large" ``` -Rows in the list and the sidebar, column headings, crumbs, menu items, notices and buttons -then grow to at least 44 px, while text and icons stay the size they were. Without it, the -list stays dense. Gannet sees the file change while it's open. Upper or lower case doesn't +Rows in the list and the sidebar, column headings, crumbs, notices, fields, checkboxes and the +other buttons then grow to at least 44 px, while text and icons stay the size they were. +Without it, the list stays dense. Gannet sees the file change while it's open. Upper or lower case doesn't matter; any other value, or no file, is the default. ## Screen readers diff --git a/crates/app/src/a11y.rs b/crates/app/src/a11y.rs index 6395b21..1c0dd41 100644 --- a/crates/app/src/a11y.rs +++ b/crates/app/src/a11y.rs @@ -1082,12 +1082,13 @@ pub struct CaretLine { /// the item picked, or the menu while none is, as when the pointer opened it. fn menu(app: &App) -> Option<(Vec, Modal, u64)> { let m = app.menu.as_ref()?; - let r = app.menu_rect(m); - let (row, top) = (app.menu_row_h(m.items.len()), r.y + app.px(spacing::SPACE_4)); + let (r, sc) = (app.menu_rect(m), app.menu_scroller(m)); let items: Vec = m.items.iter().enumerate().map(|(i, item)| { - let rect = Rect::new(r.x + app.px(spacing::SPACE_4), top + i as i32 * row, r.w - app.px(spacing::SPACE_8), row); - // The shortcut is said after the name, as it's drawn after it. - Node::new(MENU_ITEM0 + i as u64, Role::MenuItem, item.label, rect, MENU).described(item.keys).enabled(item.enabled).selected(i == m.at && item.enabled).doing(click("Choose it", "")) + let at = sc.item(i); + let rect = Rect::new(r.x + app.px(spacing::SPACE_4), at.y, r.w - app.px(spacing::SPACE_8), at.h); + // The shortcut is said after the name, as it's drawn after it. An item a long menu + // has scrolled out of view keeps where it would be, and isn't showing. + Node::new(MENU_ITEM0 + i as u64, Role::MenuItem, item.label, rect, MENU).described(item.keys).enabled(item.enabled).selected(i == m.at && item.enabled).showing(sc.shows(i)).doing(click("Choose it", "")) }) .collect(); let picked = m.items.get(m.at).filter(|i| i.enabled).map_or(MENU, |_| MENU_ITEM0 + m.at as u64); @@ -1315,13 +1316,15 @@ fn sidebar(app: &App, l: &Layout, mut places: Vec) -> (Vec, Vec /// each one in it, with the one picked by Up, Down or Tab selected. Picking one puts it in the /// field, which is what a screen reader hears; the list says what else there is. fn suggestions(app: &mut App) -> Vec { - let Some((r, row)) = app.suggestions_rect() else { return Vec::new() }; + let Some((r, _)) = app.suggestions_rect() else { return Vec::new() }; + let Some(sc) = app.suggest_scroller() else { return Vec::new() }; let Some(s) = app.suggest.as_ref() else { return Vec::new() }; let action = if s.folders { "Go to it" } else { "Connect to it" }; + // One scrolled out of view keeps where it would be, and isn't showing. let items: Vec = (0..s.items.len()) .map(|i| { - let rect = Rect::new(r.x, r.y + app.px(spacing::SPACE_4) + i as i32 * row, r.w, row); - Node::new(SUGGESTION0 + i as u64, Role::ListItem, s.label(i).to_string(), rect, SUGGESTIONS).selected(s.at == Some(i)).showing(rect.bottom() <= r.bottom()).doing(click(action, "")) + let rect = sc.item(i); + Node::new(SUGGESTION0 + i as u64, Role::ListItem, s.label(i).to_string(), rect, SUGGESTIONS).selected(s.at == Some(i)).showing(sc.shows(i)).doing(click(action, "")) }) .collect(); let list = if s.folders { diff --git a/crates/app/src/app.rs b/crates/app/src/app.rs index 4c0abac..54991ca 100644 --- a/crates/app/src/app.rs +++ b/crates/app/src/app.rs @@ -373,6 +373,9 @@ pub enum Hit { FormatKind(usize), /// A recent server offered under the path bar. Suggestion(usize), + /// Inside a menu or the suggestions, off any item: the padding, a cue saying there's more, + /// or the line saying how many more folders. A click there does nothing, and closes nothing. + Popup, PreviewBody, /// A chooser's bar: its name field, file-type list and buttons. ChooserName, @@ -597,6 +600,83 @@ pub struct Menu { pub x: i32, pub y: i32, pub at: usize, + /// How far a menu taller than the window is scrolled, in device pixels. It's held to what + /// the menu can scroll where it's used ([`App::menu_scroll`]), so a resize can't strand it. + pub scroll: i32, +} + +/// A column of rows of one height in a view that can be shorter than all of them: a menu, or +/// the path's suggestions. Taller than its view, it scrolls, with a cue at each edge it goes +/// on past that covers the row under it there. +#[derive(Clone, Copy, Debug, PartialEq)] +pub struct Scroller { + /// Where the rows show. + pub view: Rect, + pub row: i32, + pub n: usize, + /// How far it's scrolled, in device pixels, held to how far it can be. + pub scroll: i32, + /// A cue's height. + pub cue: i32, +} + +impl Scroller { + pub fn new(view: Rect, row: i32, n: usize, scroll: i32, cue: i32) -> Self { + let mut s = Scroller { view, row: row.max(1), n, scroll: 0, cue }; + s.scroll = scroll.clamp(0, s.most()); + s + } + + /// How far it can scroll: none when every row shows. + pub fn most(&self) -> i32 { + (self.row * self.n as i32 - self.view.h).max(0) + } + + /// Where row `i` is, across the view's width: above or below it when scrolled out of it. + pub fn item(&self, i: usize) -> Rect { + Rect::new(self.view.x, self.view.y + i as i32 * self.row - self.scroll, self.view.w, self.row) + } + + /// The cues showing, above and below. + pub fn cues(&self) -> (Option, Option) { + let v = self.view; + ((self.scroll > 0).then(|| Rect::new(v.x, v.y, v.w, self.cue)), (self.scroll < self.most()).then(|| Rect::new(v.x, v.bottom() - self.cue, v.w, self.cue))) + } + + /// Whether any of row `i` shows, clear of the cues. + pub fn shows(&self, i: usize) -> bool { + let (above, below) = self.cues(); + let (top, bottom) = (above.map_or(self.view.y, |c| c.bottom()), below.map_or(self.view.bottom(), |c| c.y)); + let r = self.item(i); + i < self.n && r.y < bottom && r.bottom() > top + } + + /// The row at a point, if one shows there and isn't under a cue. + pub fn at(&self, x: i32, y: i32) -> Option { + let (above, below) = self.cues(); + if !self.view.contains(x, y) || above.is_some_and(|c| c.contains(x, y)) || below.is_some_and(|c| c.contains(x, y)) { + return None; + } + let i = ((y - self.view.y + self.scroll) / self.row) as usize; + (i < self.n).then_some(i) + } + + /// The scroll that shows row `i` whole, clear of the cues, moving as little as it can. The + /// first row shows with no cue above it, and the last with none below. + pub fn reveal(&self, i: usize) -> i32 { + if i >= self.n { + return self.scroll; + } + let (n, i) = (self.n as i32, i as i32); + let top = i * self.row - if i > 0 { self.cue } else { 0 }; + let bottom = (i + 1) * self.row + if i < n - 1 { self.cue } else { 0 } - self.view.h; + (if self.scroll > top { top } else if self.scroll < bottom { bottom } else { self.scroll }).clamp(0, self.most()) + } + + /// The scroll after the wheel moves it: three rows a line, as the list scrolls. + pub fn wheel(&self, lines: f64, pixels: f64, scale: f64) -> i32 { + ((self.scroll as f64 + lines * 3.0 * self.row as f64 + pixels * scale).round() as i32).clamp(0, self.most()) + } } /// Which text field has the keyboard, if any. @@ -726,6 +806,9 @@ pub struct App { recent_servers: Vec, /// The recent servers or folders offered under the path bar for what's typed in it. pub suggest: Option, + /// How far the suggestions are scrolled, in device pixels, when they're taller than the + /// window: back to the top whenever what's offered changes. + pub suggest_scroll: i32, /// The folders in the parent typed in the path bar, once listed. Only the last parent's are /// kept, and only while the path bar is open. path_folders: Option>, @@ -1007,6 +1090,7 @@ impl App { servers_file: None, recent_servers: Vec::new(), suggest: None, + suggest_scroll: 0, path_folders: None, path_wanted: None, path_listing: false, @@ -1144,6 +1228,11 @@ impl App { if rescale && self.scale > 0.0 { self.scroll *= scale / self.scale; self.side_scroll *= scale / self.scale; + let by = scale / self.scale; + if let Some(m) = self.menu.as_mut() { + m.scroll = (m.scroll as f64 * by).round() as i32; + } + self.suggest_scroll = (self.suggest_scroll as f64 * by).round() as i32; } self.scale = scale; self.text.set_size(crate::text::UI_PX * scale as f32, crate::text::UI_HINTED && scale < 1.5); @@ -1152,6 +1241,9 @@ impl App { } self.clamp_scroll(); self.clamp_side_scroll(); + // A menu or the suggestions keep the item picked in view, at the new size. + self.menu_reveal(); + self.suggest_reveal(); self.stats_range = (0, 0); self.request_stats(); self.preview_rescale(); @@ -1162,7 +1254,7 @@ impl App { let (w, h) = (self.w, self.h); let bar = self.px(size::TOOLBAR); // A chooser's bar holds a name field and buttons, with room around them. - let status = if self.chooser.is_some() { self.px(size::CHOOSER_BAR) - self.px(size::BAR_CONTROL) + self.target(size::BAR_CONTROL) } else { self.px(size::STATUS_BAR) }; + let status = if self.chooser.is_some() { self.px(size::CHOOSER_BAR) - self.px(size::BAR_CONTROL) + self.target(size::BUTTON_HEIGHT) } else { self.px(size::STATUS_BAR) }; let side = self.px(size::SIDEBAR).min(w / 3); let header = self.target(size::HEADER); let notice_h = self.panel_row_h() * self.panel_rows() as i32; @@ -2282,6 +2374,8 @@ impl App { Act::Focus(id) => { let Some(i) = item(id) else { return }; m.at = i; + // Scrolled to, as the keyboard would, so it's on screen where it's read. + self.menu_reveal(); self.invalidate_all(); } _ => {} @@ -3909,8 +4003,8 @@ impl App { let mut x = r.right() - self.px(spacing::SPACE_12); let mut out = vec![Rect::default(); buttons.len()]; for (i, b) in buttons.iter().enumerate().rev() { - // A short label, like "No", makes a narrow button, so larger targets make it wider. - let w = (self.text.measure(&b.label) as i32 + self.px(spacing::SPACE_12 * 2.0)).max(self.target(0.0)); + // A short label, like "No", makes a narrow button, so it's made a target's width. + let w = (self.text.measure(&b.label) as i32 + self.px(spacing::SPACE_12 * 2.0)).max(self.px(TARGET)); x -= w; out[i] = Rect::new(x, y, w, h); x -= self.px(spacing::SPACE_8); @@ -3918,9 +4012,9 @@ impl App { out } - /// How tall a dialog's buttons are. + /// How tall a dialog's buttons are: a 44 px target, with larger targets on or not. pub fn dialog_button_h(&self) -> i32 { - self.target(size::CONTROL_HEIGHT) + self.target(size::BUTTON_HEIGHT) } /// The line above a dialog's buttons: "Do the same for the rest", or the passphrase field. @@ -4083,7 +4177,7 @@ impl App { items.push(MenuItem { label: "Format…", keys: "", action: Action::FormatDrive, enabled: !formatting }); } self.drive_menu = Some(v); - self.menu = Some(Menu { items, x, y, at: usize::MAX }); + self.menu = Some(Menu { items, x, y, at: usize::MAX, scroll: 0 }); self.invalidate_all(); } @@ -4413,7 +4507,7 @@ impl App { MenuItem { label: "Disconnect", keys: "", action: Action::Disconnect, enabled: !busy }, ]; self.share_menu = Some(share); - self.menu = Some(Menu { items, x, y, at: usize::MAX }); + self.menu = Some(Menu { items, x, y, at: usize::MAX, scroll: 0 }); self.invalidate_all(); } @@ -4516,6 +4610,7 @@ impl App { }; if new != self.suggest { self.suggest = new; + self.suggest_scroll = 0; self.invalidate_all(); } } @@ -4675,6 +4770,7 @@ impl App { } _ => return false, } + self.suggest_reveal(); self.invalidate_all(); true } @@ -4863,21 +4959,60 @@ impl App { let n = s.items.len() + usize::from(s.more > 0); let bar = self.path_box(); let row = self.target(size::MENU_ROW); - let l = self.layout(); - let h = (row * n as i32 + self.px(spacing::SPACE_8)).min((self.h - bar.bottom() - self.px(spacing::SPACE_4)).max(0)); - Some((Rect::new(bar.x, l.toolbar.bottom() + self.px(spacing::SPACE_2), bar.w.max(self.px(size::SUGGEST_MIN_WIDTH)).min(self.w - bar.x - self.px(spacing::SPACE_8)), h), row)) + let top = self.layout().toolbar.bottom() + self.px(spacing::SPACE_2); + // Taller than the room under the toolbar, it scrolls, and ends a little above the + // window's bottom. + let h = (row * n as i32 + self.px(spacing::SPACE_8)).min((self.h - top - self.px(spacing::SPACE_4)).max(0)); + Some((Rect::new(bar.x, top, bar.w.max(self.px(size::SUGGEST_MIN_WIDTH)).min(self.w - bar.x - self.px(spacing::SPACE_8)), h), row)) + } + + /// The suggestions' rows, the last saying how many more there are if any, in the box + /// inside its padding. + pub fn suggest_scroller(&mut self) -> Option { + let (r, row) = self.suggestions_rect()?; + let s = self.suggest.as_ref()?; + let pad = self.px(spacing::SPACE_4); + let view = Rect::new(r.x, r.y + pad, r.w, (r.h - 2 * pad).max(0)); + Some(Scroller::new(view, row, s.items.len() + usize::from(s.more > 0), self.suggest_scroll, self.px(size::MENU_SCROLL_CUE))) } /// The recent server or folder offered at a point, if any. pub fn suggestion_at(&mut self, x: i32, y: i32) -> Option { - let (r, row) = self.suggestions_rect()?; - if !r.contains(x, y) { - return None; - } - let i = ((y - r.y - self.px(spacing::SPACE_4)).max(0) / row.max(1)) as usize; + let i = self.suggest_scroller()?.at(x, y)?; (i < self.suggest.as_ref()?.items.len()).then_some(i) } + /// Scrolls the suggestions so the one picked shows whole, and holds their scroll to what it + /// can be, as after a resize. + fn suggest_reveal(&mut self) { + let Some(sc) = self.suggest_scroller() else { return }; + let at = self.suggest.as_ref().and_then(|s| s.at).unwrap_or(usize::MAX); + self.suggest_scroll = sc.reveal(at); + } + + /// The wheel over the suggestions scrolls them, if they're taller than the window. + fn suggest_wheel(&mut self, lines: f64, pixels: f64) { + let Some(sc) = self.suggest_scroller() else { return }; + let to = sc.wheel(lines, pixels, self.scale); + if to != sc.scroll { + self.suggest_scroll = to; + let r = self.suggestions_rect().map(|(r, _)| r).unwrap_or_default(); + self.invalidate(r); + // The rows moved under the pointer, so what it hovers changes with them. Inside the + // box, the repaint above already covers both, so only the box is drawn again. + if self.pointer.0 >= 0 { + let h = self.hit(self.pointer.0, self.pointer.1); + let in_box = |h: Hit| matches!(h, Hit::Suggestion(_) | Hit::Popup); + if in_box(h) && (in_box(self.hover) || self.hover == Hit::None) { + self.hover = h; + self.set_cursor(cursor_for(h)); + } else { + self.set_hover(h); + } + } + } + } + // ---- Pins ---- /// Pins are kept in GTK's bookmarks file at `file`, which is read now and whenever @@ -5086,7 +5221,7 @@ impl App { fn open_pin_menu(&mut self, path: PathBuf, x: i32, y: i32) { let items = vec![MenuItem { label: "Open", keys: "", action: Action::OpenPin, enabled: true }, MenuItem { label: "Unpin", keys: "", action: Action::Unpin, enabled: true }]; self.pin_menu = Some(path); - self.menu = Some(Menu { items, x, y, at: usize::MAX }); + self.menu = Some(Menu { items, x, y, at: usize::MAX, scroll: 0 }); self.invalidate_all(); } @@ -5445,7 +5580,7 @@ impl App { } fn open_menu(&mut self, x: i32, y: i32) { - self.menu = Some(Menu { items: self.context_items(), x, y, at: usize::MAX }); + self.menu = Some(Menu { items: self.context_items(), x, y, at: usize::MAX, scroll: 0 }); self.invalidate_all(); } @@ -5454,19 +5589,73 @@ impl App { self.invalidate_all(); } - /// How tall each of a menu's `items` is. With larger targets, a long menu in a short window - /// takes less, down to the default, so all of it shows and every item can be pressed. - pub fn menu_row_h(&self, items: usize) -> i32 { - let fits = (self.h - self.px(spacing::SPACE_8)) / items.max(1) as i32; - self.target(size::MENU_ROW).min(fits).max(self.px(size::MENU_ROW)) + /// How tall a menu's items are: a 44 px target however long the menu, with larger targets + /// on or not. A menu taller than the window scrolls instead. + pub fn menu_row_h(&self) -> i32 { + self.target(size::MENU_ROW) } + /// The menu, at most as tall as the window. pub fn menu_rect(&self, m: &Menu) -> Rect { - let (w, row) = (self.px(size::MENU_WIDTH), self.menu_row_h(m.items.len())); - let h = row * m.items.len() as i32 + self.px(spacing::SPACE_8); + let (w, row) = (self.px(size::MENU_WIDTH), self.menu_row_h()); + let h = (row * m.items.len() as i32 + self.px(spacing::SPACE_8)).min(self.h).max(0); Rect::new(m.x.min(self.w - w).max(0), m.y.min(self.h - h).max(0), w, h) } + /// A menu's items, in its view inside its padding. + pub fn menu_scroller(&self, m: &Menu) -> Scroller { + let (r, pad) = (self.menu_rect(m), self.px(spacing::SPACE_4)); + let view = Rect::new(r.x, r.y + pad, r.w, (r.h - 2 * pad).max(0)); + Scroller::new(view, self.menu_row_h(), m.items.len(), m.scroll, self.px(size::MENU_SCROLL_CUE)) + } + + /// Where a menu's items show: inside its padding. + pub fn menu_view(&self, m: &Menu) -> Rect { + self.menu_scroller(m).view + } + + /// Where item `i` is, across the menu's width: above or below the view when it's scrolled + /// out of it. + pub fn menu_item_rect(&self, m: &Menu, i: usize) -> Rect { + self.menu_scroller(m).item(i) + } + + /// The item at a point, if one shows there and isn't under a cue. + pub fn menu_item_at(&self, m: &Menu, x: i32, y: i32) -> Option { + self.menu_scroller(m).at(x, y) + } + + /// Scrolls the menu so the item picked shows whole, clear of the cues, and holds its scroll + /// to what it can be, as after a resize. + pub(crate) fn menu_reveal(&mut self) { + let Some(m) = self.menu.as_ref() else { return }; + let to = self.menu_scroller(m).reveal(m.at); + if let Some(m) = self.menu.as_mut() { + m.scroll = to; + } + } + + /// The wheel over an open menu scrolls it, if it's taller than the window, and picks the + /// item that comes under the pointer, as moving the pointer would. + fn menu_wheel(&mut self, lines: f64, pixels: f64) { + let Some(m) = self.menu.as_ref() else { return }; + let sc = self.menu_scroller(m); + let to = sc.wheel(lines, pixels, self.scale); + if to == sc.scroll { + return; + } + let (r, (px, py)) = (self.menu_rect(m), self.pointer); + if let Some(m) = self.menu.as_mut() { + m.scroll = to; + } + if let Some(i) = self.menu.as_ref().and_then(|m| self.menu_item_at(m, px, py)) + && let Some(m) = self.menu.as_mut() + { + m.at = i; + } + self.invalidate(r); + } + // ---- Input ---- pub fn input(&mut self, i: Input) { @@ -5527,7 +5716,12 @@ impl App { self.invalidate_all(); } else if self.preview.is_some() { self.preview_scroll(lines, pixels); - } else if self.menu.is_none() && self.layout().sidebar.contains(self.pointer.0, self.pointer.1) && self.scrollbar_visible(Pane::Sidebar) { + } else if self.menu.is_some() { + self.menu_wheel(lines, pixels); + } else if self.suggest_scroller().is_some_and(|sc| sc.most() > 0) && self.suggestions_rect().is_some_and(|(r, _)| r.contains(self.pointer.0, self.pointer.1)) { + // Over suggestions taller than the window, the wheel scrolls them. + self.suggest_wheel(lines, pixels); + } else if self.layout().sidebar.contains(self.pointer.0, self.pointer.1) && self.scrollbar_visible(Pane::Sidebar) { // Over a sidebar that all fits, the wheel goes on scrolling the list. let row = self.place_h() as f64; self.side_scroll_to(self.side_scroll + lines * 3.0 * row + pixels * self.scale); @@ -5791,12 +5985,28 @@ impl App { } fn menu_key(&mut self, sym: u32) { + let Some(m) = self.menu.as_ref() else { return }; + let page = (self.menu_view(m).h / self.menu_row_h().max(1)).max(1) as usize; let Some(menu) = self.menu.as_mut() else { return }; let n = menu.items.len(); match sym { k::KEY_Escape | k::KEY_Menu | k::KEY_F10 => return self.close_menu(), k::KEY_Down => menu.at = next_enabled(&menu.items, menu.at, 1), k::KEY_Up => menu.at = next_enabled(&menu.items, if menu.at == usize::MAX { n } else { menu.at }, n - 1), + k::KEY_Home => menu.at = next_enabled(&menu.items, usize::MAX, 1), + k::KEY_End => menu.at = next_enabled(&menu.items, n, n - 1), + k::KEY_Page_Down | k::KEY_Page_Up => { + // A page is as many items as show, and lands on the nearest one that can be + // pressed, going on that way and then back. It stops at either end. + let from = if menu.at >= n { 0 } else { menu.at }; + let down = sym == k::KEY_Page_Down; + let to = if down { (from + page).min(n - 1) } else { from.saturating_sub(page) }; + let ahead = |i: &usize| menu.items[*i].enabled; + let found = if down { (to..n).find(ahead).or_else(|| (0..to).rev().find(ahead)) } else { (0..=to).rev().find(ahead).or_else(|| (to + 1..n).find(ahead)) }; + if let Some(i) = found { + menu.at = i; + } + } k::KEY_Return | k::KEY_KP_Enter => { if let Some(item) = menu.items.get(menu.at).filter(|i| i.enabled) { let a = item.action; @@ -5807,6 +6017,7 @@ impl App { } _ => return, } + self.menu_reveal(); self.invalidate_all(); } @@ -6177,15 +6388,14 @@ impl App { if let Some(i) = self.suggestion_at(x, y) { return Hit::Suggestion(i); } + if self.suggestions_rect().is_some_and(|(r, _)| r.contains(x, y)) { + return Hit::Popup; + } if let Some(m) = &self.menu { - let r = self.menu_rect(m); - if r.contains(x, y) { - let i = (y - r.y - self.px(spacing::SPACE_4)) / self.menu_row_h(m.items.len()).max(1); - if (i as usize) < m.items.len() && i >= 0 { - return Hit::MenuItem(i as usize); - } + if let Some(i) = self.menu_item_at(m, x, y) { + return Hit::MenuItem(i); } - return Hit::Outside; + return if self.menu_rect(m).contains(x, y) { Hit::Popup } else { Hit::Outside }; } if let Some(h) = self.chooser_hit(x, y) { return h; @@ -6577,6 +6787,11 @@ impl App { self.cancel_file_drag(); let (x, y) = self.pointer; let hit = self.hit(x, y); + // Any button on a menu's or the suggestions' padding or cues does nothing: it doesn't + // close them, leave the field or the sidebar, or open another menu. + if hit == Hit::Popup { + return; + } // A click anywhere but a gone folder's buttons takes the keyboard from them, so Enter // can't press one that's no longer in mind, or no longer there. if !matches!(hit, Hit::Gone(_)) { @@ -6754,7 +6969,7 @@ impl App { self.stop_job(id); } } - Hit::DialogButton(_) | Hit::DialogCheck | Hit::DialogField(_) | Hit::ServerField(_) | Hit::FormatName | Hit::FormatKind(_) | Hit::Suggestion(_) | Hit::PreviewBody | Hit::PinGap(_) => {} + Hit::DialogButton(_) | Hit::DialogCheck | Hit::DialogField(_) | Hit::ServerField(_) | Hit::FormatName | Hit::FormatKind(_) | Hit::Suggestion(_) | Hit::Popup | Hit::PreviewBody | Hit::PinGap(_) => {} Hit::ChooserName | Hit::ChooserFilter | Hit::ChooserAccept | Hit::ChooserCancel => self.chooser_click(hit, x), Hit::Row(row) => { self.chooser_clicked_list(Some(row)); @@ -9220,7 +9435,7 @@ mod tests { let m = r.app.menu.as_ref().unwrap(); let rect = r.app.menu_rect(m); let target = if at == 1 { 0 } else { 1 }; - let y = rect.y + r.app.px(4.0) + target as i32 * r.app.px(28.0) + r.app.px(14.0); + let y = rect.y + r.app.px(4.0) + target as i32 * r.app.px(44.0) + r.app.px(22.0); r.app.input(Input::Move { x: (rect.x + r.app.px(10.0)) as f64, y: y as f64 }); assert_eq!(r.app.menu.as_ref().unwrap().at, target); } @@ -14752,6 +14967,70 @@ mod tests { assert!(picked.selected && picked.name == "d0", "the one picked is selected, by its name"); } + #[test] + fn nine_suggestions_in_a_short_window_keep_44_px_rows_scroll_and_keep_the_pick_in_view() { + let mut r = folders_rig("folders-short"); + for i in 0..20 { + fs::create_dir_all(r.root.join(format!("home/many/d{i}"))).unwrap(); + } + r.app.resized(900, 400, 1.0); + r.type_text("~/many/"); + r.pump_until("listed", |a| a.suggest.is_some()); + let (rect, _) = r.app.suggestions_rect().unwrap(); + let sc = r.app.suggest_scroller().unwrap(); + assert_eq!((sc.row, sc.n), (44, 9), "eight and the count, 44 each"); + assert!(sc.most() > 0 && rect.bottom() <= 400, "taller than the room, so it scrolls: {sc:?} {rect:?}"); + assert!(sc.cues().0.is_none() && sc.cues().1.is_some(), "a cue below at first"); + let in_view = |r: &mut Rig| { + let sc = r.app.suggest_scroller().unwrap(); + let at = r.app.suggest.as_ref().unwrap().at.expect("one picked"); + let i = sc.item(at); + let (above, below) = sc.cues(); + let (top, bottom) = (above.map_or(sc.view.y, |c| c.bottom()), below.map_or(sc.view.bottom(), |c| c.y)); + assert!(i.y >= top && i.bottom() <= bottom, "{at} at {i:?}, {sc:?}"); + assert_eq!(r.app.hit(i.x + 40, i.y + i.h / 2), Hit::Suggestion(at), "and pressed where it shows"); + }; + // Down to the last folder, and back up to the first. + for _ in 0..SUGGESTIONS { + r.key(k::KEY_Down, ""); + in_view(&mut r); + } + assert_eq!(r.app.suggest.as_ref().unwrap().at, Some(SUGGESTIONS - 1)); + let s = snapshot(&mut r).fixed; + assert!(!s.iter().find(|n| n.id == crate::a11y::SUGGESTION0).unwrap().showing, "the first scrolled out of view, not showing"); + for _ in 1..SUGGESTIONS { + r.key(k::KEY_Up, ""); + in_view(&mut r); + } + assert_eq!(r.app.suggest_scroller().unwrap().scroll, 0); + // The wheel over them scrolls them to the end, repainting only their box. + r.app.pointer = (rect.x + 40, rect.y + 60); + r.app.dirty = Rect::default(); + r.app.input(Input::Scroll { lines: 100.0, pixels: 0.0 }); + let sc = r.app.suggest_scroller().unwrap(); + assert_eq!(sc.scroll, sc.most()); + assert_eq!(r.app.dirty, rect); + let (px, py) = r.app.pointer; + let under = r.app.hit(px, py); + assert_eq!(r.app.hover, under, "the hover follows the rows the wheel moved under the pointer"); + assert!(matches!(r.app.hover, Hit::Suggestion(_))); + assert!(sc.cues().0.is_some() && sc.cues().1.is_none()); + // The count, last, shows, and takes no clicks; nor does the cue. + let count = sc.item(SUGGESTIONS); + assert!(count.bottom() <= sc.view.bottom()); + assert_eq!(r.app.hit(count.x + 40, count.y + 10), Hit::Popup); + let cue = sc.cues().0.unwrap(); + assert_eq!(r.app.hit(cue.x + 40, cue.y + 5), Hit::Popup); + r.app.pointer = (cue.x + 40, cue.y + 5); + r.app.button(BTN_LEFT, true); + r.app.button(BTN_LEFT, false); + assert!(r.app.suggest.is_some() && matches!(r.app.edit, Edit::Path(_)), "the list and the field still open"); + // Taller, it all fits, and isn't scrolled. + r.app.resized(900, 1000, 1.0); + let sc = r.app.suggest_scroller().unwrap(); + assert_eq!((sc.most(), sc.scroll, sc.cues()), (0, 0, (None, None))); + } + #[test] fn a_recent_server_can_be_clicked() { let mut r = connect_rig("connect-suggest-click"); @@ -15031,16 +15310,18 @@ mod tests { #[test] fn each_kind_of_target_keeps_its_size_or_takes_44() { - for (large, row, header, place, menu, panel, button, check) in [(false, 26, 28, 30, 28, 30, 30, 24), (true, 44, 44, 44, 44, 44, 44, 44)] { + // Menu items and dialog buttons are 44 either way (ALI-2665), so larger targets don't + // grow them again. + for (large, row, header, place, menu, panel, button, field, check) in [(false, 26, 28, 30, 44, 30, 44, 30, 24), (true, 44, 44, 44, 44, 44, 44, 44, 44)] { let mut r = target_rig(if large { "targets-kinds-large" } else { "targets-kinds" }, 3, large); let l = r.app.layout(); - assert_eq!((l.row_h, l.header.h, r.app.place_h(), r.app.menu_row_h(5), r.app.panel_row_h()), (row, header, place, menu, panel), "large: {large}"); + assert_eq!((l.row_h, l.header.h, r.app.place_h(), r.app.menu_row_h(), r.app.panel_row_h()), (row, header, place, menu, panel), "large: {large}"); assert_eq!(l.list.y, l.header.bottom(), "the list starts under the headings"); // A dialog's buttons and the line above them, and it's tall enough for both. r.app.dialog = Some(Dialog::ConfirmQuit { at: 1 }); let d = r.app.dialog.take().unwrap(); let (rects, plain) = (r.app.dialog_button_rects(&d), r.app.dialog_rect_for(&d)); - assert!(rects.iter().all(|b| b.h == button && b.w >= r.app.target(0.0) && plain.contains(b.x, b.y) && b.bottom() < plain.bottom()), "large: {large}: {rects:?}"); + assert!(rects.iter().all(|b| b.h == button && b.w >= 44 && plain.contains(b.x, b.y) && b.bottom() < plain.bottom()), "large: {large}: {rects:?}"); // One with a line above its buttons, a conflict's or the passphrase's. let (check_r, dialog) = (r.app.dialog_check_rect(), r.app.dialog_rect()); let buttons_y = dialog.bottom() - r.app.px(12.0) - button; @@ -15051,7 +15332,7 @@ mod tests { assert_eq!(plain.h, base_h + (button - 30), "and one with no line above its buttons doesn't grow for one"); // The rename dialog's fields and buttons. let rl = r.app.rename_layout(5); - assert_eq!((rl.find.h, rl.replace.h), (button, button)); + assert_eq!((rl.find.h, rl.replace.h), (field, field)); assert!(rl.list.h >= rl.row_h * 4, "room for four names still: {}", rl.list.h); // The path: no crumb narrower than a target. let crumbs = r.app.crumbs(); @@ -15063,7 +15344,7 @@ mod tests { #[test] fn a_choosers_bar_grows_with_its_buttons() { - for (large, button, bar) in [(false, 32, 54), (true, 44, 66)] { + for (large, button, bar) in [(false, 44, 66), (true, 44, 66)] { let mut r = Rig::new(if large { "targets-chooser-large" } else { "targets-chooser" }); r.app.set_large_targets(large); let spec = crate::chooser::Spec { mode: crate::chooser::Mode::Save, name: Some("new.txt".into()), ..crate::chooser::Spec::default() }; @@ -15160,23 +15441,225 @@ mod tests { assert_ne!(r.app.hit(f.x - 1, t.y), Hit::FilterBox, "not left of it"); } - #[test] - fn with_larger_targets_a_long_menu_still_fits_a_short_window() { - let mut r = target_rig("targets-short-menu", 3, true); - r.app.resized(900, 700, 1.0); + /// The context menu, opened by the pointer on the first row, in a `w` × `h` window. + fn open_long_menu(r: &mut Rig, w: i32, h: i32) -> (Rect, usize) { + r.app.resized(w, h, 1.0); let l = r.app.layout(); r.app.input(Input::Move { x: (l.list.x + 60) as f64, y: (l.list.y + 10) as f64 }); r.app.input(Input::Button { button: BTN_RIGHT, pressed: true }); r.app.input(Input::Button { button: BTN_RIGHT, pressed: false }); let m = r.app.menu.as_ref().expect("a menu"); - let (mr, n) = (r.app.menu_rect(m), m.items.len()); - let row = r.app.menu_row_h(n); - assert!(n * 44 > 700 && (28..44).contains(&row), "{n} items, each {row} tall"); - assert!(mr.y >= 0 && mr.bottom() <= 700, "all of it in the window: {mr:?}"); - let last = mr.y + r.app.px(4.0) + (n as i32 - 1) * row; - assert_eq!(r.app.hit(mr.x + 20, last + row - 1), Hit::MenuItem(n - 1), "the last item can be pressed"); - r.app.resized(900, 2000, 1.0); - assert_eq!(r.app.menu_row_h(n), 44, "and with room, they're 44 again"); + (r.app.menu_rect(m), m.items.len()) + } + + #[test] + fn a_long_menu_in_a_short_window_keeps_44_px_items_and_scrolls() { + for large in [false, true] { + let mut r = target_rig(if large { "targets-short-menu-large" } else { "targets-short-menu" }, 3, large); + let (mr, n) = open_long_menu(&mut r, 900, 500); + assert!(n * 44 > 500, "{n} items"); + assert_eq!(r.app.menu_row_h(), 44, "large: {large}"); + assert!(mr.y >= 0 && mr.bottom() <= 500 && mr.h == 500, "as tall as the window, and in it: {mr:?}"); + let m = r.app.menu.as_ref().unwrap(); + let (above, below) = r.app.menu_scroller(m).cues(); + assert!(above.is_none() && below.is_some(), "only the cue below, at the top"); + let cue = below.unwrap(); + assert_eq!((cue.h, cue.bottom()), (20, mr.bottom() - 4)); + // Every item showing is 44 tall where it takes clicks. + let v = r.app.menu_view(m); + let first = r.app.menu_item_rect(m, 0); + assert_eq!(r.app.hit(cue.x + 20, cue.y + 2), Hit::Popup, "the cue takes no clicks, and doesn't close the menu"); + assert_eq!((first.y, first.h), (v.y, 44)); + assert_eq!((r.app.hit(mr.x + 20, first.y), r.app.hit(mr.x + 20, first.bottom() - 1)), (Hit::MenuItem(0), Hit::MenuItem(0))); + // The wheel scrolls it to the end, and no further. + r.app.dirty = Rect::default(); + r.app.input(Input::Scroll { lines: 100.0, pixels: 0.0 }); + let m = r.app.menu.as_ref().unwrap(); + let most = n as i32 * 44 - v.h; + assert_eq!(r.app.menu_scroller(m).scroll, most); + assert!(r.app.dirty.intersects(mr), "repainted"); + let (above, below) = r.app.menu_scroller(m).cues(); + assert!(above.is_some() && below.is_none(), "only the cue above, at the end"); + let last = r.app.menu_item_rect(m, n - 1); + assert_eq!(last.bottom(), v.bottom(), "the last item ends at the view's bottom"); + assert_eq!((r.app.hit(mr.x + 20, last.y), r.app.hit(mr.x + 20, last.bottom() - 1)), (Hit::MenuItem(n - 1), Hit::MenuItem(n - 1)), "and is pressed across its 44 px"); + // The wheel at the end does nothing, and repaints nothing. + r.app.dirty = Rect::default(); + r.app.input(Input::Scroll { lines: 3.0, pixels: 0.0 }); + assert_eq!(r.app.dirty, Rect::default()); + // A screen reader finds each item where it is, those scrolled away not showing. + let s = crate::a11y::Link::new().build(&mut r.app); + let items: Vec<&crate::a11y::Node> = s.fixed.iter().filter(|n| n.role == crate::a11y::Role::MenuItem).collect(); + assert_eq!(items.len(), n); + assert!(items.iter().all(|i| i.rect.h == 44)); + assert!(!items[0].showing && items[n - 1].showing); + // Pressing the last item does what it says. + let action = r.app.menu.as_ref().unwrap().items[n - 1].action; + assert_eq!(action, Action::NewWindow); + r.app.input(Input::Move { x: (mr.x + 20) as f64, y: (last.y + 22) as f64 }); + assert_eq!(r.app.menu.as_ref().unwrap().at, n - 1, "hovered"); + // Taller, it all fits again, and isn't scrolled. + r.app.resized(900, 2000, 1.0); + let m = r.app.menu.as_ref().unwrap(); + assert_eq!((r.app.menu_scroller(m).scroll, r.app.menu_scroller(m).cues()), (0, (None, None))); + } + } + + #[test] + fn the_keyboard_keeps_a_long_menus_item_in_view() { + let mut r = target_rig("targets-menu-keys", 3, false); + let (_, n) = open_long_menu(&mut r, 900, 400); + let in_view = |r: &mut Rig| { + let m = r.app.menu.as_ref().unwrap(); + let (v, i, at) = (r.app.menu_view(m), r.app.menu_item_rect(m, m.at), m.at); + let (above, below) = r.app.menu_scroller(m).cues(); + // Whole, and clear of the cues. + let top = above.map_or(v.y, |c| c.bottom()); + let bottom = below.map_or(v.bottom(), |c| c.y); + assert!(i.y >= top && i.bottom() <= bottom, "item {at} at {i:?}, view {v:?}, cues {above:?} {below:?}"); + assert_eq!(r.app.hit(i.x + 20, i.y + 22), Hit::MenuItem(at), "and pressed where it shows"); + }; + // Down through every item, then wrapping to the top. + for _ in 0..n + 1 { + r.key(k::KEY_Down, ""); + in_view(&mut r); + } + r.key(k::KEY_End, ""); + assert_eq!(r.app.menu.as_ref().unwrap().at, n - 1); + in_view(&mut r); + assert!(r.app.menu_scroller(r.app.menu.as_ref().unwrap()).cues().1.is_none(), "no cue below the last"); + r.key(k::KEY_Home, ""); + let m = r.app.menu.as_ref().unwrap(); + assert_eq!((m.at, r.app.menu_scroller(m).scroll), (0, 0), "the first, with no cue above it"); + // Up from the top wraps to the last. + r.key(k::KEY_Up, ""); + assert_eq!(r.app.menu.as_ref().unwrap().at, n - 1); + in_view(&mut r); + // A page at a time, down and up, stopping at either end on an item that can be pressed. + r.key(k::KEY_Home, ""); + let page = (r.app.menu_view(r.app.menu.as_ref().unwrap()).h / 44) as usize; + r.key(k::KEY_Page_Down, ""); + let m = r.app.menu.as_ref().unwrap(); + assert!(m.at >= page.min(n - 1) || !m.items[page.min(n - 1)].enabled, "a page on: {} of {page}", m.at); + assert!(m.items[m.at].enabled); + in_view(&mut r); + for _ in 0..n { + r.key(k::KEY_Page_Down, ""); + in_view(&mut r); + } + assert_eq!(r.app.menu.as_ref().unwrap().at, n - 1, "Page Down stops at the end"); + for _ in 0..n { + r.key(k::KEY_Page_Up, ""); + in_view(&mut r); + } + let m = r.app.menu.as_ref().unwrap(); + assert_eq!(m.at, next_enabled(&m.items, usize::MAX, 1), "Page Up stops at the first"); + } + + /// The menu's item picked shows whole where it's drawn, clear of the cues, and is pressed + /// there. + fn assert_menu_pick_in_view(r: &mut Rig) { + let m = r.app.menu.as_ref().unwrap(); + let (sc, at) = (r.app.menu_scroller(m), m.at); + let i = sc.item(at); + let (above, below) = sc.cues(); + let (top, bottom) = (above.map_or(sc.view.y, |c| c.bottom()), below.map_or(sc.view.bottom(), |c| c.y)); + assert!(i.y >= top && i.bottom() <= bottom, "item {at} at {i:?}, {sc:?}"); + assert_eq!(r.app.hit(i.x + 20, i.y + i.h / 2), Hit::MenuItem(at)); + } + + #[test] + fn a_screen_reader_focusing_a_menu_item_scrolls_it_into_view() { + let mut r = target_rig("targets-menu-a11y", 3, false); + let (_, n) = open_long_menu(&mut r, 900, 400); + r.app.a11y_menu_act(crate::a11y::Act::Focus(crate::a11y::MENU_ITEM0 + (n - 1) as u64)); + assert_eq!(r.app.menu.as_ref().unwrap().at, n - 1); + assert_menu_pick_in_view(&mut r); + let s = crate::a11y::Link::new().build(&mut r.app); + let last = s.fixed.iter().find(|x| x.id == crate::a11y::MENU_ITEM0 + (n - 1) as u64).unwrap(); + assert!(last.showing && last.selected, "showing where it's read"); + r.app.a11y_menu_act(crate::a11y::Act::Focus(crate::a11y::MENU_ITEM0)); + assert_eq!(r.app.menu_scroller(r.app.menu.as_ref().unwrap()).scroll, 0, "and back to the first"); + } + + #[test] + fn a_menus_padding_and_cues_take_no_clicks_and_close_nothing() { + let mut r = target_rig("targets-menu-cue-clicks", 3, false); + let (mr, n) = open_long_menu(&mut r, 900, 400); + r.key(k::KEY_End, ""); + let m = r.app.menu.as_ref().unwrap(); + let (sc, at) = (r.app.menu_scroller(m), m.at); + let (above, below) = sc.cues(); + let cue = above.expect("a cue above, scrolled to the end"); + assert!(below.is_none()); + // A right or left click on the cue, or on the padding, leaves the menu as it was. + for (x, y) in [(cue.x + 30, cue.y + 5), (mr.x + 30, mr.y + 1), (mr.x + 30, mr.bottom() - 2)] { + assert_eq!(r.app.hit(x, y), Hit::Popup, "at {x}, {y}"); + for button in [BTN_RIGHT, BTN_LEFT] { + r.app.pointer = (x, y); + r.app.button(button, true); + r.app.button(button, false); + let m = r.app.menu.as_ref().expect("still open"); + assert_eq!((m.items.len(), m.at, r.app.menu_scroller(m).scroll), (n, at, sc.scroll), "the same menu, as it was"); + } + } + // Outside it, a click still closes it. + r.app.pointer = (mr.right() + 20, mr.y + 50); + r.app.button(BTN_LEFT, true); + r.app.button(BTN_LEFT, false); + assert!(r.app.menu.is_none()); + } + + #[test] + fn a_click_on_a_sidebar_menus_padding_keeps_the_sidebars_keyboard() { + let mut r = pin_rig("pins-menu-padding", &["Projects", "Notes"]); + r.key(k::KEY_F6, ""); + r.key(k::KEY_Down, ""); + r.key(k::KEY_Menu, ""); + let m = r.app.menu.as_ref().expect("the pin's menu"); + let mr = r.app.menu_rect(m); + let side = r.app.side_focus(); + assert!(side.is_some()); + r.app.pointer = (mr.x + 30, mr.y + 1); + r.app.button(BTN_LEFT, true); + r.app.button(BTN_LEFT, false); + assert!(r.app.menu.is_some() && r.app.side_focus() == side, "the menu open, and the sidebar still has the keyboard"); + } + + #[test] + fn a_resize_keeps_a_long_menus_pick_in_view() { + let mut r = target_rig("targets-menu-resize", 3, false); + let (_, n) = open_long_menu(&mut r, 900, 500); + r.key(k::KEY_End, ""); + assert_menu_pick_in_view(&mut r); + for (w, h, scale) in [(900, 400, 1.0), (900, 800, 2.0), (900, 600, 1.5), (900, 2000, 1.0), (900, 400, 1.0)] { + r.app.resized(w, h, scale); + assert_eq!(r.app.menu.as_ref().unwrap().at, n - 1); + assert_menu_pick_in_view(&mut r); + let m = r.app.menu.as_ref().unwrap(); + assert_eq!(m.scroll, r.app.menu_scroller(m).scroll, "held to what it can be at {w}x{h}@{scale}"); + } + } + + #[test] + fn dialog_buttons_menu_items_and_suggestions_are_44_by_default() { + // At 1x and 2x, larger targets off and on: never less than 44 logical px, and never + // grown past it twice. + for (scale, large) in [(1.0, false), (2.0, false), (1.0, true), (2.0, true)] { + let mut r = target_rig(&format!("targets-44-{scale}-{large}"), 3, large); + r.app.resized(1000, 800, scale); + let t = r.app.px(44.0); + for d in [Dialog::ConfirmQuit { at: 1 }, Dialog::ConfirmDelete { paths: vec![PathBuf::from("a")], at: 0, empty: false }] { + let rects = r.app.dialog_button_rects(&d); + assert!(!rects.is_empty() && rects.iter().all(|b| b.h == t && b.w >= t), "{scale} {large}: {rects:?}"); + } + assert_eq!(r.app.menu_row_h(), t); + // The path suggestions, as typing a path offers them. + r.app.suggest = Some(crate::connect::Suggest { items: vec!["~/a/".into(), "~/b/".into()], at: None, typed: "~/".into(), folders: true, more: 0 }); + let (_, row) = r.app.suggestions_rect().expect("offered"); + assert_eq!(row, t); + // The chooser's and Open With's buttons are in their own tests; here, the bar. + } } #[test] diff --git a/crates/app/src/chooser.rs b/crates/app/src/chooser.rs index 8c346b9..05f84ff 100644 --- a/crates/app/src/chooser.rs +++ b/crates/app/src/chooser.rs @@ -382,7 +382,9 @@ impl App { let bar = l.status; let Some(c) = self.chooser.as_ref() else { return Bar { accept: Rect::default(), cancel: Rect::default(), filter: None, name: None, info: Rect::default() } }; let (accept_label, save, labels) = (c.spec.accept_label(), c.spec.mode == Mode::Save, c.labels.clone()); - let h = self.target(size::BAR_CONTROL); + // The buttons are 44 px targets, and the name field and file type button beside them + // as tall, so the bar's one row lines up. + let h = self.target(size::BUTTON_HEIGHT); let y = bar.y + (bar.h - h) / 2; let button_w = |app: &mut App, s: &str| (app.text.measure(s) as i32 + app.px(spacing::SPACE_18 * 2.0)).max(app.px(size::BUTTON_MIN_WIDTH)); let w = button_w(self, &accept_label); @@ -759,9 +761,11 @@ impl App { let Some(c) = self.chooser.as_ref() else { return }; let items: Vec = c.labels.iter().enumerate().map(|(i, &label)| MenuItem { label, keys: "", action: Action::ChooseFilter(i), enabled: true }).collect(); let at = c.filter.unwrap_or(usize::MAX); - let h = self.menu_row_h(items.len()) * items.len() as i32 + self.px(spacing::SPACE_8); - // It opens upwards, over the list, from the right edge of the button. - self.menu = Some(Menu { items, x: r.right() - self.px(size::MENU_WIDTH), y: r.y - h - self.px(spacing::SPACE_4), at }); + let h = self.menu_row_h() * items.len() as i32 + self.px(spacing::SPACE_8); + // It opens upwards, over the list, from the right edge of the button, scrolled to the + // type picked if it's that long. + self.menu = Some(Menu { items, x: r.right() - self.px(size::MENU_WIDTH), y: r.y - h - self.px(spacing::SPACE_4), at, scroll: 0 }); + self.menu_reveal(); self.invalidate_all(); } diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs index cc3762d..c69b169 100644 --- a/crates/app/src/main.rs +++ b/crates/app/src/main.rs @@ -889,8 +889,7 @@ mod bench { let focus = a.gone.as_ref().and_then(|g| g.focus); let gone = format!("[{}]", a.gone_buttons().into_iter().map(|(b, label, r)| format!("[{},{},{}]", esc(&label), rect(r), focus == Some(b))).collect::>().join(",")); let menu = a.menu.as_ref().map(|m| { - let (r, row) = (a.menu_rect(m), a.menu_row_h(m.items.len())); - (0..m.items.len()).map(|i| crate::canvas::Rect::new(r.x, r.y + a.px(gannet_core::tokens::spacing::SPACE_4) + i as i32 * row, r.w, row)).collect() + (0..m.items.len()).map(|i| a.menu_item_rect(m, i)).collect() }); format!( "{{\"name_field\":{},\"large\":{},\"nav\":{},\"crumbs\":{},\"row_h\":{},\"header\":{},\"places\":{},\"ejects\":{},\"closes\":{},\"menu\":{},\"gone\":{}}}", diff --git a/crates/app/src/openwith.rs b/crates/app/src/openwith.rs index 9ceb9f4..8651f25 100644 --- a/crates/app/src/openwith.rs +++ b/crates/app/src/openwith.rs @@ -416,7 +416,8 @@ impl Window { let search = Rect::new(pad, title.bottom() + self.px(spacing::SPACE_8), self.w - 2 * pad, self.target(size::BAR_CONTROL)); // "Always use it" has a line of its own above the buttons, as the type's name can be long. let offer = self.picker.can_always(); - let (h, always_h) = (self.target(size::BAR_CONTROL), self.target(size::ALWAYS_ROW)); + // Open and Cancel are 44 px targets. + let (h, always_h) = (self.target(size::BUTTON_HEIGHT), self.target(size::ALWAYS_ROW)); let grow = h - self.px(size::BAR_CONTROL) + if offer { always_h - self.px(size::ALWAYS_ROW) } else { 0 }; let bar_h = self.px(if offer { size::OPEN_WITH_BAR_ALWAYS } else { size::OPEN_WITH_BAR }) + grow; let bar = Rect::new(0, self.h - bar_h, self.w, bar_h); @@ -1266,7 +1267,8 @@ mod tests { #[test] fn with_larger_targets_the_apps_buttons_and_box_are_44_tall() { - for (large, row, button, always) in [(false, 30, 32, 28), (true, 44, 44, 44)] { + // Open and Cancel are 44 either way (ALI-2665); the search box grows with larger targets. + for (large, row, button, search, always) in [(false, 30, 44, 32, 28), (true, 44, 44, 44, 44)] { let (dir, apps) = installed(); let db = mime_db(&dir); let spec = Spec { types: vec!["text/markdown".into()], offer_always: true, ..Spec::default() }; @@ -1274,7 +1276,8 @@ mod tests { let mut w = Window { picker, apps, text: Text::new(crate::text::UI_PX, false), colors: theme::builtin(true), scale: 1.0, large_targets: large, w: 520, h: 560, scroll: 0, pointer: (0, 0), hover: Hit::None, last_click: None, dirty: false, finish: None, has_keyboard: true, a11y_ids: HashMap::new() }; let l = w.layout(); let tick = l.always.unwrap(); - assert_eq!((l.open.h, l.cancel.h, l.search.h, tick.h), (button, button, button, always), "large: {large}"); + assert_eq!((l.open.h, l.cancel.h, l.search.h, tick.h), (button, button, search, always), "large: {large}"); + assert!(l.open.w >= 44 && l.cancel.w >= 44); assert!(l.bar.contains(tick.x, tick.y) && tick.bottom() < l.open.y && l.open.bottom() < l.bar.bottom(), "all in the bar, the box above the buttons"); assert_eq!((w.hit(l.open.x, l.open.y), w.hit(tick.x, tick.bottom() - 1)), (Hit::Open, Hit::Always)); // The first app, under its heading. diff --git a/crates/app/src/paint.rs b/crates/app/src/paint.rs index 59563e8..e6d0078 100644 --- a/crates/app/src/paint.rs +++ b/crates/app/src/paint.rs @@ -945,23 +945,32 @@ impl App { /// The recent servers or folders offered under the path bar, with the one picked by Up, Down /// or Tab, or under the pointer, highlighted, and how many more there are under them. fn paint_suggestions(&mut self, c: &mut Canvas) { - let Some((r, row)) = self.suggestions_rect() else { return }; - let Some(s) = &self.suggest else { return }; + let Some((r, _)) = self.suggestions_rect() else { return }; + let Some(sc) = self.suggest_scroller() else { return }; + let Some(s) = self.suggest.take() else { return }; let co = self.colors; c.rrect(r, self.px(radius::MENU), co.surface); c.frame(r, HAIRLINE, co.border); let icon = self.px(size::ICON); - let top = r.y + self.px(spacing::SPACE_4); let tx = (r.x + self.px(spacing::SPACE_12) + icon + self.px(spacing::SPACE_8)) as f32; let room = (r.right() - self.px(spacing::SPACE_12)) as f32 - tx; - for i in 0..s.items.len() { - let y = top + i as i32 * row; - if y + row > r.bottom() { - break; + let old = c.clip(); + c.set_clip(old.intersect(sc.view)); + for i in 0..sc.n { + let row = sc.item(i); + // Only the rows in view are drawn; one cut by the edge is clipped there. + if !row.intersects(sc.view) { + continue; + } + let (y, h) = (row.y, row.h); + // The last row, after the items, says how many more there are. + if i >= s.items.len() { + self.text.draw_fitted(c, &more_label(s.more), tx, self.baseline(y, h), room, co.muted); + continue; } let picked = s.at == Some(i); if picked || self.hover == Hit::Suggestion(i) { - let hl = Rect::new(r.x + self.px(spacing::SPACE_4), y, r.w - self.px(spacing::SPACE_8), row); + let hl = Rect::new(r.x + self.px(spacing::SPACE_4), y, r.w - self.px(spacing::SPACE_8), h); c.rrect(hl, self.px(radius::HIGHLIGHT), if picked { co.selection } else { co.hover }); // The bar a menu's highlight has, so the one picked isn't told by colour alone. if picked { @@ -971,12 +980,27 @@ impl App { let fg = if picked { co.on_selection } else { co.foreground }; // Folders' icons are coloured as they are in the list. let (shape, tint) = if s.folders { (Icon::Folder, if picked { fg } else { co.accent_mark }) } else { (Icon::Server, fg) }; - self.icons.draw(c, shape, r.x + self.px(spacing::SPACE_12), y + (row - icon) / 2, icon, tint); - self.text.draw_fitted(c, s.label(i), tx, self.baseline(y, row), room, fg); + self.icons.draw(c, shape, r.x + self.px(spacing::SPACE_12), y + (h - icon) / 2, icon, tint); + self.text.draw_fitted(c, s.label(i), tx, self.baseline(y, h), room, fg); } - let y = top + s.items.len() as i32 * row; - if s.more > 0 && y + row <= r.bottom() { - self.text.draw_fitted(c, &more_label(s.more), tx, self.baseline(y, row), room, co.muted); + self.paint_scroll_cues(c, &sc); + c.set_clip(old); + self.suggest = Some(s); + } + + /// A scrolled menu's or the suggestions' cues: an arrow at each edge there's more past, on + /// the box's own surface over the row it covers, with a line between it and the rows so the + /// row cut short reads as going on, and isn't told by a cut edge alone. + fn paint_scroll_cues(&mut self, c: &mut Canvas, sc: &crate::app::Scroller) { + let co = self.colors; + let (above, below) = sc.cues(); + let arrow = self.px(size::ICON); + for (cue, icon, up) in [(above, Icon::ArrowUp, true), (below, Icon::ArrowDown, false)] { + if let Some(q) = cue { + c.fill(q, co.surface); + c.fill(Rect::new(q.x, if up { q.bottom() - HAIRLINE } else { q.y }, q.w, HAIRLINE), co.border); + self.icons.draw(c, icon, q.x + (q.w - arrow) / 2, q.y + (q.h - arrow) / 2, arrow, co.muted); + } } } @@ -1113,12 +1137,18 @@ impl App { let r = self.menu_rect(&m); c.rrect(r, self.px(radius::MENU), co.surface); c.frame(r, HAIRLINE, co.border); - let row = self.menu_row_h(m.items.len()); - let top = r.y + self.px(spacing::SPACE_4); + let view = self.menu_view(&m); + let old = c.clip(); + c.set_clip(old.intersect(view)); for (i, item) in m.items.iter().enumerate() { - let y = top + i as i32 * row; + let row = self.menu_item_rect(&m, i); + // Only the items in view are drawn; one cut by the edge is clipped there. + if !row.intersects(view) { + continue; + } + let y = row.y; if i == m.at && item.enabled { - let hl = Rect::new(r.x + self.px(spacing::SPACE_4), y, r.w - self.px(spacing::SPACE_8), row); + let hl = Rect::new(r.x + self.px(spacing::SPACE_4), y, r.w - self.px(spacing::SPACE_8), row.h); c.rrect(hl, self.px(radius::HIGHLIGHT), co.selection); // The bar a selected row has, so the highlight isn't told by colour alone. c.fill(Rect::new(hl.x, hl.y + self.px(spacing::SPACE_5), self.px(size::SELECTION_BAR), hl.h - self.px(spacing::SPACE_5 * 2.0)), co.selection_mark); @@ -1130,12 +1160,16 @@ impl App { } else { co.foreground }; - let by = self.baseline(y, row); + let by = self.baseline(y, row.h); self.text.draw_str(c, item.label, (r.x + self.px(spacing::SPACE_12)) as f32, by, fg); let w = self.text.measure(item.keys); let keys = if !item.enabled { co.border } else if i == m.at { co.on_selection_muted } else { co.muted }; self.text.draw_str(c, item.keys, (r.right() - self.px(spacing::SPACE_12)) as f32 - w, by, keys); } + // A menu taller than the window says there's more above or below. + let sc = self.menu_scroller(&m); + self.paint_scroll_cues(c, &sc); + c.set_clip(old); self.menu = Some(m); } } diff --git a/crates/core/src/tokens.rs b/crates/core/src/tokens.rs index c1ffcab..f538984 100644 --- a/crates/core/src/tokens.rs +++ b/crates/core/src/tokens.rs @@ -918,7 +918,7 @@ pub mod radius { /// Fixed sizes, in px. pub mod size { - /// The least a target measures each way: WCAG 2.2's enhanced target size. Back, Forward and Up always have it, panel rows' close buttons are this wide, and with larger targets on (settings: targets = "large") every row, button and field grows to it (crates/app/src/app.rs TARGET, App::target). + /// The least a target measures each way: WCAG 2.2's enhanced target size. Back, Forward and Up always have it, panel rows' close buttons are this wide, dialog buttons (button-height), menu items and path suggestions (menu-row) are this tall, and with larger targets on (settings: targets = "large") every row, button and field grows to it (crates/app/src/app.rs TARGET, App::target). pub const TARGET: f32 = 44.0; /// Lines between parts of the window and a field's or dialog's outline: one device pixel at any scale, so it's drawn unscaled (crates/app/src/app.rs HAIRLINE). @@ -954,10 +954,10 @@ pub mod size { /// The status bar's height. pub const STATUS_BAR: f32 = 26.0; - /// A file chooser's bottom bar, with the name field and buttons, before larger targets grow them. + /// A file chooser's bottom bar as if its controls were bar-control tall. Its name field, file type button, Open and Cancel are button-height tall, which adds what they have over bar-control. pub const CHOOSER_BAR: f32 = 54.0; - /// A field or button in a bottom bar (the chooser's name, filter, Open and Cancel; Open With's search and buttons) and Quick View's Open button. + /// Open With's search field and Quick View's Open button. The bottom bars' buttons are button-height. pub const BAR_CONTROL: f32 = 32.0; /// The sidebar's width, at most a third of the window. @@ -975,14 +975,20 @@ pub mod size { /// A row of the panel above the status bar: a job under way or a notice. pub const PANEL_ROW: f32 = 30.0; - /// A dialog's buttons and fields, and the Trash bar's Empty Trash. + /// A dialog's fields, and the Trash bar's Empty Trash. A dialog's buttons are button-height. pub const CONTROL_HEIGHT: f32 = 30.0; + /// A dialog's buttons (questions, conflicts, Format, Connect to Server, Rename many), and the buttons and name field in the chooser's and Open With's bottom bars: target's 44 px, so larger targets don't grow them (ALI-2665). + pub const BUTTON_HEIGHT: f32 = 44.0; + /// A dialog's checkbox row (Do the same for the rest, Remember the password). pub const CHECK_ROW: f32 = 24.0; - /// A menu item and a path suggestion, at most what fits in the window. - pub const MENU_ROW: f32 = 28.0; + /// A menu item and a path suggestion: target's 44 px, so larger targets don't grow them. A menu or the suggestions taller than the window scroll (ALI-2665). + pub const MENU_ROW: f32 = 44.0; + + /// The strip at a scrolled menu's or the path suggestions' top or bottom edge with an arrow (icon, in muted on surface) saying there's more that way, and a hairline (border) on its side towards the items. It covers the item under it, which takes no clicks there. + pub const MENU_SCROLL_CUE: f32 = 20.0; /// A heading row in Open With's list (Recommended, Other apps). pub const HEADING_ROW: f32 = 28.0; @@ -993,10 +999,10 @@ pub mod size { /// Open With's "Always use this app" checkbox row. pub const ALWAYS_ROW: f32 = 28.0; - /// Open With's bottom bar with only its buttons, before it grows for large targets. + /// Open With's bottom bar with only its buttons, as if they were bar-control tall: button-height adds what it has over that. pub const OPEN_WITH_BAR: f32 = 60.0; - /// Open With's bottom bar with the "Always use this app" row above its buttons, before it grows for large targets. + /// Open With's bottom bar with the "Always use this app" row above its buttons, as if they were bar-control tall: button-height, and larger targets on the row, add to it. pub const OPEN_WITH_BAR_ALWAYS: f32 = 96.0; /// A sidebar heading's height, like Devices (crates/app/src/app.rs SIDEBAR_HEADING). @@ -1125,7 +1131,7 @@ pub mod size { /// A question's dialog width (Delete, Empty Trash, Replace). pub const DIALOG_WIDTH: f32 = 520.0; - /// A question's dialog height before larger targets and a checkbox add to it. + /// A question's dialog height as if its buttons were control-height tall: button-height, and larger targets and a checkbox, add to it. pub const DIALOG_HEIGHT: f32 = 170.0; /// The Connect to Server dialog's and a share's password dialog's width. @@ -1146,7 +1152,7 @@ pub mod size { /// The Rename many dialog's width. pub const RENAME_MANY_WIDTH: f32 = 680.0; - /// The Rename many dialog's height apart from its list of names. + /// The Rename many dialog's height apart from its list of names, with control-height fields and buttons: button-height, and larger targets on the fields, add to it. pub const RENAME_MANY_FIXED: f32 = 228.0; /// The tallest the Rename many dialog gets. diff --git a/design/tokens.json b/design/tokens.json index 5a59906..7a2e2df 100644 --- a/design/tokens.json +++ b/design/tokens.json @@ -655,7 +655,7 @@ { "name": "target", "value": "44px", - "usage": "The least a target measures each way: WCAG 2.2's enhanced target size. Back, Forward and Up always have it, panel rows' close buttons are this wide, and with larger targets on (settings: targets = \"large\") every row, button and field grows to it (crates/app/src/app.rs TARGET, App::target)." + "usage": "The least a target measures each way: WCAG 2.2's enhanced target size. Back, Forward and Up always have it, panel rows' close buttons are this wide, dialog buttons (button-height), menu items and path suggestions (menu-row) are this tall, and with larger targets on (settings: targets = \"large\") every row, button and field grows to it (crates/app/src/app.rs TARGET, App::target)." }, { "name": "hairline", @@ -715,12 +715,12 @@ { "name": "chooser-bar", "value": "54px", - "usage": "A file chooser's bottom bar, with the name field and buttons, before larger targets grow them." + "usage": "A file chooser's bottom bar as if its controls were bar-control tall. Its name field, file type button, Open and Cancel are button-height tall, which adds what they have over bar-control." }, { "name": "bar-control", "value": "32px", - "usage": "A field or button in a bottom bar (the chooser's name, filter, Open and Cancel; Open With's search and buttons) and Quick View's Open button." + "usage": "Open With's search field and Quick View's Open button. The bottom bars' buttons are button-height." }, { "name": "sidebar", @@ -750,7 +750,12 @@ { "name": "control-height", "value": "30px", - "usage": "A dialog's buttons and fields, and the Trash bar's Empty Trash." + "usage": "A dialog's fields, and the Trash bar's Empty Trash. A dialog's buttons are button-height." + }, + { + "name": "button-height", + "value": "44px", + "usage": "A dialog's buttons (questions, conflicts, Format, Connect to Server, Rename many), and the buttons and name field in the chooser's and Open With's bottom bars: target's 44 px, so larger targets don't grow them (ALI-2665)." }, { "name": "check-row", @@ -759,8 +764,13 @@ }, { "name": "menu-row", - "value": "28px", - "usage": "A menu item and a path suggestion, at most what fits in the window." + "value": "44px", + "usage": "A menu item and a path suggestion: target's 44 px, so larger targets don't grow them. A menu or the suggestions taller than the window scroll (ALI-2665)." + }, + { + "name": "menu-scroll-cue", + "value": "20px", + "usage": "The strip at a scrolled menu's or the path suggestions' top or bottom edge with an arrow (icon, in muted on surface) saying there's more that way, and a hairline (border) on its side towards the items. It covers the item under it, which takes no clicks there." }, { "name": "heading-row", @@ -780,12 +790,12 @@ { "name": "open-with-bar", "value": "60px", - "usage": "Open With's bottom bar with only its buttons, before it grows for large targets." + "usage": "Open With's bottom bar with only its buttons, as if they were bar-control tall: button-height adds what it has over that." }, { "name": "open-with-bar-always", "value": "96px", - "usage": "Open With's bottom bar with the \"Always use this app\" row above its buttons, before it grows for large targets." + "usage": "Open With's bottom bar with the \"Always use this app\" row above its buttons, as if they were bar-control tall: button-height, and larger targets on the row, add to it." }, { "name": "sidebar-heading", @@ -1000,7 +1010,7 @@ { "name": "dialog-height", "value": "170px", - "usage": "A question's dialog height before larger targets and a checkbox add to it." + "usage": "A question's dialog height as if its buttons were control-height tall: button-height, and larger targets and a checkbox, add to it." }, { "name": "server-dialog-width", @@ -1035,7 +1045,7 @@ { "name": "rename-many-fixed", "value": "228px", - "usage": "The Rename many dialog's height apart from its list of names." + "usage": "The Rename many dialog's height apart from its list of names, with control-height fields and buttons: button-height, and larger targets on the fields, add to it." }, { "name": "rename-many-max-height", diff --git a/tests/e2e.py b/tests/e2e.py index 31e72ce..7916ebe 100644 --- a/tests/e2e.py +++ b/tests/e2e.py @@ -4363,6 +4363,110 @@ def all_44(rects): return bool(rects) and all(w >= 44 and h >= 44 for _, _, w, h in rects) +@check +def dialog_buttons_menus_and_suggestions_are_44_by_default(h): + """With the default setting, a question's and a conflict's buttons, Open With's buttons, menu + items and path suggestions are 44 px tall, in light and dark and at twice the scale. A menu + taller than the window scrolls, with an arrow at the edge it goes on past.""" + fs = fresh_fs() + tree(fs, {"src/a.txt": "A", "dst/a.txt": "B", "Projects/x": "", "Programs/p": "", "notes.md": "# hi", **{f"many/d{i}/f": "" for i in range(20)}}) + share, _ = stand_in_apps() + shutil.rmtree(SCRATCH / "client/home/.local/state/aliasos", ignore_errors=True) + gtk = SCRATCH / "client/config/gtk-4.0" + try: + for theme in ("light", "dark"): + if theme == "dark": + gtk.mkdir(parents=True, exist_ok=True) + (gtk / "settings.ini").write_text("[Settings]\ngtk-application-prefer-dark-theme=1\n") + for scale in (1, 2): + tag = f"{theme}-{scale}x" + a = App(h, fs / "src", extra_env={"XDG_DATA_DIRS": str(share)}) + try: + if scale == 2: + a.sway("output * scale 2") + s = a.wait(lambda s: s["names"] == ["a.txt"] and s["targets"]["row_h"] == scale * ROW, "listed") + assert (s["base"] == 0xfafafa) == (theme == "light"), f"{tag}: {s['base']:06x}" + assert not s["targets"]["large"] + # The list's menu, from the keyboard: 44 an item, scrolled at the end. + a.key("Menu") + s = a.wait(lambda s: s["menu"] and s["targets"]["menu"], "the menu") + items = s["targets"]["menu"] + assert all(h == scale * 44 for _, _, _, h in items), items + a.shot(f"targets-44-menu-{tag}") + a.key("End") + # The window is 800 device pixels tall at either scale: the last item ends in it. + a.wait(lambda s: s["menu"] and s["targets"]["menu"] and s["targets"]["menu"][-1][1] + s["targets"]["menu"][-1][3] <= 800, "scrolled to the end") + a.shot(f"targets-44-menu-end-{tag}") + a.key("Escape") + a.wait(lambda s: not s["menu"], "the menu closed") + # A question. + a.key("Down") + a.wait(lambda s: s["selected"] == ["a.txt"], "selected") + a.key("Delete", mods=["shift"]) + a.wait(lambda s: s["dialog"] == "delete", "asks first") + a.shot(f"targets-44-question-{tag}") + a.key("Escape") + a.wait(lambda s: s["dialog"] == "", "asked no more") + # A conflict. + a.key("c", mods=["ctrl"]) + time.sleep(0.1) + a.key("l", mods=["ctrl"]) + a.wait(lambda s: s["edit"].startswith("path:"), "the path bar") + a.key("a", mods=["ctrl"]) + a.type(str(fs / "dst")) + a.key("Return") + a.wait(lambda s: s["dir"] == str(fs / "dst") and s["edit"] == "none", "in dst") + a.key("v", mods=["ctrl"]) + a.wait(lambda s: s["dialog"] == "conflict", "conflict question") + a.shot(f"targets-44-conflict-{tag}") + time.sleep(0.45) # A new conflict ignores input for a moment. + a.key("Escape") + a.wait(lambda s: s["dialog"] == "" and s["jobs"] == 0, "the paste stopped") + assert (fs / "dst/a.txt").read_text() == "B", "nothing replaced" + # The path's suggestions. + a.key("l", mods=["ctrl"]) + a.wait(lambda s: s["edit"].startswith("path:"), "the path bar") + a.key("a", mods=["ctrl"]) + a.type(f"{fs}/Pro") + a.wait(lambda s: suggested(s) == [f"{fs}/Programs/", f"{fs}/Projects/"], "suggested") + a.key("Down") + a.wait(lambda s: s["suggest"]["at"] == 0, "picked") + a.shot(f"targets-44-suggest-{tag}") + # Eight and the count: at twice the scale, taller than the room, so they + # scroll to keep the one picked in view. + a.key("a", mods=["ctrl"]) + a.type(f"{fs}/many/") + a.wait(lambda s: len(suggested(s)) == 8 and s["suggest"]["more"] == 12, "eight, and 12 more") + a.key(*["Down"] * 8) + a.wait(lambda s: s["suggest"]["at"] == 7, "the last picked") + a.shot(f"targets-44-suggest-many-{tag}") + a.key("Escape") + a.key("Escape") + a.wait(lambda s: s["edit"] == "none", "the field put away") + # Open With, from the menu. + a.key("l", mods=["ctrl"]) + a.wait(lambda s: s["edit"].startswith("path:"), "the path bar") + a.key("a", mods=["ctrl"]) + a.type(str(fs)) + a.key("Return") + s = a.wait(lambda s: s["dir"] == str(fs) and "notes.md" in s["names"] and s["edit"] == "none", "in the top folder") + (SCRATCH / "state.json.openwith").unlink(missing_ok=True) + # The pointer's place is out of the output's 1280 x 800, whatever its scale. + a.click(ROW_X * scale, row_y(s["names"].index("notes.md")) * scale, 0x111) + menu_choose(a, "Open with…") + h.wait_window(10) + wait_open_with(lambda s: s["rows"], "the apps") + a.shot(f"targets-44-open-with-{tag}") + a.key("Escape") + time.sleep(0.3) + finally: + if scale == 2: + a.sway("output * scale 1") + a.close() + finally: + shutil.rmtree(gtk, ignore_errors=True) + + @check def larger_targets_from_the_settings_file_without_a_restart(h): fs = fresh_fs() @@ -4381,12 +4485,12 @@ def larger_targets_from_the_settings_file_without_a_restart(h): a.click(ROW_X, list_y + t["row_h"] + t["row_h"] - 3) a.wait(lambda s: s["selected"] == ["b.txt"], "the second row, 44 tall") a.shot("targets-large") - # The list's menu at 44 an item needs a taller screen than 800. In a shorter window its - # items take less, so it fits. + # The list's menu at 44 an item needs a taller screen than 800. In a shorter window it + # keeps its 44 px items and scrolls. a.click(ROW_X, list_y + 4, button=0x111) s = a.wait(lambda s: s["menu"] and s["targets"]["menu"], "the menu") items = s["targets"]["menu"] - assert items[-1][1] + items[-1][3] <= 800 and all(28 <= h < 44 for _, _, _, h in items), items + assert items[-1][1] + items[-1][3] > 800 and all(h == 44 for _, _, _, h in items), items a.key("Escape") a.wait(lambda s: not s["menu"]) a.sway("output HEADLESS-1 resolution 1280x900") @@ -6662,7 +6766,8 @@ def folders_pin_to_the_sidebar_by_dragging_and_reorder_there(h): a.click(60, y, button=BTN_LEFT + 1) assert a.wait(lambda s: s["menu"], "the pin's menu")["menu_items"] == ["Open", "Unpin"] a.shot("pin-menu") - a.click(80, y + 4 + 28 + 14) + # The second item, Unpin: menu items are 44 px tall. + a.click(80, y + 4 + 44 + 22) b.wait(lambda s: "Projects" not in s["places"], "unpinned in the other window too") assert (fs / "work/Projects/p").exists() assert conf.read_text().startswith("sftp://server/srv Server\n")