authoravatarclover caruso<git@paperclover.net>2026-10-16 14:09:29-07:00
committeravatarclover caruso<git@paperclover.net>2026-10-19 16:50:39-07:00
logc3f000fe161ab495e3e0123a1c79cfc438c1fe72
treea3920ca313380e17ad0dd9acff4b0033fd00d766
parent2793455970b9dbe108f5103c69802fc459b30298
signature Signed by SSH key SHA256:52mNGHRsVFBDED9IAX5pe+LRWUefqTbxEReunq21QvU

feat: draw split panes

The page area divides as a tree, each part one pane or two side by side or one above the other. Each pane has a page box of its own, named by its id where the one page box was. While split, each pane is a group named for its section and page, under a header with them and a close button. Dividers are the frame's gap between papers: dragging one moves it, a double click evens it. A press on a pane, or F6 reaching it, focuses it before it acts, and the toolbar, tabs, page list and title follow; the wheel scrolls the pane under the pointer. Every pane's page is painted and rounded, and the open page tab joins the focused pane only beside the list. Only replays reach it, through the steps split right, split down and close pane; closing back to one pane draws the window as it was. Assisted-by: claude-opus-5.5

17 files changed, 967 insertions(+), 157 deletions(-)

crates/snowbound/src/conflict_render.rs+2-2
......@@ -41,7 +41,7 @@ fn layout(ui: &mut Ui, session: &Session, showing: &Showing, menu: bool) -> Vec<
4141 .into_iter()
4242 .collect();
4343 ui.open_as(
44 page(),
44 Id::ROOT.child("page"),
4545 Spec {
4646 flags: Flags::CUSTOM,
4747 size: [fill(), fill()],
......@@ -87,7 +87,7 @@ fn paint(
8787 queue: &wgpu::Queue,
8888) -> Vec<u8> {
8989 let size = SIZE.map(|side| (side * SCALE) as u32);
90 let corner = ui.laid_out(super::page()).unwrap();
90 let corner = ui.laid_out(Id::ROOT.child("page")).unwrap();
9191 let box_size = [
9292 ((corner[2] - corner[0]) * SCALE) as u32,
9393 ((corner[3] - corner[1]) * SCALE) as u32,
crates/snowbound/src/link.rs+2-2
......@@ -2,7 +2,7 @@
22//! the page's context menu, and following a clicked link, to a page
33//! of the notebook or with the system's handler.
44
5use crate::{Command, State, art, commands, page, platform};
5use crate::{Command, State, art, commands, platform};
66use canvas::interaction::Context;
77use onestore::ExGuid;
88use onestore::page::link::{LinkTarget, internal_link};
......@@ -245,7 +245,7 @@ impl State {
245245 return Ok(());
246246 }
247247 self.ui.close_popup(id());
248 self.ui.set_focus(Some(page()));
248 self.ui.set_focus(Some(self.pane.id));
249249 self.link = None;
250250 Ok(())
251251 }
crates/snowbound/src/live.rs+3-3
......@@ -6,7 +6,7 @@
66//! this computer to whoever types its code (`Host`), or opens one another computer shares
77//! (`Joined`), as `share.rs`'s dialogs start them.
88
9use crate::{Command, Library, Session, State, TAB_ROW, page, platform, settings};
9use crate::{Command, Library, Session, State, TAB_ROW, platform, settings};
1010use canvas::{document::TextPosition, editor::TextOutline};
1111use notebook::live::{
1212 self, Caret, Hello, Peer, Reach, Room, Spot,
......@@ -920,7 +920,7 @@ impl State {
920920 let Some(session) = &self.session else {
921921 return;
922922 };
923 let Some([left, top, right, bottom]) = self.ui.laid_out(page()) else {
923 let Some([left, top, right, bottom]) = self.ui.laid_out(self.pane.id) else {
924924 return;
925925 };
926926 let here = (section(session), Some(self.pane.showing.space.into()));
......@@ -1044,7 +1044,7 @@ impl State {
10441044 [x0, y0, y1]: [f32; 3],
10451045 selection: &[[f32; 4]],
10461046 ) {
1047 let Some([left, top, ..]) = self.ui.laid_out(page()) else {
1047 let Some([left, top, ..]) = self.ui.laid_out(self.pane.id) else {
10481048 return;
10491049 };
10501050 let id = peer.hello.peer;
crates/snowbound/src/main.rs+236-119
......@@ -426,6 +426,10 @@ enum Replay {
426426 Resize([f32; 2]),
427427 /// Draws with this backend from then on, as Options' Renderer does.
428428 Renderer(settings::Backend),
429 /// Shows the focused page in a new pane after the focused one along the axis.
430 Split(Axis),
431 /// Closes the focused pane.
432 ClosePane,
429433 Quit,
430434}
431435
......@@ -542,6 +546,9 @@ fn icloud_listed(proxy: EventLoopProxy<UserEvent>) -> impl Fn() + Send + Sync +
542546
543547/// A page view, and which page, locked section or empty notebook it shows.
544548struct Pane {
549 /// The pane's page box, whose accessibility node holds the page's tree while the pane
550 /// has the focus.
551 id: Id,
545552 view: PageView,
546553 showing: Showing,
547554 /// The newest read requested; older ones are dropped when they finish.
......@@ -566,7 +573,7 @@ struct Pane {
566573}
567574
568575/// Which page of the open section a pane shows, and what the page list shows beneath it.
569#[derive(Default)]
576#[derive(Clone, Copy, Default)]
570577struct Showing {
571578 space: ExGuid,
572579 /// The version of page `space` open, by its context.
......@@ -761,6 +768,15 @@ struct Opening {
761768const HOLD: std::time::Duration = std::time::Duration::from_millis(200);
762769
763770impl Pane {
771 /// The paper the pane's page lies on in `theme`, in the page's colour.
772 fn paper(&self, theme: &Theme) -> canvas::gpu::Paper {
773 canvas::gpu::Paper {
774 color: theme.paper,
775 ink: theme.paper_ink,
776 }
777 .colored(self.view.editor.page_color())
778 }
779
764780 /// The page opening here, once the pictures it shows first are drawn on `paper` or
765781 /// `HOLD` has passed.
766782 fn opened(&mut self, paper: canvas::gpu::Paper, redraw: &std::task::Waker) -> Option<Opening> {
......@@ -859,6 +875,10 @@ enum Command {
859875 Page(Request),
860876 /// Runs a command, or one of a list's entries, after the frame's input.
861877 Choose(commands::Choice),
878 /// Shows the focused pane's page in a new pane after it along the axis.
879 Split(Axis),
880 /// Closes the pane of this page box.
881 ClosePane(Id),
862882}
863883
864884struct State {
......@@ -899,6 +919,8 @@ struct State {
899919 /// The focused pane, which the chrome around the page area follows.
900920 pane: Pane,
901921 parked: Vec<split::Parked>,
922 /// How the panes divide the page area.
923 split: split::Split,
902924 /// The open notebooks in the sidebar's order.
903925 notebooks: Vec<Arc<Library>>,
904926 /// The section the focused pane shows.
......@@ -1070,12 +1092,6 @@ fn tab_row() -> Id {
10701092 Id::ROOT.child("tab row")
10711093}
10721094
1073/// The page's box, only ever built as the graft of the page's accessibility tree, so the
1074/// tree is sent while it is laid out.
1075fn page() -> Id {
1076 Id::ROOT.child("page")
1077}
1078
10791095/// The section's colour around the page and its tabs.
10801096fn frame() -> Id {
10811097 Id::ROOT.child("frame")
......@@ -1351,7 +1367,8 @@ impl State {
13511367 // A window shown but never focused hears no focus event; a hidden one draws as focused.
13521368 ui.window_focused = !visible || window.has_focus();
13531369 ui.fall_back_to(&fallbacks);
1354 ui.set_focus(Some(page()));
1370 let page = Id::ROOT.child("page");
1371 ui.set_focus(Some(page));
13551372 for family in FONTS {
13561373 for (face, _) in engine.substitute(family).map_or(&[][..], |s| &s.faces) {
13571374 ui.preview_font(face.clone(), family);
......@@ -1394,6 +1411,7 @@ impl State {
13941411 unavailable,
13951412 ui,
13961413 pane: Pane {
1414 id: page,
13971415 view: PageView::new(
13981416 editor,
13991417 engine,
......@@ -1414,6 +1432,7 @@ impl State {
14141432 locked,
14151433 },
14161434 parked: Vec::new(),
1435 split: split::Split::Leaf(page),
14171436 notebooks,
14181437 session,
14191438 shelved: Vec::new(),
......@@ -1622,9 +1641,15 @@ impl State {
16221641 platform::resize_direction(&self.window, self.pointer)
16231642 .map(CursorIcon::from)
16241643 .or_else(|| self.ui.cursor())
1625 .unwrap_or_else(|| cursor_icon(self.pane.view.cursor())),
1644 .unwrap_or_else(|| {
1645 let hovered = self.ui.box_at(self.pointer);
1646 let pane = (self.parked.iter().map(|parked| &parked.pane))
1647 .find(|pane| Some(pane.id) == hovered)
1648 .unwrap_or(&self.pane);
1649 cursor_icon(pane.view.cursor())
1650 }),
16261651 );
1627 let ime = if self.ui.focused() == Some(page()) {
1652 let ime = if self.ui.focused() == Some(self.pane.id) {
16281653 self.pane.view.accepts_text()
16291654 } else {
16301655 search::takes_text(self.ui.focused())
......@@ -1711,16 +1736,26 @@ impl State {
17111736 |_| [0.0; 4],
17121737 );
17131738 }
1714 if let Some(rect) = self.ui.laid_out(page()) {
1715 let size = [
1739 let sized = |rect: [f32; 4]| {
1740 [
17161741 ((rect[2] - rect[0]) * scale).round() as u32,
17171742 ((rect[3] - rect[1]) * scale).round() as u32,
1718 ];
1743 ]
1744 };
1745 if let Some(rect) = self.ui.laid_out(self.pane.id) {
1746 let size = sized(rect);
17191747 if size != self.pane.view.viewport.size {
17201748 let response = self.pane.view.resized(size)?;
17211749 self.respond(response);
17221750 }
17231751 }
1752 for Pane { id, view, .. } in self.parked.iter_mut().map(|parked| &mut parked.pane) {
1753 if let Some(size) = self.ui.laid_out(*id).map(sized)
1754 && size != view.viewport.size
1755 {
1756 let _ = view.resized(size)?;
1757 }
1758 }
17241759 Ok(())
17251760 }
17261761
......@@ -1746,6 +1781,7 @@ impl State {
17461781 /// Builds the frame's boxes and returns the section's colours as they ease, the open
17471782 /// section tab and the open page's tab, for the edges drawn once they are laid out.
17481783 fn build(&mut self) -> Result<(ui::Section, Id, Option<Id>), Box<dyn Error>> {
1784 self.follow_focus()?;
17491785 let target = self.ui.theme.section(section_color(
17501786 self.session
17511787 .as_ref()
......@@ -2040,6 +2076,43 @@ impl State {
20402076 ..Spec::default()
20412077 },
20422078 );
2079 let shown = self.panes(&theme)?;
2080 self.ui.close();
2081 if !shown {
2082 self.ui.close();
2083 self.ui.close();
2084 if self.navigation_bar_right {
2085 self.sidebar(&theme, sidebar);
2086 }
2087 self.sidebar_button(height, sidebar);
2088 self.ui.close();
2089 self.context_menu();
2090 return Ok((section, open_tab, None));
2091 }
2092 if !self.page_tabs_left {
2093 open_page = self.page_list(&theme, &section, row);
2094 }
2095 self.ui.close();
2096 self.ui.close();
2097 if self.navigation_bar_right {
2098 self.sidebar(&theme, sidebar);
2099 }
2100 self.task_pane(&theme);
2101 self.sidebar_button(height, sidebar);
2102 self.ui.close();
2103 self.context_menu();
2104 // No tab stands on the frame in Full Page View.
2105 let open_tab = if self.full_page {
2106 frame().child("no tab")
2107 } else {
2108 open_tab
2109 };
2110 Ok((section, open_tab, open_page))
2111 }
2112
2113 /// Builds the focused pane in the box open: its page, under the bars it shows above it,
2114 /// or what it shows in place of one; whether that is a page.
2115 fn pane_content(&mut self, theme: &Theme) -> Result<bool, Box<dyn Error>> {
20432116 if let Some(session) = &self.session
20442117 && let Some(bar) = session.bar(&self.pane.showing)
20452118 {
......@@ -2060,16 +2133,7 @@ impl State {
20602133 }
20612134 if self.session.is_none() && self.pane.locked.is_some() {
20622135 self.locked_page();
2063 self.ui.close();
2064 self.ui.close();
2065 self.ui.close();
2066 if self.navigation_bar_right {
2067 self.sidebar(&theme, sidebar);
2068 }
2069 self.sidebar_button(height, sidebar);
2070 self.ui.close();
2071 self.context_menu();
2072 return Ok((section, open_tab, None));
2136 return Ok(false);
20732137 }
20742138 if let Some(library) = self
20752139 .pane
......@@ -2078,19 +2142,10 @@ impl State {
20782142 .filter(|_| self.session.is_none())
20792143 {
20802144 self.no_sections(library);
2081 self.ui.close();
2082 self.ui.close();
2083 self.ui.close();
2084 if self.navigation_bar_right {
2085 self.sidebar(&theme, sidebar);
2086 }
2087 self.sidebar_button(height, sidebar);
2088 self.ui.close();
2089 self.context_menu();
2090 return Ok((section, open_tab, None));
2145 return Ok(false);
20912146 }
20922147 self.ui.open_as(
2093 page(),
2148 self.pane.id,
20942149 Spec {
20952150 flags: Flags::CUSTOM | Flags::FOCUSABLE,
20962151 size: [fill(), fill()],
......@@ -2099,15 +2154,15 @@ impl State {
20992154 ..Spec::default()
21002155 },
21012156 );
2102 if let Some(node) = self.ui.access(page()) {
2157 if let Some(node) = self.ui.access(self.pane.id) {
21032158 node.set_tree_id(PAGE_TREE);
21042159 }
21052160 // A page opening has neither the templates nor the scroll of the page leaving.
21062161 let opening = self.loading().is_some();
21072162 if !opening {
2108 self.template_strip(&theme);
2163 self.template_strip(theme);
21092164 }
2110 self.transport(&theme)?;
2165 self.transport(theme)?;
21112166 let scroll = self.pane.view.scroll();
21122167 for (index, axis) in [Axis::X, Axis::Y]
21132168 .into_iter()
......@@ -2143,7 +2198,7 @@ impl State {
21432198 ..Spec::default()
21442199 },
21452200 );
2146 page().child("task")
2201 self.pane.id.child("task")
21472202 });
21482203 self.ui.close();
21492204 if let Some(task) = task {
......@@ -2154,34 +2209,15 @@ impl State {
21542209 Some("Edit it in OneNote with Outlook"),
21552210 );
21562211 }
2157 let signal = self.ui.signal(page());
2158 let focused = self.ui.window_focused && self.ui.focused() == Some(page());
2212 let signal = self.ui.signal(self.pane.id);
2213 let focused = self.ui.window_focused && self.ui.focused() == Some(self.pane.id);
21592214 if focused != self.pane.page_focused {
21602215 self.pane.page_focused = focused;
21612216 let response = self.pane.view.focus_changed(focused)?;
21622217 self.respond(response);
21632218 }
21642219 self.page_events(signal.events)?;
2165 self.ui.close();
2166 if !self.page_tabs_left {
2167 open_page = self.page_list(&theme, &section, row);
2168 }
2169 self.ui.close();
2170 self.ui.close();
2171 if self.navigation_bar_right {
2172 self.sidebar(&theme, sidebar);
2173 }
2174 self.task_pane(&theme);
2175 self.sidebar_button(height, sidebar);
2176 self.ui.close();
2177 self.context_menu();
2178 // No tab stands on the frame in Full Page View.
2179 let open_tab = if self.full_page {
2180 frame().child("no tab")
2181 } else {
2182 open_tab
2183 };
2184 Ok((section, open_tab, open_page))
2220 Ok(true)
21852221 }
21862222
21872223 /// The page's corner radius, sharing its centres with the window's corners.
......@@ -2193,16 +2229,44 @@ impl State {
21932229 /// together with the open page's tab, joined where they meet.
21942230 fn edges(&mut self, section: ui::Section, open_tab: Id, open_page: Option<Id>) {
21952231 let panel = self.ui.laid_out(frame().child("panel"));
2196 let (Some(frame), Some(page)) = (self.ui.laid_out(frame()), self.ui.laid_out(page()))
2197 else {
2232 let column = self.ui.laid_out(frame().child("column"));
2233 let Some(frame) = self.ui.laid_out(frame()) else {
21982234 return;
21992235 };
22002236 let rounding = self.rounding();
2237 let height = (frame[3] - frame[1]).max(1.0);
2238 let gradient = |y| ui::mix(section.frame[0], section.frame[1], (y - frame[1]) / height);
2239 let parked: Vec<_> = (self.parked.iter())
2240 .filter_map(|parked| {
2241 let paper = parked.pane.paper(&self.ui.theme).color;
2242 Some((self.ui.laid_out(parked.pane.id)?, paper))
2243 })
2244 .collect();
2245 for ([left, top, right, bottom], paper) in parked {
2246 let outline = [
2247 ([left, top], rounding),
2248 ([right, top], rounding),
2249 ([right, bottom], rounding),
2250 ([left, bottom], rounding),
2251 ];
2252 self.ui.round_corners(&outline, paper, gradient);
2253 self.ui.border(&outline, true, section.edge);
2254 }
2255 let Some(page) = self.ui.laid_out(self.pane.id) else {
2256 return;
2257 };
2258 // The open page's tab joins the focused pane only beside the page list.
2259 let column = column.unwrap_or(page);
22012260 // Where the open page tab meets the page, concentric with its neighbours.
22022261 let join = PILL_MARGIN + rounding;
22032262 let [left, top, right, bottom] = page;
22042263 let left_tabs = self.page_tabs_left;
2264 let beside = match left_tabs {
2265 true => left - column[0],
2266 false => column[2] - right,
2267 } < 0.5;
22052268 let tab = open_page
2269 .filter(|_| beside)
22062270 .and_then(|id| self.ui.laid_out(id))
22072271 .map(|row| [row[0], row[1], row[2], row[3] - ROW_GAP])
22082272 .zip(panel)
......@@ -2265,11 +2329,8 @@ impl State {
22652329 ([left, bottom], rounding),
22662330 ]),
22672331 }
2268 let height = (frame[3] - frame[1]).max(1.0);
22692332 let paper = self.paper().color;
2270 self.ui.round_corners(&outline, paper, |y| {
2271 ui::mix(section.frame[0], section.frame[1], (y - frame[1]) / height)
2272 });
2333 self.ui.round_corners(&outline, paper, gradient);
22732334 self.ui.border(&outline, true, section.edge);
22742335 // The frame's top corners share the page's centres, and beside the sidebar so does
22752336 // its bottom one, rounding in as the sidebar opens; the frame's top edge breaks where
......@@ -3312,7 +3373,7 @@ impl State {
33123373 let percent = typed.trim().trim_end_matches('%').trim().parse::<f32>();
33133374 zoom = percent.ok().filter(|_| key == NamedKey::Enter);
33143375 self.zoom_typed = None;
3315 self.ui.set_focus(Some(page()));
3376 self.ui.set_focus(Some(self.pane.id));
33163377 }
33173378 } else {
33183379 let id = self.ui.id("level");
......@@ -3522,7 +3583,7 @@ impl State {
35223583 .as_ref()
35233584 .is_some_and(|session| session.read_only(&self.pane.showing));
35243585 let scale = self.ui.scale();
3525 let corner = self.ui.laid_out(page()).unwrap_or_default();
3586 let corner = self.ui.laid_out(self.pane.id).unwrap_or_default();
35263587 let device = |point: [f32; 2]| {
35273588 [
35283589 (point[0] - corner[0]) * scale,
......@@ -3826,6 +3887,8 @@ impl State {
38263887 Command::Page(Request::OpenAttachment(file)) => self.open_attachment(&file)?,
38273888 Command::Page(Request::Play { file, at_ms }) => self.play(&file, at_ms)?,
38283889 Command::Choose(choice) => self.run(choice)?,
3890 Command::Split(axis) => self.split_pane(axis)?,
3891 Command::ClosePane(id) => self.close_pane(id)?,
38293892 Command::TagPicture => self.pick_tag_picture(),
38303893 Command::Text(text) => {
38313894 if let Some(context) = self.pane.view.caret_context() {
......@@ -4064,24 +4127,10 @@ impl State {
40644127 .as_ref()
40654128 .is_none_or(|open| open.library.location != session.library.location);
40664129 self.list(&session.library);
4067 // The section left stays open a while for coming back to; the notebook's
4068 // background sync takes it over once it is closed.
40694130 self.pane.locked = None;
40704131 let previous = self.session.replace(*session);
40714132 if let Some(previous) = previous.and_then(|previous| self.shelve(previous)) {
4072 let path = &previous.tabs[previous.tab].path;
4073 let locked = self.leave(&previous.library, path);
4074 let library = &previous.library;
4075 if !locked && self.notebooks.iter().any(|open| Arc::ptr_eq(open, library)) {
4076 library.keep(&previous.tabs[previous.tab].path, previous.section);
4077 } else {
4078 let section = previous.section;
4079 crate::spawn(move || {
4080 if let Err(error) = section.close() {
4081 eprintln!("Synchronization stopped: {error}");
4082 }
4083 });
4084 }
4133 self.release(previous);
40854134 }
40864135 self.pane.showing = Showing {
40874136 space,
......@@ -4157,6 +4206,25 @@ impl State {
41574206 Ok(())
41584207 }
41594208
4209 /// Keeps `session`, a section no pane shows any more, open a while for coming back to,
4210 /// or closes it where it locks as it is left; the notebook's background sync takes it
4211 /// over once it is closed.
4212 fn release(&mut self, session: Session) {
4213 let path = &session.tabs[session.tab].path;
4214 let locked = self.leave(&session.library, path);
4215 let library = &session.library;
4216 if !locked && self.notebooks.iter().any(|open| Arc::ptr_eq(open, library)) {
4217 library.keep(path, session.section);
4218 } else {
4219 let section = session.section;
4220 crate::spawn(move || {
4221 if let Err(error) = section.close() {
4222 eprintln!("Synchronization stopped: {error}");
4223 }
4224 });
4225 }
4226 }
4227
41604228 /// Takes `library`, a notebook read again after a change, in place of the one it was;
41614229 /// the open section, now at catalog `path` in it, keeps its replica where it moved.
41624230 /// Without `path` the notebook has no sections left, and one of its shows none.
......@@ -4227,7 +4295,7 @@ impl State {
42274295 }
42284296 // A page a search result shows leaves the keys with the search.
42294297 if !search::takes_text(self.ui.focused()) {
4230 self.ui.set_focus(Some(page()));
4298 self.ui.set_focus(Some(self.pane.id));
42314299 }
42324300 self.title();
42334301 self.update_accessibility(true)?;
......@@ -4250,7 +4318,7 @@ impl State {
42504318 /// Follows the view moving: the input method's position and accessibility.
42514319 fn after_move(&mut self) -> Result<(), Box<dyn Error>> {
42524320 let scale = self.ui.scale();
4253 let corner = self.ui.laid_out(page()).unwrap_or_default();
4321 let corner = self.ui.laid_out(self.pane.id).unwrap_or_default();
42544322 let [x0, y0, x1, y1] = self.pane.view.caret_area()?;
42554323 self.window.set_ime_cursor_area(
42564324 LogicalPosition::new(x0 / scale + corner[0], y0 / scale + corner[1]),
......@@ -4397,7 +4465,7 @@ impl State {
43974465 let at = |offset| canvas::document::TextPosition { paragraph, offset };
43984466 self.pane.view.editor.focus_outline(outline)?;
43994467 self.pane.view.editor.select([at(0), at(length)].into())?;
4400 self.ui.set_focus(Some(page()));
4468 self.ui.set_focus(Some(self.pane.id));
44014469 let response = self.pane.view.focus_text()?;
44024470 self.respond(response);
44034471 self.window.request_redraw();
......@@ -4588,13 +4656,13 @@ impl State {
45884656 /// `page` asks or its tree is not grafted yet. The interface's tree goes first, since it
45894657 /// holds the page's.
45904658 fn update_accessibility(&mut self, page: bool) -> Result<(), Box<dyn Error>> {
4591 let built = self.ui.laid_out(self::page()).is_some();
4659 let built = self.ui.laid_out(self.pane.id).is_some();
45924660 if !built && self.page_grafted {
45934661 // Its graft is gone, and with it the tree, which must be sent whole again.
45944662 self.accessibility.deactivate();
45954663 self.page_grafted = false;
45964664 }
4597 let graft = self::page().node();
4665 let graft = self.pane.id.node();
45984666 let title = self.window.title();
45994667 let scale = self.window.scale_factor();
46004668 let grafted = self.page_grafted;
......@@ -4613,10 +4681,10 @@ impl State {
46134681 }
46144682 let mut error = None;
46154683 let mut sent = false;
4616 let (view, ui, window) = (&self.pane.view, &self.ui, &self.window);
4684 let (pane, ui, window) = (&self.pane, &self.ui, &self.window);
46174685 self.access_adapter.update_if_active(|| {
46184686 sent = true;
4619 page_tree(view, ui, window, &mut self.accessibility).unwrap_or_else(|failure| {
4687 page_tree(pane, ui, window, &mut self.accessibility).unwrap_or_else(|failure| {
46204688 error = Some(failure);
46214689 self.accessibility.deactivate();
46224690 let mut root = accesskit::Node::new(accesskit::Role::Group);
......@@ -4686,18 +4754,18 @@ impl State {
46864754 write(&child, depth + 1, out);
46874755 }
46884756 }
4689 let graft = page().node();
4757 let graft = self.pane.id.node();
46904758 let mut chrome = self
46914759 .ui
46924760 .accessibility_tree(&self.window.title(), self.window.scale_factor());
46934761 let focus = std::mem::replace(&mut chrome.focus, ui::Id::ROOT.node());
46944762 let mut tree = Tree::new(chrome, true);
4695 if self.ui.laid_out(page()).is_some() {
4763 if self.ui.laid_out(self.pane.id).is_some() {
46964764 let mut fresh = accessibility::Accessibility::default();
4697 let page = page_tree(&self.pane.view, &self.ui, &self.window, &mut fresh)?;
4765 let page = page_tree(&self.pane, &self.ui, &self.window, &mut fresh)?;
46984766 tree.update_and_process_changes(page, &mut Unwatched);
46994767 }
4700 if focus != graft || self.ui.laid_out(page()).is_some() {
4768 if focus != graft || self.ui.laid_out(self.pane.id).is_some() {
47014769 let update = accesskit::TreeUpdate {
47024770 nodes: Vec::new(),
47034771 tree: None,
......@@ -4739,7 +4807,7 @@ impl State {
47394807 if let Some(index) = self.accessibility.read_only_for_node(request.target_node) {
47404808 if request.action == Action::Focus {
47414809 self.window.focus_window();
4742 self.ui.set_focus(Some(page()));
4810 self.ui.set_focus(Some(self.pane.id));
47434811 let response = self.pane.view.focus_read_only(index)?;
47444812 self.respond(response);
47454813 self.window.request_redraw();
......@@ -4772,7 +4840,7 @@ impl State {
47724840 }
47734841 _ => return Ok(()),
47744842 }
4775 self.ui.set_focus(Some(page()));
4843 self.ui.set_focus(Some(self.pane.id));
47764844 let response = self.pane.view.focus_text()?;
47774845 self.respond(response);
47784846 self.window.request_redraw();
......@@ -4791,6 +4859,12 @@ impl State {
47914859 paper,
47924860 );
47934861 }
4862 for view in self.parked.iter_mut().map(|parked| &mut parked.pane.view) {
4863 let paper = paper.colored(view.editor.page_color());
4864 if let Some((scene, _)) = &mut view.scene {
4865 scene.settle(Some(&view.editor), view.viewport.scale, paper);
4866 }
4867 }
47944868 self.snapshot(&path)?;
47954869 }
47964870 if let Some((dir, opened)) = &self.frames {
......@@ -4870,7 +4944,7 @@ impl State {
48704944 }
48714945 let theme = &self.ui.theme;
48724946 let scale = self.ui.scale();
4873 let corner = self.ui.laid_out(page()).unwrap_or_default();
4947 let corner = self.ui.laid_out(self.pane.id).unwrap_or_default();
48744948 // A page taking a while to open shows its outline, drawn in points from the corner.
48754949 let (page_primitives, viewport) = match self.loading() {
48764950 Some(since) => (
......@@ -4894,24 +4968,51 @@ impl State {
48944968 self.pane.view.viewport,
48954969 ),
48964970 };
4971 let mut pages = vec![(self.pane.id, page_primitives, viewport, corner, paper)];
4972 // Pictures first, as the primitives borrow the views.
4973 for pane in self.parked.iter_mut().map(|parked| &mut parked.pane) {
4974 let paper = pane.paper(theme);
4975 pane.view.update_pictures(paper, &self.redraw);
4976 }
4977 for parked in &self.parked {
4978 let view = &parked.pane.view;
4979 let paper = parked.pane.paper(theme);
4980 let colors = TextColors {
4981 caret: theme.caret,
4982 selection: theme.inactive_selection,
4983 paper,
4984 };
4985 let corner = self.ui.laid_out(parked.pane.id).unwrap_or_default();
4986 pages.push((
4987 parked.pane.id,
4988 view.primitives(colors)?,
4989 view.viewport,
4990 corner,
4991 paper,
4992 ));
4993 }
48974994 lap("page primitives", start);
48984995 let interface = self.ui.layers();
48994996 let layers: Vec<_> = interface
49004997 .iter()
4901 .map(|layer| match layer {
4902 ui::Layer::Primitives(primitives) => primitives.layer(scale),
4903 ui::Layer::Custom { rect, .. } => draw::Layer {
4904 scale: viewport.scale,
4905 origin: [
4906 viewport.origin[0] + corner[0] * scale,
4907 viewport.origin[1] + corner[1] * scale,
4908 ],
4909 clip: Some(rect.map(|value| value * scale)),
4910 backdrop: Some(paper.color),
4911 round: None,
4912 motion: None,
4913 primitives: &page_primitives,
4914 },
4998 .filter_map(|layer| match layer {
4999 ui::Layer::Primitives(primitives) => Some(primitives.layer(scale)),
5000 ui::Layer::Custom { id, rect } => {
5001 let (_, primitives, viewport, corner, paper) =
5002 pages.iter().find(|(page, ..)| page == id)?;
5003 Some(draw::Layer {
5004 scale: viewport.scale,
5005 origin: [
5006 viewport.origin[0] + corner[0] * scale,
5007 viewport.origin[1] + corner[1] * scale,
5008 ],
5009 clip: Some(rect.map(|value| value * scale)),
5010 backdrop: Some(paper.color),
5011 round: None,
5012 motion: None,
5013 primitives,
5014 })
5015 }
49155016 })
49165017 .collect();
49175018 trace_input(&("Draw", viewport.origin, viewport.scale));
......@@ -4943,14 +5044,14 @@ impl State {
49435044 }
49445045
49455046 fn over_page(&self) -> bool {
4946 let [x0, y0, x1, y1] = self.ui.laid_out(page()).unwrap_or_default();
5047 let [x0, y0, x1, y1] = self.ui.laid_out(self.pane.id).unwrap_or_default();
49475048 let [x, y] = self.pointer;
49485049 (x0..x1).contains(&x) && (y0..y1).contains(&y)
49495050 }
49505051
49515052 /// Window point `point` in the page's device pixels.
49525053 fn page_point(&self, point: [f32; 2]) -> [f32; 2] {
4953 let [left, top, ..] = self.ui.laid_out(page()).unwrap_or_default();
5054 let [left, top, ..] = self.ui.laid_out(self.pane.id).unwrap_or_default();
49545055 let scale = self.ui.scale();
49555056 [(point[0] - left) * scale, (point[1] - top) * scale]
49565057 }
......@@ -5001,6 +5102,13 @@ impl State {
50015102 self.window.request_redraw();
50025103 return;
50035104 }
5105 // A press of either button on a parked pane's page focuses it, then acts there.
5106 if let ui::Event::Button { pressed: true, .. } = event
5107 && let Some(hovered) = self.ui.box_at(self.pointer)
5108 && self.parked.iter().any(|parked| parked.pane.id == hovered)
5109 {
5110 self.ui.set_focus(Some(hovered));
5111 }
50045112 if let ui::Event::Button { pressed: true, .. } = event
50055113 && self.renaming.is_some()
50065114 && self.ui.box_at(self.pointer) != Some(rename::field())
......@@ -5074,16 +5182,17 @@ fn theme(appearance: winit::window::Theme, light_pages: bool, backdrop: bool) ->
50745182 }
50755183}
50765184
5077/// The page's accessibility tree, as changed since `access` last sent it, for the graft at
5078/// the page's box: bounds in the window's pixels, which the interface's scale renders fewer
5079/// of when capped.
5185/// `pane`'s page accessibility tree, as changed since `access` last sent it, for the graft at
5186/// its page box: bounds in the window's pixels, which the interface's scale renders fewer of
5187/// when capped.
50805188fn page_tree(
5081 view: &PageView,
5189 pane: &Pane,
50825190 ui: &Ui,
50835191 window: &Window,
50845192 access: &mut accessibility::Accessibility,
50855193) -> Result<accesskit::TreeUpdate, onestore::page::text::EditError> {
5086 let corner = ui.laid_out(page()).unwrap_or_default();
5194 let view = &pane.view;
5195 let corner = ui.laid_out(pane.id).unwrap_or_default();
50875196 let scale = ui.scale();
50885197 let ratio = window.scale_factor() as f32 / scale;
50895198 let viewport = canvas::gpu::Viewport {
......@@ -6479,7 +6588,7 @@ impl State {
64796588 self.window.request_redraw();
64806589 }
64816590 UserEvent::InsertText(text) => {
6482 if self.ui.focused() == Some(page()) {
6591 if self.ui.focused() == Some(self.pane.id) {
64836592 match self.pane.view.insert_text(text) {
64846593 Ok(response) => self.respond(response),
64856594 Err(error) => eprintln!("{error}"),
......@@ -6589,6 +6698,8 @@ impl State {
65896698 .request_inner_size(LogicalSize::new(width, height));
65906699 }
65916700 Replay::Renderer(_) => unreachable!("The app switches renderers"),
6701 Replay::Split(axis) => self.commands.push(Command::Split(axis)),
6702 Replay::ClosePane => self.commands.push(Command::ClosePane(self.pane.id)),
65926703 }
65936704 // A covered window gets no redraws, so each step draws its own frame.
65946705 if let Err(error) = self.frame() {
......@@ -7102,6 +7213,12 @@ fn replay(script: String, proxy: EventLoopProxy<UserEvent>) -> Result<(), Box<dy
71027213 Ok(Replay::Access(action, label.to_owned()))
71037214 }
71047215 "renderer" => Ok(Replay::Renderer(settings::Backend::named(rest)?)),
7216 "split" => Ok(Replay::Split(match rest {
7217 "right" => Axis::X,
7218 "down" => Axis::Y,
7219 _ => return Err(format!("Unknown split {rest}").into()),
7220 })),
7221 "close" if rest == "pane" => Ok(Replay::ClosePane),
71057222 "appearance" => Ok(Replay::Appearance(match rest {
71067223 "light" => winit::window::Theme::Light,
71077224 "dark" => winit::window::Theme::Dark,
crates/snowbound/src/manage.rs+1-1
......@@ -250,7 +250,7 @@ impl State {
250250 since: now,
251251 requested: now,
252252 })?;
253 self.ui.set_focus(Some(crate::page()));
253 self.ui.set_focus(Some(self.pane.id));
254254 if let Some(title) = self
255255 .pane
256256 .view
crates/snowbound/src/protection.rs+1-1
......@@ -66,7 +66,7 @@ fn notice() -> Id {
6666 Id::ROOT.child("locked-notice")
6767}
6868
69fn section_name(path: &str) -> &str {
69pub(crate) fn section_name(path: &str) -> &str {
7070 let name = path.rsplit('/').next().unwrap_or(path);
7171 name.strip_suffix(".one").unwrap_or(name)
7272}
crates/snowbound/src/recording.rs+9-8
......@@ -57,8 +57,9 @@ pub enum Transport {
5757 SeePlayback,
5858}
5959
60fn seek_field() -> ui::Id {
61 crate::page().child("transport").child("seek")
60/// The Seek To field of the transport over page box `page`.
61fn seek_field(page: ui::Id) -> ui::Id {
62 page.child("transport").child("seek")
6263}
6364
6465impl State {
......@@ -263,8 +264,8 @@ impl State {
263264 }
264265 (Transport::SeekTo, Media::Playing(playback)) => {
265266 playback.seeking = Some(clock(playback.player.position_ms()));
266 self.ui.set_focus(Some(seek_field()));
267 self.ui.focus_all(seek_field());
267 self.ui.set_focus(Some(seek_field(self.pane.id)));
268 self.ui.focus_all(seek_field(self.pane.id));
268269 }
269270 _ => {}
270271 }
......@@ -482,7 +483,7 @@ impl State {
482483 Media::Playing(playback) => &mut playback.seeking,
483484 _ => &mut None,
484485 };
485 let focused = self.ui.focused() == Some(seek_field());
486 let focused = self.ui.focused() == Some(seek_field(self.pane.id));
486487 let Some(text) = seeking.as_mut().filter(|_| focused) else {
487488 *seeking = None;
488489 let playing = matches!(self.media, Media::Playing(_));
......@@ -519,12 +520,12 @@ impl State {
519520 };
520521 let keys = ui::popup::navigation(
521522 &mut self.ui,
522 &[seek_field()],
523 &[seek_field(self.pane.id)],
523524 &[NamedKey::Enter, NamedKey::Escape],
524525 );
525526 ui::text_field(
526527 &mut self.ui,
527 seek_field(),
528 seek_field(self.pane.id),
528529 text,
529530 "m:ss",
530531 Spec {
......@@ -542,7 +543,7 @@ impl State {
542543 .flatten();
543544 if !keys.is_empty() {
544545 *seeking = None;
545 self.ui.set_focus(Some(crate::page()));
546 self.ui.set_focus(Some(self.pane.id));
546547 }
547548 at
548549 }
crates/snowbound/src/rename.rs+1-1
......@@ -126,7 +126,7 @@ impl State {
126126 let Some(Renaming { target, name }) = self.renaming.take() else {
127127 return;
128128 };
129 self.ui.set_focus(Some(crate::page()));
129 self.ui.set_focus(Some(self.pane.id));
130130 let name = name.trim().to_owned();
131131 if !keep || name.is_empty() {
132132 return;
crates/snowbound/src/search.rs+3-3
......@@ -3,7 +3,7 @@
33//! its own, from the section files and the open section's replica.
44
55use crate::task_pane::TaskPane;
6use crate::{Command, Library, State, Theme, art, commands, lap, name, page};
6use crate::{Command, Library, State, Theme, art, commands, lap, name};
77use accesskit::Role;
88use canvas::search::{Entry, Found, Index, PageMatch, Query, page_matches, paragraph_match};
99use notebook::Replica;
......@@ -685,7 +685,7 @@ impl State {
685685 self.search.finding = false;
686686 self.search.current = None;
687687 self.ui.close_popup(results());
688 self.ui.set_focus(Some(page()));
688 self.ui.set_focus(Some(self.pane.id));
689689 if !matches!(self.search.task_pane, Some(TaskPane::Search { .. })) {
690690 self.search.query.clear();
691691 self.search.scope = self.search.default;
......@@ -1120,7 +1120,7 @@ impl State {
11201120 self.open_result(index)?;
11211121 self.search.open = false;
11221122 self.ui.close_popup(results());
1123 self.ui.set_focus(Some(page()));
1123 self.ui.set_focus(Some(self.pane.id));
11241124 }
11251125 Ok(())
11261126 }
crates/snowbound/src/server.rs+1-1
......@@ -835,7 +835,7 @@ impl State {
835835 ui.close();
836836 if cancel {
837837 self.ui.close_popup(id());
838 self.ui.set_focus(Some(crate::page()));
838 self.ui.set_focus(Some(self.pane.id));
839839 self.server = None;
840840 return;
841841 }
crates/snowbound/src/share.rs+2-2
......@@ -590,7 +590,7 @@ impl State {
590590 }
591591 if done {
592592 self.ui.close_popup(share_id());
593 self.ui.set_focus(Some(crate::page()));
593 self.ui.set_focus(Some(self.pane.id));
594594 return;
595595 }
596596 self.peers.share = Some(dialog);
......@@ -661,7 +661,7 @@ impl State {
661661 ui.close();
662662 if cancel {
663663 self.ui.close_popup(join_id());
664 self.ui.set_focus(Some(crate::page()));
664 self.ui.set_focus(Some(self.pane.id));
665665 return;
666666 }
667667 if open && !matches!(dialog.status, Status::Waiting) {
crates/snowbound/src/split.rs+429-3
......@@ -3,13 +3,76 @@
33//! are parked. Panes on one section share its `Session`, since a section's replica opens
44//! once (`locking_mode=EXCLUSIVE`).
55
6use crate::{Command, Library, Loaded, Pane, Session, State};
6use crate::{Command, FRAME, Library, Loaded, Pane, Session, State, art, name, navigation};
7use canvas::{gpu::page::PageScene, interaction::PageView};
8use draw::edit::SelectionUnit;
79use notebook::{Replica, session::Event};
810use onestore::ExGuid;
911use std::{
1012 error::Error,
1113 sync::{Arc, atomic::Ordering},
1214};
15use ui::{Axis, Extent, Flags, Id, Overflow, Size, Spec, Theme, fill, px};
16use winit::window::CursorIcon;
17
18/// The least a pane gives way to another beside it as their divider moves.
19const LEAST: f32 = 160.0;
20
21/// How the page area divides among the panes: all to one, or between two parts side by side
22/// or one above the other, `ratio` of it going to the first.
23pub enum Split {
24 Leaf(Id),
25 Pair {
26 axis: Axis,
27 ratio: f32,
28 a: Box<Split>,
29 b: Box<Split>,
30 },
31}
32
33impl Split {
34 /// The first pane in reading order.
35 fn first(&self) -> Id {
36 match self {
37 Split::Leaf(id) => *id,
38 Split::Pair { a, .. } => a.first(),
39 }
40 }
41
42 /// Divides pane `at`'s room along `axis` with pane `new`, after it.
43 fn divide(&mut self, at: Id, axis: Axis, new: Id) -> bool {
44 match self {
45 Split::Leaf(id) if *id == at => {
46 *self = Split::Pair {
47 axis,
48 ratio: 0.5,
49 a: Box::new(Split::Leaf(at)),
50 b: Box::new(Split::Leaf(new)),
51 };
52 true
53 }
54 Split::Leaf(_) => false,
55 Split::Pair { a, b, .. } => a.divide(at, axis, new) || b.divide(at, axis, new),
56 }
57 }
58
59 /// Gives pane `gone`'s room to the part beside it, and names that part's first pane.
60 fn remove(&mut self, gone: Id) -> Option<Id> {
61 let Split::Pair { a, b, .. } = self else {
62 return None;
63 };
64 let is = |part: &Split| matches!(part, Split::Leaf(id) if *id == gone);
65 let kept = if is(a) {
66 std::mem::replace(&mut **b, Split::Leaf(gone))
67 } else if is(b) {
68 std::mem::replace(&mut **a, Split::Leaf(gone))
69 } else {
70 return a.remove(gone).or_else(|| b.remove(gone));
71 };
72 *self = kept;
73 Some(self.first())
74 }
75}
1376
1477/// A pane out of focus, and the section it shows by `Library::key`; the focused pane's is
1578/// `State::session`.
......@@ -91,9 +154,16 @@ impl State {
91154 });
92155 }
93156
94 /// Closes the parked panes `gone` picks.
157 /// Closes the parked panes `gone` picks, their room going to the parts beside them.
95158 fn close_parked(&mut self, gone: impl Fn(&Parked) -> bool) {
96 self.parked.retain(|parked| !gone(parked));
159 let ids: Vec<Id> = (self.parked.iter())
160 .filter(|parked| gone(parked))
161 .map(|parked| parked.pane.id)
162 .collect();
163 for id in &ids {
164 self.split.remove(*id);
165 }
166 self.parked.retain(|parked| !ids.contains(&parked.pane.id));
97167 }
98168
99169 /// Moves the sections only parked panes show in `library`, a notebook read again, to
......@@ -370,6 +440,362 @@ impl State {
370440 self.commands.push(Command::OpenPage(open));
371441 Ok(true)
372442 }
443
444 /// Gives the focus to the parked pane whose page box the keyboard moved to, as a press on
445 /// it or F6 moves it.
446 pub(crate) fn follow_focus(&mut self) -> Result<(), Box<dyn Error>> {
447 let focused = self.ui.focused();
448 match (self.parked.iter()).position(|parked| Some(parked.pane.id) == focused) {
449 Some(at) => self.focus_pane(at),
450 None => Ok(()),
451 }
452 }
453
454 /// Moves the focus to parked pane `at`. The pane leaving it stores what was typed in it,
455 /// and stops recording.
456 fn focus_pane(&mut self, at: usize) -> Result<(), Box<dyn Error>> {
457 self.stop_recording(true)?;
458 self.pane.view.editor.finish_composition();
459 crate::platform::clear_marked_text(&self.window);
460 self.persist()?;
461 self.pane.page_focused = false;
462 let response = self.pane.view.focus_changed(false)?;
463 self.respond(response);
464 self.swap_pane(at);
465 // The page's tree moves to the pane focused, sent whole.
466 self.accessibility.deactivate();
467 self.page_grafted = false;
468 self.title();
469 self.window.request_redraw();
470 Ok(())
471 }
472
473 /// Shows the focused pane's page in a new pane after it along `axis`, which takes the
474 /// focus.
475 pub(crate) fn split_pane(&mut self, axis: Axis) -> Result<(), Box<dyn Error>> {
476 let Some(session) = &self.session else {
477 return Ok(());
478 };
479 let taken =
480 |id: &Id| *id == self.pane.id || self.parked.iter().any(|parked| parked.pane.id == *id);
481 let id = (1..)
482 .map(|count: u32| Id::ROOT.child(("page", count)))
483 .find(|id| !taken(id))
484 .ok_or("No pane is left to make")?;
485 let (showing, section) = (self.pane.showing, Some(session.key()));
486 let page = match showing.version {
487 Some(version) => session.version_reader(showing.space, version)()?,
488 None => session.reader(showing.space)()?,
489 };
490 let shown = &self.pane.view;
491 let mut engine = shown.engine.clone();
492 let (scene, editor) = PageScene::from_page(page, &mut engine)?;
493 let size = shown.viewport.size;
494 let double_click = crate::platform::double_click_interval();
495 let scene = Some((scene, [0.0; 2]));
496 let scale = self.ui.scale();
497 let mut view = PageView::new(editor, engine, scene, size, scale, double_click);
498 view.viewport = shown.viewport;
499 view.spelling.clone_from(&shown.spelling);
500 view.snap_to_grid = shown.snap_to_grid;
501 view.editor.styles = shown.editor.styles.clone();
502 view.tag_art = shown.tag_art.clone();
503 let pane = Pane {
504 id,
505 view,
506 showing,
507 loading: 0,
508 opening: None,
509 switching: None,
510 trail: navigation::Trail::default(),
511 stale: false,
512 page_focused: false,
513 sectionless: None,
514 locked: None,
515 refused: Arc::default(),
516 };
517 self.parked.push(Parked { pane, section });
518 self.split.divide(self.pane.id, axis, id);
519 self.focus_pane(self.parked.len() - 1)?;
520 self.visited();
521 self.ui.set_focus(Some(self.pane.id));
522 Ok(())
523 }
524
525 /// Closes pane `id`, its room going to the part beside it; the first pane there takes the
526 /// focus where the pane closed had it. The only pane stays.
527 pub(crate) fn close_pane(&mut self, id: Id) -> Result<(), Box<dyn Error>> {
528 let Some(next) = self.split.remove(id) else {
529 return Ok(());
530 };
531 if id == self.pane.id {
532 let at = (self.parked.iter())
533 .position(|parked| parked.pane.id == next)
534 .ok_or("No pane takes the focus")?;
535 self.focus_pane(at)?;
536 self.ui.set_focus(Some(self.pane.id));
537 }
538 let at = (self.parked.iter())
539 .position(|parked| parked.pane.id == id)
540 .ok_or("No such pane")?;
541 let Parked { pane, section } = self.parked.swap_remove(at);
542 let Some(key) = section else {
543 return Ok(());
544 };
545 let space = pane.showing.space;
546 self.places.insert((key.clone(), space), pane.view.place());
547 let focused = self.session.as_ref().filter(|session| session.key() == key);
548 // The focused pane's page stays the section's last.
549 if focused.is_none() {
550 self.last_pages.insert(key.clone(), space);
551 }
552 let session = focused.or(self.shelved.iter().find(|session| session.key() == key));
553 // A page another pane still shows keeps that pane's history.
554 if session.is_some_and(|session| !session.read_only(&pane.showing))
555 && !self.shown_parked(&key, space)
556 && (focused.is_none() || self.pane.showing.space != space)
557 {
558 self.undo.park(space, pane.view.editor);
559 }
560 if !(self.parked.iter()).any(|parked| parked.section.as_ref() == Some(&key))
561 && let Some(session) = self.unshelve(&key)
562 {
563 self.release(session);
564 }
565 Ok(())
566 }
567
568 /// Builds the panes in the page area's box, as the split divides them; whether the
569 /// focused one shows a page.
570 pub(crate) fn panes(&mut self, theme: &Theme) -> Result<bool, Box<dyn Error>> {
571 if self.parked.is_empty() {
572 return self.pane_content(theme);
573 }
574 let mut split = std::mem::replace(&mut self.split, Split::Leaf(self.pane.id));
575 let shown = self.part(&mut split, "panes", [fill(), fill()], theme);
576 self.split = split;
577 shown
578 }
579
580 /// Builds `split`, `size` big, as box `part`; whether the focused pane in it shows a page.
581 fn part(
582 &mut self,
583 split: &mut Split,
584 part: &str,
585 size: [Extent; 2],
586 theme: &Theme,
587 ) -> Result<bool, Box<dyn Error>> {
588 let (axis, ratio, a, b) = match split {
589 Split::Leaf(id) => return self.leaf(*id, part, size, theme),
590 Split::Pair { axis, ratio, a, b } => (axis, ratio, a, b),
591 };
592 let along = usize::from(*axis == Axis::Y);
593 let id = self.ui.open(
594 part,
595 Spec {
596 axis: *axis,
597 size,
598 ..Spec::default()
599 },
600 );
601 let share = |fraction: f32| {
602 let mut size = [fill(); 2];
603 size[along] = Extent {
604 size: Size::Fraction(fraction),
605 strictness: 0.0,
606 };
607 size
608 };
609 let mut shown = self.part(a, "a", share(*ratio), theme)?;
610 let mut thin = [fill(); 2];
611 thin[along] = px(FRAME);
612 let divider = self.ui.open(
613 "divider",
614 Spec {
615 flags: Flags::CLICKABLE,
616 size: thin,
617 cursor: Some(match axis {
618 Axis::X => CursorIcon::ColResize,
619 Axis::Y => CursorIcon::RowResize,
620 }),
621 ..Spec::default()
622 },
623 );
624 self.ui.close();
625 shown |= self.part(b, "b", share(1.0 - *ratio), theme)?;
626 self.ui.close();
627 let signal = self.ui.signal(divider);
628 if signal.pressed && signal.unit != SelectionUnit::Grapheme {
629 *ratio = 0.5;
630 } else if signal.dragging
631 && let (Some(pointer), Some(rect)) = (self.ui.pointer(), self.ui.laid_out(id))
632 {
633 let length = rect[along + 2] - rect[along] - FRAME;
634 let least = (LEAST / length).min(0.5);
635 let at = (pointer[along] - rect[along] - FRAME / 2.0) / length;
636 *ratio = at.clamp(least, 1.0 - least);
637 }
638 Ok(shown)
639 }
640
641 /// Builds pane `id`, `size` big, as box `part`: a group named for what it shows, under a
642 /// header with its close button; whether it is the focused pane showing a page.
643 fn leaf(
644 &mut self,
645 id: Id,
646 part: &str,
647 size: [Extent; 2],
648 theme: &Theme,
649 ) -> Result<bool, Box<dyn Error>> {
650 let parked = (self.parked.iter()).position(|parked| parked.pane.id == id);
651 let (section, page) = match parked {
652 Some(at) => {
653 let parked = &self.parked[at];
654 let key = parked.section.as_ref();
655 let session = self.sessions().find(|session| Some(&session.key()) == key);
656 label(&parked.pane, session)
657 }
658 None => label(&self.pane, self.session.as_ref()),
659 };
660 let leaf = self.ui.open(
661 part,
662 Spec {
663 axis: Axis::Y,
664 size,
665 role: Some(accesskit::Role::Group),
666 ..Spec::default()
667 },
668 );
669 if let Some(node) = self.ui.access(leaf) {
670 node.set_label(format!("{section}, {page}"));
671 }
672 let header = format!("{section} · {page}");
673 self.ui.open(
674 "header",
675 Spec {
676 size: [fill(), px(ui::shell::TOOL)],
677 ..Spec::default()
678 },
679 );
680 self.ui.leaf(
681 "title",
682 Spec {
683 size: [fill(), px(ui::shell::TOOL)],
684 text: Some(&header),
685 overflow: Overflow::Ellipsis,
686 bold: parked.is_none(),
687 pad: [4.0, 0.0],
688 ..Spec::default()
689 },
690 );
691 let close = ui::shell::tool_button(&mut self.ui, "close", art::CLOSE, theme.text_dim, None);
692 let button = self.ui.id("close");
693 name(&mut self.ui, button, "Close Pane");
694 self.ui.close();
695 if close.clicked {
696 self.commands.push(Command::ClosePane(id));
697 }
698 let shown = match parked {
699 Some(at) => {
700 self.parked_page(at)?;
701 false
702 }
703 None => self.pane_content(theme)?,
704 };
705 self.ui.close();
706 Ok(shown)
707 }
708
709 /// Parked pane `at`'s page, which the wheel scrolls and a press focuses; a pane without
710 /// a page shows bare paper.
711 fn parked_page(&mut self, at: usize) -> Result<(), Box<dyn Error>> {
712 let Parked { pane, section } = &self.parked[at];
713 let paper = pane.paper(&self.ui.theme);
714 let id = pane.id;
715 let shown = section.is_some();
716 self.ui.open_as(
717 id,
718 Spec {
719 flags: Flags::FOCUSABLE
720 | if shown {
721 Flags::CUSTOM
722 } else {
723 Flags::CLICKABLE
724 },
725 size: [fill(), fill()],
726 fill: Some(paper.color),
727 role: Some(accesskit::Role::GenericContainer),
728 ..Spec::default()
729 },
730 );
731 if shown {
732 let view = &self.parked[at].pane.view;
733 let scroll = view.scroll();
734 let (origin, size) = (view.viewport.origin, view.viewport.size);
735 for (index, axis) in [Axis::X, Axis::Y].into_iter().enumerate() {
736 if let Some(offset) = ui::scrollbar(
737 &mut self.ui,
738 index,
739 axis,
740 -origin[index],
741 [scroll.min[index], scroll.max[index]],
742 size[index] as f32,
743 scroll.max[1 - index] > scroll.min[1 - index],
744 [0.18, 0.18, 0.18, 0.45],
745 ) {
746 let _ = self.parked[at].pane.view.scroll_to(index, offset)?;
747 self.window.request_redraw();
748 }
749 }
750 }
751 self.ui.close();
752 let scale = self.ui.scale();
753 let corner = self.ui.laid_out(id).unwrap_or_default();
754 let view = &mut self.parked[at].pane.view;
755 for event in self.ui.signal(id).events {
756 let response = match event {
757 ui::Event::PointerMoved([x, y]) => {
758 view.pointer_moved([(x - corner[0]) * scale, (y - corner[1]) * scale])?
759 }
760 ui::Event::PointerLeft => view.pointer_left(),
761 ui::Event::Wheel([x, y]) => view.wheel([x * scale, y * scale])?,
762 ui::Event::Modifiers(modifiers) => {
763 view.modifiers_changed(ui::edit_modifiers(modifiers))?
764 }
765 _ => continue,
766 };
767 if response.changed || response.moved {
768 self.window.request_redraw();
769 }
770 }
771 Ok(())
772 }
773}
774
775/// What `pane` shows of `session`, its section and page, as its header names them.
776fn label(pane: &Pane, session: Option<&Session>) -> (String, String) {
777 match session {
778 Some(session) => {
779 let title = session.title(pane.showing.space);
780 (
781 session.tabs[session.tab].name.clone(),
782 if title.is_empty() {
783 "Untitled page"
784 } else {
785 title
786 }
787 .to_owned(),
788 )
789 }
790 None => match (&pane.locked, &pane.sectionless) {
791 (Some(locked), _) => (
792 crate::protection::section_name(&locked.path).to_owned(),
793 "Locked".to_owned(),
794 ),
795 (None, Some(library)) => (library.name.clone(), "No sections".to_owned()),
796 (None, None) => (String::new(), String::new()),
797 },
798 }
373799}
374800
375801/// Shows `library`'s section at catalog `path`, which a parked pane holds open through
crates/snowbound/src/tags.rs+1-1
......@@ -578,7 +578,7 @@ impl State {
578578 return;
579579 }
580580 self.ui.close_popup(id());
581 self.ui.set_focus(Some(crate::page()));
581 self.ui.set_focus(Some(self.pane.id));
582582 self.tag_list = None;
583583 }
584584}
crates/snowbound/src/task_pane.rs+4-4
......@@ -3,7 +3,7 @@
33//! Spelling (F7), walking the page's marked words.
44
55use crate::search::{Scope, marked};
6use crate::{State, Theme, art, page, platform};
6use crate::{State, Theme, art, platform};
77use canvas::gpu::tag_sources;
88use canvas::outline::TagIcon;
99use canvas::search::{Found, Tagged};
......@@ -673,7 +673,7 @@ impl State {
673673 ],
674674 );
675675 if keys.contains(&NamedKey::Escape) {
676 self.ui.set_focus(Some(page()));
676 self.ui.set_focus(Some(self.pane.id));
677677 }
678678 let border = if self.ui.focused() == Some(field()) {
679679 theme.accent
......@@ -824,7 +824,7 @@ impl State {
824824 let found = &self.search.found[order[row]];
825825 self.reveal(found.section.clone(), found.space, None)?;
826826 if clicked.is_some() || keys.contains(&NamedKey::Enter) {
827 self.ui.set_focus(Some(page()));
827 self.ui.set_focus(Some(self.pane.id));
828828 }
829829 }
830830 Ok(())
......@@ -922,7 +922,7 @@ impl State {
922922 {
923923 eprintln!("{error}");
924924 }
925 self.ui.set_focus(Some(page()));
925 self.ui.set_focus(Some(self.pane.id));
926926 }
927927 }
928928
crates/snowbound/src/templates.rs+8-4
......@@ -174,11 +174,13 @@ fn strip(
174174 (chosen, solid)
175175}
176176
177/// Dialog `id`, titled `title`, of every template docked inside the page box's trailing edge,
178/// `height` tall, while it is open. Returns the template chosen; it stays open to choose again.
177/// Dialog `id`, titled `title`, of every template docked inside page box `page`'s trailing
178/// edge, `height` tall, while it is open. Returns the template chosen; it stays open to choose
179/// again.
179180#[allow(clippy::too_many_arguments)]
180181fn gallery(
181182 ui: &mut Ui,
183 page: Id,
182184 theme: &Theme,
183185 thumbnails: &mut Thumbnails,
184186 paper: Paper,
......@@ -202,7 +204,7 @@ fn gallery(
202204 radius: 8.0,
203205 pad: [PAD, PAD],
204206 gap: 8.0,
205 anchor: Some(Anchor::Dock(crate::page())),
207 anchor: Some(Anchor::Dock(page)),
206208 role: Some(accesskit::Role::Dialog),
207209 ..Spec::default()
208210 },
......@@ -389,7 +391,7 @@ impl crate::State {
389391 };
390392 let space = self.pane.showing.space;
391393 let read_only = session.read_only(&self.pane.showing);
392 let Some(rect) = self.ui.laid_out(crate::page()) else {
394 let Some(rect) = self.ui.laid_out(self.pane.id) else {
393395 return;
394396 };
395397 // Thumbnails show templates on plain paper, not the page's colour.
......@@ -400,6 +402,7 @@ impl crate::State {
400402 let height = rect[3] - rect[1] - 8.0;
401403 if let Some(name) = gallery(
402404 &mut self.ui,
405 self.pane.id,
403406 theme,
404407 &mut self.thumbnails,
405408 paper,
......@@ -447,6 +450,7 @@ impl crate::State {
447450 }
448451 if let Some(name) = gallery(
449452 &mut self.ui,
453 self.pane.id,
450454 theme,
451455 &mut self.thumbnails,
452456 paper,
crates/snowbound/src/web.rs+2-2
......@@ -3,7 +3,7 @@
33//! event loop are stand-ins with the calls `State` makes of winit's; menus are the kit's own,
44//! as on Linux; the browser's chords stay the browser's. See arc/platforms.md.
55
6use crate::{Reply, State, UserEvent, commands, page, settings};
6use crate::{Reply, State, UserEvent, commands, settings};
77use canvas::date::DateField;
88use std::{
99 cell::{Cell, RefCell},
......@@ -1816,7 +1816,7 @@ pub fn dictionary_arrived(name: String, affix: String, words: String) {
18161816/// Parks the text area while the page takes no text, keeping it writable for the
18171817/// interface's fields.
18181818fn park_input(state: &State) {
1819 if state.ui.focused() != Some(page()) || !state.pane.view.accepts_text() {
1819 if state.ui.focused() != Some(state.pane.id) || !state.pane.view.accepts_text() {
18201820 place_input(0.0, 0.0, 1.0, state.ui.focused().is_some());
18211821 }
18221822}
crates/snowbound/tests/replay.rs+262
......@@ -1524,3 +1524,265 @@ fn an_icloud_notebook_offers_delete_in_place_of_close() {
15241524 "{menu}"
15251525 );
15261526}
1527
1528/// The line of `tree` that starts, past its indent, with `start`.
1529fn line<'a>(tree: &'a str, start: &str) -> &'a str {
1530 tree.lines()
1531 .find(|line| line.trim_start().starts_with(start))
1532 .unwrap_or_else(|| panic!("no {start:?} in:\n{tree}"))
1533}
1534
1535/// Split, each pane is a group named for its section and page, and the window's title, the
1536/// section tabs and the zoom follow the pane focused.
1537#[test]
1538fn split_panes_are_named_groups_and_the_chrome_follows_focus() {
1539 let scratch = Scratch::new("split-focus");
1540 let notebook = Path::new(env!("CARGO_MANIFEST_DIR")).join("../../corpus/search/notebook");
1541 let steps = [
1542 "split right",
1543 "settle",
1544 // The Reading tab, which opens in the pane split off, then zoomed in.
1545 "move 311 51",
1546 "press",
1547 "release",
1548 "settle",
1549 "modifiers command",
1550 "key =",
1551 "modifiers",
1552 "settle",
1553 "accessibility right",
1554 "move 177 300",
1555 "press",
1556 "release",
1557 "settle",
1558 "accessibility left",
1559 // The Reading tab again, now in the pane on Garden, while only the other shows it.
1560 "move 311 51",
1561 "press",
1562 "release",
1563 "settle",
1564 "accessibility held",
1565 ];
1566 let [right, left, held] = replay(&scratch, Some(&notebook), &steps)
1567 .try_into()
1568 .unwrap();
1569 for tree in [&right, &left] {
1570 let groups: Vec<_> = (tree.lines())
1571 .filter(|line| line.starts_with(" Group "))
1572 .collect();
1573 assert_eq!(
1574 groups,
1575 [
1576 r#" Group "Garden, Spring planting plan""#,
1577 r#" Group "Reading, Reading now""#
1578 ],
1579 "{tree}"
1580 );
1581 }
1582 assert_eq!(
1583 line(&right, "Window"),
1584 r#"Window "Reading now · Reading.one""#
1585 );
1586 assert_eq!(
1587 line(&right, "Tab \"Reading\""),
1588 r#" Tab "Reading" [selected]"#
1589 );
1590 assert_ne!(
1591 line(&right, "Button \"Zoom\""),
1592 r#" Button "Zoom" = "100%""#
1593 );
1594 assert_eq!(
1595 line(&left, "Window"),
1596 r#"Window "Spring planting plan · Garden.one""#
1597 );
1598 assert_eq!(
1599 line(&left, "Tab \"Garden\""),
1600 r#" Tab "Garden" [selected]"#
1601 );
1602 assert_eq!(
1603 line(&left, "Button \"Zoom\""),
1604 r#" Button "Zoom" = "100%""#
1605 );
1606 // The section opens from the pane holding it, not its file again, which waits for it.
1607 assert_eq!(
1608 pane_groups(&held),
1609 [
1610 r#" Group "Reading, Reading now""#,
1611 r#" Group "Reading, Reading now""#
1612 ],
1613 "{held}"
1614 );
1615 assert_eq!(
1616 line(&held, "Window"),
1617 r#"Window "Reading now · Reading.one""#
1618 );
1619}
1620
1621/// The groups at the top of `tree`: a split pane's each, or the one pane's page.
1622fn pane_groups(tree: &str) -> Vec<&str> {
1623 (tree.lines())
1624 .filter(|line| line.starts_with(" Group "))
1625 .collect()
1626}
1627
1628/// The line of `tree` holding the focused pane's page title.
1629fn page_title(tree: &str) -> &str {
1630 line(tree, "MultilineTextInput \"Page title\"")
1631}
1632
1633/// What is typed in one pane shows at once in another on the page, which takes it in place.
1634#[test]
1635fn an_edit_in_one_pane_shows_in_another_on_the_page() {
1636 let scratch = Scratch::new("split-edit");
1637 let notebook = Path::new(env!("CARGO_MANIFEST_DIR")).join("../../corpus/search/notebook");
1638 let steps = [
1639 "split right",
1640 "settle",
1641 // Into the title of the pane split off, then back to the first.
1642 "move 649 129",
1643 "press",
1644 "release",
1645 "type Both ",
1646 "settle",
1647 "move 177 300",
1648 "press",
1649 "release",
1650 "settle",
1651 "accessibility left",
1652 ];
1653 let [left] = replay(&scratch, Some(&notebook), &steps)
1654 .try_into()
1655 .unwrap();
1656 assert!(page_title(&left).contains("Both "), "{left}");
1657}
1658
1659/// Undoing a page's new name, done away from the frame, shows in every pane on the page,
1660/// so none writes the old name back.
1661#[test]
1662fn undoing_a_rename_shows_in_every_pane_on_the_page() {
1663 let scratch = Scratch::new("split-undo");
1664 let notebook = Path::new(env!("CARGO_MANIFEST_DIR")).join("../../corpus/search/notebook");
1665 let steps = [
1666 "split right",
1667 "settle",
1668 // A double click on the page's tab renames it.
1669 "move 1003 81",
1670 "press",
1671 "release",
1672 "press",
1673 "release",
1674 "settle",
1675 "type Renamed",
1676 "key Enter",
1677 "settle",
1678 "modifiers command",
1679 "key z",
1680 "modifiers",
1681 "settle",
1682 "move 177 300",
1683 "press",
1684 "release",
1685 "settle",
1686 "accessibility left",
1687 ];
1688 let [left] = replay(&scratch, Some(&notebook), &steps)
1689 .try_into()
1690 .unwrap();
1691 assert!(
1692 page_title(&left).ends_with(r#"= "Spring planting plan""#),
1693 "{left}"
1694 );
1695}
1696
1697/// A page's version shown beside the page stays as it was while the page is edited.
1698#[test]
1699fn a_version_beside_its_page_keeps_its_text() {
1700 let scratch = Scratch::new("split-version");
1701 let notebook =
1702 Path::new(env!("CARGO_MANIFEST_DIR")).join("../../corpus/page-versions/candidate-restore");
1703 let mut steps: Vec<String> = ["split right", "settle"].map(String::from).to_vec();
1704 // The version row under the page, opened in the pane split off.
1705 steps.extend(["modifiers command shift", "key p", "modifiers"].map(String::from));
1706 steps.extend(["type Page Versions", "settle", "key Enter", "settle"].map(String::from));
1707 steps.extend(["move 1003 114", "press", "release", "settle"].map(String::from));
1708 // Typing in the page, in the first pane, then back to the version.
1709 steps.extend(["move 177 200", "press", "release", "settle"].map(String::from));
1710 steps.extend(["type Zebra ", "accessibility page"].map(String::from));
1711 steps.extend(["move 640 300", "press", "release", "settle"].map(String::from));
1712 steps.push("accessibility version".into());
1713 let [page, version] = run(&scratch, &notebook, &steps).try_into().unwrap();
1714 let outline = "MultilineTextInput \"Text outline 1\"";
1715 assert!(line(&page, outline).contains("Zebra"), "{page}");
1716 let text = line(&version, outline);
1717 assert!(
1718 text.contains("Second author line") && !text.contains("Zebra"),
1719 "{version}"
1720 );
1721}
1722
1723/// A version deleted in one pane leaves the other pane showing it for the page itself.
1724#[test]
1725fn a_version_deleted_in_one_pane_leaves_the_other() {
1726 let scratch = Scratch::new("split-delete-version");
1727 let notebook =
1728 Path::new(env!("CARGO_MANIFEST_DIR")).join("../../corpus/page-versions/candidate-restore");
1729 let mut versions: Vec<String> = ["modifiers command shift", "key p", "modifiers"]
1730 .into_iter()
1731 .chain(["type Page Versions", "settle", "key Enter", "settle"])
1732 // The version row under the page.
1733 .chain(["move 1003 114", "press", "release", "settle"])
1734 .map(String::from)
1735 .collect();
1736 let mut steps: Vec<String> = vec!["split right".into(), "settle".into()];
1737 steps.append(&mut versions.clone());
1738 steps.extend(["move 177 300", "press", "release", "settle"].map(String::from));
1739 steps.append(&mut versions);
1740 // Delete Version on the first pane's bar, then back to the other.
1741 steps.extend(["move 177 116", "press", "release", "settle"].map(String::from));
1742 steps.extend(["key Down", "key Down", "key Enter", "settle"].map(String::from));
1743 steps.extend(["move 640 300", "press", "release", "settle"].map(String::from));
1744 steps.push("accessibility other".into());
1745 let [other] = run(&scratch, &notebook, &steps).try_into().unwrap();
1746 assert!(
1747 line(&other, "MultilineTextInput \"Text outline 1\"")
1748 .ends_with(r#"= "First state. Typed by virtual.""#),
1749 "{other}"
1750 );
1751 assert!(other.contains(r#"Tab "Versioned" [selected]"#), "{other}");
1752}
1753
1754/// Closing the panes split off leaves the window drawn as it was before the split.
1755#[test]
1756fn closing_split_panes_leaves_the_window_as_it_was() {
1757 let scratch = Scratch::new("split-close");
1758 let notebook =
1759 Path::new(env!("CARGO_MANIFEST_DIR")).join("../../corpus/cross-container/candidate");
1760 let [before, after] = ["before", "after"].map(|name| scratch.0.join(format!("{name}.png")));
1761 let snapshot = |path: &Path| format!("snapshot {}", path.display());
1762 let steps = [
1763 "appearance light".to_owned(),
1764 // Colours ease into the appearance.
1765 "wait 1500".into(),
1766 "settle".into(),
1767 snapshot(&before),
1768 "split right".into(),
1769 "settle".into(),
1770 "split down".into(),
1771 "settle".into(),
1772 "close pane".into(),
1773 "settle".into(),
1774 "close pane".into(),
1775 "wait 1500".into(),
1776 "settle".into(),
1777 snapshot(&after),
1778 "settle".into(),
1779 ];
1780 let steps: Vec<_> = steps.iter().map(String::as_str).collect();
1781 replay(&scratch, Some(&notebook), &steps);
1782 assert!(
1783 std::fs::read(&before).unwrap() == std::fs::read(&after).unwrap(),
1784 "the window changed: {} {}",
1785 before.display(),
1786 after.display()
1787 );
1788}