| author | |
| committer | |
| log | c3f000fe161ab495e3e0123a1c79cfc438c1fe72 |
| tree | a3920ca313380e17ad0dd9acff4b0033fd00d766 |
| parent | 2793455970b9dbe108f5103c69802fc459b30298 |
| signature | Signed by SSH key SHA256:52mNGHRsVFBDED9IAX5pe+LRWUefqTbxEReunq21QvU |
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.517 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< |
| 41 | 41 | .into_iter() |
| 42 | 42 | .collect(); |
| 43 | 43 | ui.open_as( |
| 44 | page(), | |
| 44 | Id::ROOT.child("page"), | |
| 45 | 45 | Spec { |
| 46 | 46 | flags: Flags::CUSTOM, |
| 47 | 47 | size: [fill(), fill()], |
| ... | ... | @@ -87,7 +87,7 @@ fn paint( |
| 87 | 87 | queue: &wgpu::Queue, |
| 88 | 88 | ) -> Vec<u8> { |
| 89 | 89 | 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(); | |
| 91 | 91 | let box_size = [ |
| 92 | 92 | ((corner[2] - corner[0]) * SCALE) as u32, |
| 93 | 93 | ((corner[3] - corner[1]) * SCALE) as u32, |
crates/snowbound/src/link.rs+2-2| ... | ... | @@ -2,7 +2,7 @@ |
| 2 | 2 | //! the page's context menu, and following a clicked link, to a page |
| 3 | 3 | //! of the notebook or with the system's handler. |
| 4 | 4 | |
| 5 | use crate::{Command, State, art, commands, page, platform}; | |
| 5 | use crate::{Command, State, art, commands, platform}; | |
| 6 | 6 | use canvas::interaction::Context; |
| 7 | 7 | use onestore::ExGuid; |
| 8 | 8 | use onestore::page::link::{LinkTarget, internal_link}; |
| ... | ... | @@ -245,7 +245,7 @@ impl State { |
| 245 | 245 | return Ok(()); |
| 246 | 246 | } |
| 247 | 247 | self.ui.close_popup(id()); |
| 248 | self.ui.set_focus(Some(page())); | |
| 248 | self.ui.set_focus(Some(self.pane.id)); | |
| 249 | 249 | self.link = None; |
| 250 | 250 | Ok(()) |
| 251 | 251 | } |
crates/snowbound/src/live.rs+3-3| ... | ... | @@ -6,7 +6,7 @@ |
| 6 | 6 | //! this computer to whoever types its code (`Host`), or opens one another computer shares |
| 7 | 7 | //! (`Joined`), as `share.rs`'s dialogs start them. |
| 8 | 8 | |
| 9 | use crate::{Command, Library, Session, State, TAB_ROW, page, platform, settings}; | |
| 9 | use crate::{Command, Library, Session, State, TAB_ROW, platform, settings}; | |
| 10 | 10 | use canvas::{document::TextPosition, editor::TextOutline}; |
| 11 | 11 | use notebook::live::{ |
| 12 | 12 | self, Caret, Hello, Peer, Reach, Room, Spot, |
| ... | ... | @@ -920,7 +920,7 @@ impl State { |
| 920 | 920 | let Some(session) = &self.session else { |
| 921 | 921 | return; |
| 922 | 922 | }; |
| 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 { | |
| 924 | 924 | return; |
| 925 | 925 | }; |
| 926 | 926 | let here = (section(session), Some(self.pane.showing.space.into())); |
| ... | ... | @@ -1044,7 +1044,7 @@ impl State { |
| 1044 | 1044 | [x0, y0, y1]: [f32; 3], |
| 1045 | 1045 | selection: &[[f32; 4]], |
| 1046 | 1046 | ) { |
| 1047 | let Some([left, top, ..]) = self.ui.laid_out(page()) else { | |
| 1047 | let Some([left, top, ..]) = self.ui.laid_out(self.pane.id) else { | |
| 1048 | 1048 | return; |
| 1049 | 1049 | }; |
| 1050 | 1050 | let id = peer.hello.peer; |
crates/snowbound/src/main.rs+236-119| ... | ... | @@ -426,6 +426,10 @@ enum Replay { |
| 426 | 426 | Resize([f32; 2]), |
| 427 | 427 | /// Draws with this backend from then on, as Options' Renderer does. |
| 428 | 428 | 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, | |
| 429 | 433 | Quit, |
| 430 | 434 | } |
| 431 | 435 | |
| ... | ... | @@ -542,6 +546,9 @@ fn icloud_listed(proxy: EventLoopProxy<UserEvent>) -> impl Fn() + Send + Sync + |
| 542 | 546 | |
| 543 | 547 | /// A page view, and which page, locked section or empty notebook it shows. |
| 544 | 548 | struct 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, | |
| 545 | 552 | view: PageView, |
| 546 | 553 | showing: Showing, |
| 547 | 554 | /// The newest read requested; older ones are dropped when they finish. |
| ... | ... | @@ -566,7 +573,7 @@ struct Pane { |
| 566 | 573 | } |
| 567 | 574 | |
| 568 | 575 | /// 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)] | |
| 570 | 577 | struct Showing { |
| 571 | 578 | space: ExGuid, |
| 572 | 579 | /// The version of page `space` open, by its context. |
| ... | ... | @@ -761,6 +768,15 @@ struct Opening { |
| 761 | 768 | const HOLD: std::time::Duration = std::time::Duration::from_millis(200); |
| 762 | 769 | |
| 763 | 770 | impl 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 | ||
| 764 | 780 | /// The page opening here, once the pictures it shows first are drawn on `paper` or |
| 765 | 781 | /// `HOLD` has passed. |
| 766 | 782 | fn opened(&mut self, paper: canvas::gpu::Paper, redraw: &std::task::Waker) -> Option<Opening> { |
| ... | ... | @@ -859,6 +875,10 @@ enum Command { |
| 859 | 875 | Page(Request), |
| 860 | 876 | /// Runs a command, or one of a list's entries, after the frame's input. |
| 861 | 877 | 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), | |
| 862 | 882 | } |
| 863 | 883 | |
| 864 | 884 | struct State { |
| ... | ... | @@ -899,6 +919,8 @@ struct State { |
| 899 | 919 | /// The focused pane, which the chrome around the page area follows. |
| 900 | 920 | pane: Pane, |
| 901 | 921 | parked: Vec<split::Parked>, |
| 922 | /// How the panes divide the page area. | |
| 923 | split: split::Split, | |
| 902 | 924 | /// The open notebooks in the sidebar's order. |
| 903 | 925 | notebooks: Vec<Arc<Library>>, |
| 904 | 926 | /// The section the focused pane shows. |
| ... | ... | @@ -1070,12 +1092,6 @@ fn tab_row() -> Id { |
| 1070 | 1092 | Id::ROOT.child("tab row") |
| 1071 | 1093 | } |
| 1072 | 1094 | |
| 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. | |
| 1075 | fn page() -> Id { | |
| 1076 | Id::ROOT.child("page") | |
| 1077 | } | |
| 1078 | ||
| 1079 | 1095 | /// The section's colour around the page and its tabs. |
| 1080 | 1096 | fn frame() -> Id { |
| 1081 | 1097 | Id::ROOT.child("frame") |
| ... | ... | @@ -1351,7 +1367,8 @@ impl State { |
| 1351 | 1367 | // A window shown but never focused hears no focus event; a hidden one draws as focused. |
| 1352 | 1368 | ui.window_focused = !visible || window.has_focus(); |
| 1353 | 1369 | ui.fall_back_to(&fallbacks); |
| 1354 | ui.set_focus(Some(page())); | |
| 1370 | let page = Id::ROOT.child("page"); | |
| 1371 | ui.set_focus(Some(page)); | |
| 1355 | 1372 | for family in FONTS { |
| 1356 | 1373 | for (face, _) in engine.substitute(family).map_or(&[][..], |s| &s.faces) { |
| 1357 | 1374 | ui.preview_font(face.clone(), family); |
| ... | ... | @@ -1394,6 +1411,7 @@ impl State { |
| 1394 | 1411 | unavailable, |
| 1395 | 1412 | ui, |
| 1396 | 1413 | pane: Pane { |
| 1414 | id: page, | |
| 1397 | 1415 | view: PageView::new( |
| 1398 | 1416 | editor, |
| 1399 | 1417 | engine, |
| ... | ... | @@ -1414,6 +1432,7 @@ impl State { |
| 1414 | 1432 | locked, |
| 1415 | 1433 | }, |
| 1416 | 1434 | parked: Vec::new(), |
| 1435 | split: split::Split::Leaf(page), | |
| 1417 | 1436 | notebooks, |
| 1418 | 1437 | session, |
| 1419 | 1438 | shelved: Vec::new(), |
| ... | ... | @@ -1622,9 +1641,15 @@ impl State { |
| 1622 | 1641 | platform::resize_direction(&self.window, self.pointer) |
| 1623 | 1642 | .map(CursorIcon::from) |
| 1624 | 1643 | .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 | }), | |
| 1626 | 1651 | ); |
| 1627 | let ime = if self.ui.focused() == Some(page()) { | |
| 1652 | let ime = if self.ui.focused() == Some(self.pane.id) { | |
| 1628 | 1653 | self.pane.view.accepts_text() |
| 1629 | 1654 | } else { |
| 1630 | 1655 | search::takes_text(self.ui.focused()) |
| ... | ... | @@ -1711,16 +1736,26 @@ impl State { |
| 1711 | 1736 | |_| [0.0; 4], |
| 1712 | 1737 | ); |
| 1713 | 1738 | } |
| 1714 | if let Some(rect) = self.ui.laid_out(page()) { | |
| 1715 | let size = [ | |
| 1739 | let sized = |rect: [f32; 4]| { | |
| 1740 | [ | |
| 1716 | 1741 | ((rect[2] - rect[0]) * scale).round() as u32, |
| 1717 | 1742 | ((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); | |
| 1719 | 1747 | if size != self.pane.view.viewport.size { |
| 1720 | 1748 | let response = self.pane.view.resized(size)?; |
| 1721 | 1749 | self.respond(response); |
| 1722 | 1750 | } |
| 1723 | 1751 | } |
| 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 | } | |
| 1724 | 1759 | Ok(()) |
| 1725 | 1760 | } |
| 1726 | 1761 | |
| ... | ... | @@ -1746,6 +1781,7 @@ impl State { |
| 1746 | 1781 | /// Builds the frame's boxes and returns the section's colours as they ease, the open |
| 1747 | 1782 | /// section tab and the open page's tab, for the edges drawn once they are laid out. |
| 1748 | 1783 | fn build(&mut self) -> Result<(ui::Section, Id, Option<Id>), Box<dyn Error>> { |
| 1784 | self.follow_focus()?; | |
| 1749 | 1785 | let target = self.ui.theme.section(section_color( |
| 1750 | 1786 | self.session |
| 1751 | 1787 | .as_ref() |
| ... | ... | @@ -2040,6 +2076,43 @@ impl State { |
| 2040 | 2076 | ..Spec::default() |
| 2041 | 2077 | }, |
| 2042 | 2078 | ); |
| 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>> { | |
| 2043 | 2116 | if let Some(session) = &self.session |
| 2044 | 2117 | && let Some(bar) = session.bar(&self.pane.showing) |
| 2045 | 2118 | { |
| ... | ... | @@ -2060,16 +2133,7 @@ impl State { |
| 2060 | 2133 | } |
| 2061 | 2134 | if self.session.is_none() && self.pane.locked.is_some() { |
| 2062 | 2135 | 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); | |
| 2073 | 2137 | } |
| 2074 | 2138 | if let Some(library) = self |
| 2075 | 2139 | .pane |
| ... | ... | @@ -2078,19 +2142,10 @@ impl State { |
| 2078 | 2142 | .filter(|_| self.session.is_none()) |
| 2079 | 2143 | { |
| 2080 | 2144 | 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); | |
| 2091 | 2146 | } |
| 2092 | 2147 | self.ui.open_as( |
| 2093 | page(), | |
| 2148 | self.pane.id, | |
| 2094 | 2149 | Spec { |
| 2095 | 2150 | flags: Flags::CUSTOM | Flags::FOCUSABLE, |
| 2096 | 2151 | size: [fill(), fill()], |
| ... | ... | @@ -2099,15 +2154,15 @@ impl State { |
| 2099 | 2154 | ..Spec::default() |
| 2100 | 2155 | }, |
| 2101 | 2156 | ); |
| 2102 | if let Some(node) = self.ui.access(page()) { | |
| 2157 | if let Some(node) = self.ui.access(self.pane.id) { | |
| 2103 | 2158 | node.set_tree_id(PAGE_TREE); |
| 2104 | 2159 | } |
| 2105 | 2160 | // A page opening has neither the templates nor the scroll of the page leaving. |
| 2106 | 2161 | let opening = self.loading().is_some(); |
| 2107 | 2162 | if !opening { |
| 2108 | self.template_strip(&theme); | |
| 2163 | self.template_strip(theme); | |
| 2109 | 2164 | } |
| 2110 | self.transport(&theme)?; | |
| 2165 | self.transport(theme)?; | |
| 2111 | 2166 | let scroll = self.pane.view.scroll(); |
| 2112 | 2167 | for (index, axis) in [Axis::X, Axis::Y] |
| 2113 | 2168 | .into_iter() |
| ... | ... | @@ -2143,7 +2198,7 @@ impl State { |
| 2143 | 2198 | ..Spec::default() |
| 2144 | 2199 | }, |
| 2145 | 2200 | ); |
| 2146 | page().child("task") | |
| 2201 | self.pane.id.child("task") | |
| 2147 | 2202 | }); |
| 2148 | 2203 | self.ui.close(); |
| 2149 | 2204 | if let Some(task) = task { |
| ... | ... | @@ -2154,34 +2209,15 @@ impl State { |
| 2154 | 2209 | Some("Edit it in OneNote with Outlook"), |
| 2155 | 2210 | ); |
| 2156 | 2211 | } |
| 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); | |
| 2159 | 2214 | if focused != self.pane.page_focused { |
| 2160 | 2215 | self.pane.page_focused = focused; |
| 2161 | 2216 | let response = self.pane.view.focus_changed(focused)?; |
| 2162 | 2217 | self.respond(response); |
| 2163 | 2218 | } |
| 2164 | 2219 | 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) | |
| 2185 | 2221 | } |
| 2186 | 2222 | |
| 2187 | 2223 | /// The page's corner radius, sharing its centres with the window's corners. |
| ... | ... | @@ -2193,16 +2229,44 @@ impl State { |
| 2193 | 2229 | /// together with the open page's tab, joined where they meet. |
| 2194 | 2230 | fn edges(&mut self, section: ui::Section, open_tab: Id, open_page: Option<Id>) { |
| 2195 | 2231 | 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 { | |
| 2198 | 2234 | return; |
| 2199 | 2235 | }; |
| 2200 | 2236 | 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); | |
| 2201 | 2260 | // Where the open page tab meets the page, concentric with its neighbours. |
| 2202 | 2261 | let join = PILL_MARGIN + rounding; |
| 2203 | 2262 | let [left, top, right, bottom] = page; |
| 2204 | 2263 | 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; | |
| 2205 | 2268 | let tab = open_page |
| 2269 | .filter(|_| beside) | |
| 2206 | 2270 | .and_then(|id| self.ui.laid_out(id)) |
| 2207 | 2271 | .map(|row| [row[0], row[1], row[2], row[3] - ROW_GAP]) |
| 2208 | 2272 | .zip(panel) |
| ... | ... | @@ -2265,11 +2329,8 @@ impl State { |
| 2265 | 2329 | ([left, bottom], rounding), |
| 2266 | 2330 | ]), |
| 2267 | 2331 | } |
| 2268 | let height = (frame[3] - frame[1]).max(1.0); | |
| 2269 | 2332 | 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); | |
| 2273 | 2334 | self.ui.border(&outline, true, section.edge); |
| 2274 | 2335 | // The frame's top corners share the page's centres, and beside the sidebar so does |
| 2275 | 2336 | // its bottom one, rounding in as the sidebar opens; the frame's top edge breaks where |
| ... | ... | @@ -3312,7 +3373,7 @@ impl State { |
| 3312 | 3373 | let percent = typed.trim().trim_end_matches('%').trim().parse::<f32>(); |
| 3313 | 3374 | zoom = percent.ok().filter(|_| key == NamedKey::Enter); |
| 3314 | 3375 | self.zoom_typed = None; |
| 3315 | self.ui.set_focus(Some(page())); | |
| 3376 | self.ui.set_focus(Some(self.pane.id)); | |
| 3316 | 3377 | } |
| 3317 | 3378 | } else { |
| 3318 | 3379 | let id = self.ui.id("level"); |
| ... | ... | @@ -3522,7 +3583,7 @@ impl State { |
| 3522 | 3583 | .as_ref() |
| 3523 | 3584 | .is_some_and(|session| session.read_only(&self.pane.showing)); |
| 3524 | 3585 | 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(); | |
| 3526 | 3587 | let device = |point: [f32; 2]| { |
| 3527 | 3588 | [ |
| 3528 | 3589 | (point[0] - corner[0]) * scale, |
| ... | ... | @@ -3826,6 +3887,8 @@ impl State { |
| 3826 | 3887 | Command::Page(Request::OpenAttachment(file)) => self.open_attachment(&file)?, |
| 3827 | 3888 | Command::Page(Request::Play { file, at_ms }) => self.play(&file, at_ms)?, |
| 3828 | 3889 | Command::Choose(choice) => self.run(choice)?, |
| 3890 | Command::Split(axis) => self.split_pane(axis)?, | |
| 3891 | Command::ClosePane(id) => self.close_pane(id)?, | |
| 3829 | 3892 | Command::TagPicture => self.pick_tag_picture(), |
| 3830 | 3893 | Command::Text(text) => { |
| 3831 | 3894 | if let Some(context) = self.pane.view.caret_context() { |
| ... | ... | @@ -4064,24 +4127,10 @@ impl State { |
| 4064 | 4127 | .as_ref() |
| 4065 | 4128 | .is_none_or(|open| open.library.location != session.library.location); |
| 4066 | 4129 | 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. | |
| 4069 | 4130 | self.pane.locked = None; |
| 4070 | 4131 | let previous = self.session.replace(*session); |
| 4071 | 4132 | 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); | |
| 4085 | 4134 | } |
| 4086 | 4135 | self.pane.showing = Showing { |
| 4087 | 4136 | space, |
| ... | ... | @@ -4157,6 +4206,25 @@ impl State { |
| 4157 | 4206 | Ok(()) |
| 4158 | 4207 | } |
| 4159 | 4208 | |
| 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 | ||
| 4160 | 4228 | /// Takes `library`, a notebook read again after a change, in place of the one it was; |
| 4161 | 4229 | /// the open section, now at catalog `path` in it, keeps its replica where it moved. |
| 4162 | 4230 | /// Without `path` the notebook has no sections left, and one of its shows none. |
| ... | ... | @@ -4227,7 +4295,7 @@ impl State { |
| 4227 | 4295 | } |
| 4228 | 4296 | // A page a search result shows leaves the keys with the search. |
| 4229 | 4297 | if !search::takes_text(self.ui.focused()) { |
| 4230 | self.ui.set_focus(Some(page())); | |
| 4298 | self.ui.set_focus(Some(self.pane.id)); | |
| 4231 | 4299 | } |
| 4232 | 4300 | self.title(); |
| 4233 | 4301 | self.update_accessibility(true)?; |
| ... | ... | @@ -4250,7 +4318,7 @@ impl State { |
| 4250 | 4318 | /// Follows the view moving: the input method's position and accessibility. |
| 4251 | 4319 | fn after_move(&mut self) -> Result<(), Box<dyn Error>> { |
| 4252 | 4320 | 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(); | |
| 4254 | 4322 | let [x0, y0, x1, y1] = self.pane.view.caret_area()?; |
| 4255 | 4323 | self.window.set_ime_cursor_area( |
| 4256 | 4324 | LogicalPosition::new(x0 / scale + corner[0], y0 / scale + corner[1]), |
| ... | ... | @@ -4397,7 +4465,7 @@ impl State { |
| 4397 | 4465 | let at = |offset| canvas::document::TextPosition { paragraph, offset }; |
| 4398 | 4466 | self.pane.view.editor.focus_outline(outline)?; |
| 4399 | 4467 | 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)); | |
| 4401 | 4469 | let response = self.pane.view.focus_text()?; |
| 4402 | 4470 | self.respond(response); |
| 4403 | 4471 | self.window.request_redraw(); |
| ... | ... | @@ -4588,13 +4656,13 @@ impl State { |
| 4588 | 4656 | /// `page` asks or its tree is not grafted yet. The interface's tree goes first, since it |
| 4589 | 4657 | /// holds the page's. |
| 4590 | 4658 | 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(); | |
| 4592 | 4660 | if !built && self.page_grafted { |
| 4593 | 4661 | // Its graft is gone, and with it the tree, which must be sent whole again. |
| 4594 | 4662 | self.accessibility.deactivate(); |
| 4595 | 4663 | self.page_grafted = false; |
| 4596 | 4664 | } |
| 4597 | let graft = self::page().node(); | |
| 4665 | let graft = self.pane.id.node(); | |
| 4598 | 4666 | let title = self.window.title(); |
| 4599 | 4667 | let scale = self.window.scale_factor(); |
| 4600 | 4668 | let grafted = self.page_grafted; |
| ... | ... | @@ -4613,10 +4681,10 @@ impl State { |
| 4613 | 4681 | } |
| 4614 | 4682 | let mut error = None; |
| 4615 | 4683 | 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); | |
| 4617 | 4685 | self.access_adapter.update_if_active(|| { |
| 4618 | 4686 | 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| { | |
| 4620 | 4688 | error = Some(failure); |
| 4621 | 4689 | self.accessibility.deactivate(); |
| 4622 | 4690 | let mut root = accesskit::Node::new(accesskit::Role::Group); |
| ... | ... | @@ -4686,18 +4754,18 @@ impl State { |
| 4686 | 4754 | write(&child, depth + 1, out); |
| 4687 | 4755 | } |
| 4688 | 4756 | } |
| 4689 | let graft = page().node(); | |
| 4757 | let graft = self.pane.id.node(); | |
| 4690 | 4758 | let mut chrome = self |
| 4691 | 4759 | .ui |
| 4692 | 4760 | .accessibility_tree(&self.window.title(), self.window.scale_factor()); |
| 4693 | 4761 | let focus = std::mem::replace(&mut chrome.focus, ui::Id::ROOT.node()); |
| 4694 | 4762 | 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() { | |
| 4696 | 4764 | 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)?; | |
| 4698 | 4766 | tree.update_and_process_changes(page, &mut Unwatched); |
| 4699 | 4767 | } |
| 4700 | if focus != graft || self.ui.laid_out(page()).is_some() { | |
| 4768 | if focus != graft || self.ui.laid_out(self.pane.id).is_some() { | |
| 4701 | 4769 | let update = accesskit::TreeUpdate { |
| 4702 | 4770 | nodes: Vec::new(), |
| 4703 | 4771 | tree: None, |
| ... | ... | @@ -4739,7 +4807,7 @@ impl State { |
| 4739 | 4807 | if let Some(index) = self.accessibility.read_only_for_node(request.target_node) { |
| 4740 | 4808 | if request.action == Action::Focus { |
| 4741 | 4809 | self.window.focus_window(); |
| 4742 | self.ui.set_focus(Some(page())); | |
| 4810 | self.ui.set_focus(Some(self.pane.id)); | |
| 4743 | 4811 | let response = self.pane.view.focus_read_only(index)?; |
| 4744 | 4812 | self.respond(response); |
| 4745 | 4813 | self.window.request_redraw(); |
| ... | ... | @@ -4772,7 +4840,7 @@ impl State { |
| 4772 | 4840 | } |
| 4773 | 4841 | _ => return Ok(()), |
| 4774 | 4842 | } |
| 4775 | self.ui.set_focus(Some(page())); | |
| 4843 | self.ui.set_focus(Some(self.pane.id)); | |
| 4776 | 4844 | let response = self.pane.view.focus_text()?; |
| 4777 | 4845 | self.respond(response); |
| 4778 | 4846 | self.window.request_redraw(); |
| ... | ... | @@ -4791,6 +4859,12 @@ impl State { |
| 4791 | 4859 | paper, |
| 4792 | 4860 | ); |
| 4793 | 4861 | } |
| 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 | } | |
| 4794 | 4868 | self.snapshot(&path)?; |
| 4795 | 4869 | } |
| 4796 | 4870 | if let Some((dir, opened)) = &self.frames { |
| ... | ... | @@ -4870,7 +4944,7 @@ impl State { |
| 4870 | 4944 | } |
| 4871 | 4945 | let theme = &self.ui.theme; |
| 4872 | 4946 | 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(); | |
| 4874 | 4948 | // A page taking a while to open shows its outline, drawn in points from the corner. |
| 4875 | 4949 | let (page_primitives, viewport) = match self.loading() { |
| 4876 | 4950 | Some(since) => ( |
| ... | ... | @@ -4894,24 +4968,51 @@ impl State { |
| 4894 | 4968 | self.pane.view.viewport, |
| 4895 | 4969 | ), |
| 4896 | 4970 | }; |
| 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 | } | |
| 4897 | 4994 | lap("page primitives", start); |
| 4898 | 4995 | let interface = self.ui.layers(); |
| 4899 | 4996 | let layers: Vec<_> = interface |
| 4900 | 4997 | .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 | } | |
| 4915 | 5016 | }) |
| 4916 | 5017 | .collect(); |
| 4917 | 5018 | trace_input(&("Draw", viewport.origin, viewport.scale)); |
| ... | ... | @@ -4943,14 +5044,14 @@ impl State { |
| 4943 | 5044 | } |
| 4944 | 5045 | |
| 4945 | 5046 | 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(); | |
| 4947 | 5048 | let [x, y] = self.pointer; |
| 4948 | 5049 | (x0..x1).contains(&x) && (y0..y1).contains(&y) |
| 4949 | 5050 | } |
| 4950 | 5051 | |
| 4951 | 5052 | /// Window point `point` in the page's device pixels. |
| 4952 | 5053 | 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(); | |
| 4954 | 5055 | let scale = self.ui.scale(); |
| 4955 | 5056 | [(point[0] - left) * scale, (point[1] - top) * scale] |
| 4956 | 5057 | } |
| ... | ... | @@ -5001,6 +5102,13 @@ impl State { |
| 5001 | 5102 | self.window.request_redraw(); |
| 5002 | 5103 | return; |
| 5003 | 5104 | } |
| 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 | } | |
| 5004 | 5112 | if let ui::Event::Button { pressed: true, .. } = event |
| 5005 | 5113 | && self.renaming.is_some() |
| 5006 | 5114 | && self.ui.box_at(self.pointer) != Some(rename::field()) |
| ... | ... | @@ -5074,16 +5182,17 @@ fn theme(appearance: winit::window::Theme, light_pages: bool, backdrop: bool) -> |
| 5074 | 5182 | } |
| 5075 | 5183 | } |
| 5076 | 5184 | |
| 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. | |
| 5080 | 5188 | fn page_tree( |
| 5081 | view: &PageView, | |
| 5189 | pane: &Pane, | |
| 5082 | 5190 | ui: &Ui, |
| 5083 | 5191 | window: &Window, |
| 5084 | 5192 | access: &mut accessibility::Accessibility, |
| 5085 | 5193 | ) -> 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(); | |
| 5087 | 5196 | let scale = ui.scale(); |
| 5088 | 5197 | let ratio = window.scale_factor() as f32 / scale; |
| 5089 | 5198 | let viewport = canvas::gpu::Viewport { |
| ... | ... | @@ -6479,7 +6588,7 @@ impl State { |
| 6479 | 6588 | self.window.request_redraw(); |
| 6480 | 6589 | } |
| 6481 | 6590 | UserEvent::InsertText(text) => { |
| 6482 | if self.ui.focused() == Some(page()) { | |
| 6591 | if self.ui.focused() == Some(self.pane.id) { | |
| 6483 | 6592 | match self.pane.view.insert_text(text) { |
| 6484 | 6593 | Ok(response) => self.respond(response), |
| 6485 | 6594 | Err(error) => eprintln!("{error}"), |
| ... | ... | @@ -6589,6 +6698,8 @@ impl State { |
| 6589 | 6698 | .request_inner_size(LogicalSize::new(width, height)); |
| 6590 | 6699 | } |
| 6591 | 6700 | 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)), | |
| 6592 | 6703 | } |
| 6593 | 6704 | // A covered window gets no redraws, so each step draws its own frame. |
| 6594 | 6705 | if let Err(error) = self.frame() { |
| ... | ... | @@ -7102,6 +7213,12 @@ fn replay(script: String, proxy: EventLoopProxy<UserEvent>) -> Result<(), Box<dy |
| 7102 | 7213 | Ok(Replay::Access(action, label.to_owned())) |
| 7103 | 7214 | } |
| 7104 | 7215 | "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), | |
| 7105 | 7222 | "appearance" => Ok(Replay::Appearance(match rest { |
| 7106 | 7223 | "light" => winit::window::Theme::Light, |
| 7107 | 7224 | "dark" => winit::window::Theme::Dark, |
crates/snowbound/src/manage.rs+1-1| ... | ... | @@ -250,7 +250,7 @@ impl State { |
| 250 | 250 | since: now, |
| 251 | 251 | requested: now, |
| 252 | 252 | })?; |
| 253 | self.ui.set_focus(Some(crate::page())); | |
| 253 | self.ui.set_focus(Some(self.pane.id)); | |
| 254 | 254 | if let Some(title) = self |
| 255 | 255 | .pane |
| 256 | 256 | .view |
crates/snowbound/src/protection.rs+1-1| ... | ... | @@ -66,7 +66,7 @@ fn notice() -> Id { |
| 66 | 66 | Id::ROOT.child("locked-notice") |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | fn section_name(path: &str) -> &str { | |
| 69 | pub(crate) fn section_name(path: &str) -> &str { | |
| 70 | 70 | let name = path.rsplit('/').next().unwrap_or(path); |
| 71 | 71 | name.strip_suffix(".one").unwrap_or(name) |
| 72 | 72 | } |
crates/snowbound/src/recording.rs+9-8| ... | ... | @@ -57,8 +57,9 @@ pub enum Transport { |
| 57 | 57 | SeePlayback, |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | fn seek_field() -> ui::Id { | |
| 61 | crate::page().child("transport").child("seek") | |
| 60 | /// The Seek To field of the transport over page box `page`. | |
| 61 | fn seek_field(page: ui::Id) -> ui::Id { | |
| 62 | page.child("transport").child("seek") | |
| 62 | 63 | } |
| 63 | 64 | |
| 64 | 65 | impl State { |
| ... | ... | @@ -263,8 +264,8 @@ impl State { |
| 263 | 264 | } |
| 264 | 265 | (Transport::SeekTo, Media::Playing(playback)) => { |
| 265 | 266 | 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)); | |
| 268 | 269 | } |
| 269 | 270 | _ => {} |
| 270 | 271 | } |
| ... | ... | @@ -482,7 +483,7 @@ impl State { |
| 482 | 483 | Media::Playing(playback) => &mut playback.seeking, |
| 483 | 484 | _ => &mut None, |
| 484 | 485 | }; |
| 485 | let focused = self.ui.focused() == Some(seek_field()); | |
| 486 | let focused = self.ui.focused() == Some(seek_field(self.pane.id)); | |
| 486 | 487 | let Some(text) = seeking.as_mut().filter(|_| focused) else { |
| 487 | 488 | *seeking = None; |
| 488 | 489 | let playing = matches!(self.media, Media::Playing(_)); |
| ... | ... | @@ -519,12 +520,12 @@ impl State { |
| 519 | 520 | }; |
| 520 | 521 | let keys = ui::popup::navigation( |
| 521 | 522 | &mut self.ui, |
| 522 | &[seek_field()], | |
| 523 | &[seek_field(self.pane.id)], | |
| 523 | 524 | &[NamedKey::Enter, NamedKey::Escape], |
| 524 | 525 | ); |
| 525 | 526 | ui::text_field( |
| 526 | 527 | &mut self.ui, |
| 527 | seek_field(), | |
| 528 | seek_field(self.pane.id), | |
| 528 | 529 | text, |
| 529 | 530 | "m:ss", |
| 530 | 531 | Spec { |
| ... | ... | @@ -542,7 +543,7 @@ impl State { |
| 542 | 543 | .flatten(); |
| 543 | 544 | if !keys.is_empty() { |
| 544 | 545 | *seeking = None; |
| 545 | self.ui.set_focus(Some(crate::page())); | |
| 546 | self.ui.set_focus(Some(self.pane.id)); | |
| 546 | 547 | } |
| 547 | 548 | at |
| 548 | 549 | } |
crates/snowbound/src/rename.rs+1-1| ... | ... | @@ -126,7 +126,7 @@ impl State { |
| 126 | 126 | let Some(Renaming { target, name }) = self.renaming.take() else { |
| 127 | 127 | return; |
| 128 | 128 | }; |
| 129 | self.ui.set_focus(Some(crate::page())); | |
| 129 | self.ui.set_focus(Some(self.pane.id)); | |
| 130 | 130 | let name = name.trim().to_owned(); |
| 131 | 131 | if !keep || name.is_empty() { |
| 132 | 132 | return; |
crates/snowbound/src/search.rs+3-3| ... | ... | @@ -3,7 +3,7 @@ |
| 3 | 3 | //! its own, from the section files and the open section's replica. |
| 4 | 4 | |
| 5 | 5 | use crate::task_pane::TaskPane; |
| 6 | use crate::{Command, Library, State, Theme, art, commands, lap, name, page}; | |
| 6 | use crate::{Command, Library, State, Theme, art, commands, lap, name}; | |
| 7 | 7 | use accesskit::Role; |
| 8 | 8 | use canvas::search::{Entry, Found, Index, PageMatch, Query, page_matches, paragraph_match}; |
| 9 | 9 | use notebook::Replica; |
| ... | ... | @@ -685,7 +685,7 @@ impl State { |
| 685 | 685 | self.search.finding = false; |
| 686 | 686 | self.search.current = None; |
| 687 | 687 | self.ui.close_popup(results()); |
| 688 | self.ui.set_focus(Some(page())); | |
| 688 | self.ui.set_focus(Some(self.pane.id)); | |
| 689 | 689 | if !matches!(self.search.task_pane, Some(TaskPane::Search { .. })) { |
| 690 | 690 | self.search.query.clear(); |
| 691 | 691 | self.search.scope = self.search.default; |
| ... | ... | @@ -1120,7 +1120,7 @@ impl State { |
| 1120 | 1120 | self.open_result(index)?; |
| 1121 | 1121 | self.search.open = false; |
| 1122 | 1122 | self.ui.close_popup(results()); |
| 1123 | self.ui.set_focus(Some(page())); | |
| 1123 | self.ui.set_focus(Some(self.pane.id)); | |
| 1124 | 1124 | } |
| 1125 | 1125 | Ok(()) |
| 1126 | 1126 | } |
crates/snowbound/src/server.rs+1-1| ... | ... | @@ -835,7 +835,7 @@ impl State { |
| 835 | 835 | ui.close(); |
| 836 | 836 | if cancel { |
| 837 | 837 | self.ui.close_popup(id()); |
| 838 | self.ui.set_focus(Some(crate::page())); | |
| 838 | self.ui.set_focus(Some(self.pane.id)); | |
| 839 | 839 | self.server = None; |
| 840 | 840 | return; |
| 841 | 841 | } |
crates/snowbound/src/share.rs+2-2| ... | ... | @@ -590,7 +590,7 @@ impl State { |
| 590 | 590 | } |
| 591 | 591 | if done { |
| 592 | 592 | self.ui.close_popup(share_id()); |
| 593 | self.ui.set_focus(Some(crate::page())); | |
| 593 | self.ui.set_focus(Some(self.pane.id)); | |
| 594 | 594 | return; |
| 595 | 595 | } |
| 596 | 596 | self.peers.share = Some(dialog); |
| ... | ... | @@ -661,7 +661,7 @@ impl State { |
| 661 | 661 | ui.close(); |
| 662 | 662 | if cancel { |
| 663 | 663 | self.ui.close_popup(join_id()); |
| 664 | self.ui.set_focus(Some(crate::page())); | |
| 664 | self.ui.set_focus(Some(self.pane.id)); | |
| 665 | 665 | return; |
| 666 | 666 | } |
| 667 | 667 | if open && !matches!(dialog.status, Status::Waiting) { |
crates/snowbound/src/split.rs+429-3| ... | ... | @@ -3,13 +3,76 @@ |
| 3 | 3 | //! are parked. Panes on one section share its `Session`, since a section's replica opens |
| 4 | 4 | //! once (`locking_mode=EXCLUSIVE`). |
| 5 | 5 | |
| 6 | use crate::{Command, Library, Loaded, Pane, Session, State}; | |
| 6 | use crate::{Command, FRAME, Library, Loaded, Pane, Session, State, art, name, navigation}; | |
| 7 | use canvas::{gpu::page::PageScene, interaction::PageView}; | |
| 8 | use draw::edit::SelectionUnit; | |
| 7 | 9 | use notebook::{Replica, session::Event}; |
| 8 | 10 | use onestore::ExGuid; |
| 9 | 11 | use std::{ |
| 10 | 12 | error::Error, |
| 11 | 13 | sync::{Arc, atomic::Ordering}, |
| 12 | 14 | }; |
| 15 | use ui::{Axis, Extent, Flags, Id, Overflow, Size, Spec, Theme, fill, px}; | |
| 16 | use winit::window::CursorIcon; | |
| 17 | ||
| 18 | /// The least a pane gives way to another beside it as their divider moves. | |
| 19 | const 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. | |
| 23 | pub enum Split { | |
| 24 | Leaf(Id), | |
| 25 | Pair { | |
| 26 | axis: Axis, | |
| 27 | ratio: f32, | |
| 28 | a: Box<Split>, | |
| 29 | b: Box<Split>, | |
| 30 | }, | |
| 31 | } | |
| 32 | ||
| 33 | impl 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 | } | |
| 13 | 76 | |
| 14 | 77 | /// A pane out of focus, and the section it shows by `Library::key`; the focused pane's is |
| 15 | 78 | /// `State::session`. |
| ... | ... | @@ -91,9 +154,16 @@ impl State { |
| 91 | 154 | }); |
| 92 | 155 | } |
| 93 | 156 | |
| 94 | /// Closes the parked panes `gone` picks. | |
| 157 | /// Closes the parked panes `gone` picks, their room going to the parts beside them. | |
| 95 | 158 | 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)); | |
| 97 | 167 | } |
| 98 | 168 | |
| 99 | 169 | /// Moves the sections only parked panes show in `library`, a notebook read again, to |
| ... | ... | @@ -370,6 +440,362 @@ impl State { |
| 370 | 440 | self.commands.push(Command::OpenPage(open)); |
| 371 | 441 | Ok(true) |
| 372 | 442 | } |
| 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. | |
| 776 | fn 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 | } | |
| 373 | 799 | } |
| 374 | 800 | |
| 375 | 801 | /// 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 { |
| 578 | 578 | return; |
| 579 | 579 | } |
| 580 | 580 | self.ui.close_popup(id()); |
| 581 | self.ui.set_focus(Some(crate::page())); | |
| 581 | self.ui.set_focus(Some(self.pane.id)); | |
| 582 | 582 | self.tag_list = None; |
| 583 | 583 | } |
| 584 | 584 | } |
crates/snowbound/src/task_pane.rs+4-4| ... | ... | @@ -3,7 +3,7 @@ |
| 3 | 3 | //! Spelling (F7), walking the page's marked words. |
| 4 | 4 | |
| 5 | 5 | use crate::search::{Scope, marked}; |
| 6 | use crate::{State, Theme, art, page, platform}; | |
| 6 | use crate::{State, Theme, art, platform}; | |
| 7 | 7 | use canvas::gpu::tag_sources; |
| 8 | 8 | use canvas::outline::TagIcon; |
| 9 | 9 | use canvas::search::{Found, Tagged}; |
| ... | ... | @@ -673,7 +673,7 @@ impl State { |
| 673 | 673 | ], |
| 674 | 674 | ); |
| 675 | 675 | if keys.contains(&NamedKey::Escape) { |
| 676 | self.ui.set_focus(Some(page())); | |
| 676 | self.ui.set_focus(Some(self.pane.id)); | |
| 677 | 677 | } |
| 678 | 678 | let border = if self.ui.focused() == Some(field()) { |
| 679 | 679 | theme.accent |
| ... | ... | @@ -824,7 +824,7 @@ impl State { |
| 824 | 824 | let found = &self.search.found[order[row]]; |
| 825 | 825 | self.reveal(found.section.clone(), found.space, None)?; |
| 826 | 826 | if clicked.is_some() || keys.contains(&NamedKey::Enter) { |
| 827 | self.ui.set_focus(Some(page())); | |
| 827 | self.ui.set_focus(Some(self.pane.id)); | |
| 828 | 828 | } |
| 829 | 829 | } |
| 830 | 830 | Ok(()) |
| ... | ... | @@ -922,7 +922,7 @@ impl State { |
| 922 | 922 | { |
| 923 | 923 | eprintln!("{error}"); |
| 924 | 924 | } |
| 925 | self.ui.set_focus(Some(page())); | |
| 925 | self.ui.set_focus(Some(self.pane.id)); | |
| 926 | 926 | } |
| 927 | 927 | } |
| 928 | 928 |
crates/snowbound/src/templates.rs+8-4| ... | ... | @@ -174,11 +174,13 @@ fn strip( |
| 174 | 174 | (chosen, solid) |
| 175 | 175 | } |
| 176 | 176 | |
| 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. | |
| 179 | 180 | #[allow(clippy::too_many_arguments)] |
| 180 | 181 | fn gallery( |
| 181 | 182 | ui: &mut Ui, |
| 183 | page: Id, | |
| 182 | 184 | theme: &Theme, |
| 183 | 185 | thumbnails: &mut Thumbnails, |
| 184 | 186 | paper: Paper, |
| ... | ... | @@ -202,7 +204,7 @@ fn gallery( |
| 202 | 204 | radius: 8.0, |
| 203 | 205 | pad: [PAD, PAD], |
| 204 | 206 | gap: 8.0, |
| 205 | anchor: Some(Anchor::Dock(crate::page())), | |
| 207 | anchor: Some(Anchor::Dock(page)), | |
| 206 | 208 | role: Some(accesskit::Role::Dialog), |
| 207 | 209 | ..Spec::default() |
| 208 | 210 | }, |
| ... | ... | @@ -389,7 +391,7 @@ impl crate::State { |
| 389 | 391 | }; |
| 390 | 392 | let space = self.pane.showing.space; |
| 391 | 393 | 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 { | |
| 393 | 395 | return; |
| 394 | 396 | }; |
| 395 | 397 | // Thumbnails show templates on plain paper, not the page's colour. |
| ... | ... | @@ -400,6 +402,7 @@ impl crate::State { |
| 400 | 402 | let height = rect[3] - rect[1] - 8.0; |
| 401 | 403 | if let Some(name) = gallery( |
| 402 | 404 | &mut self.ui, |
| 405 | self.pane.id, | |
| 403 | 406 | theme, |
| 404 | 407 | &mut self.thumbnails, |
| 405 | 408 | paper, |
| ... | ... | @@ -447,6 +450,7 @@ impl crate::State { |
| 447 | 450 | } |
| 448 | 451 | if let Some(name) = gallery( |
| 449 | 452 | &mut self.ui, |
| 453 | self.pane.id, | |
| 450 | 454 | theme, |
| 451 | 455 | &mut self.thumbnails, |
| 452 | 456 | paper, |
crates/snowbound/src/web.rs+2-2| ... | ... | @@ -3,7 +3,7 @@ |
| 3 | 3 | //! event loop are stand-ins with the calls `State` makes of winit's; menus are the kit's own, |
| 4 | 4 | //! as on Linux; the browser's chords stay the browser's. See arc/platforms.md. |
| 5 | 5 | |
| 6 | use crate::{Reply, State, UserEvent, commands, page, settings}; | |
| 6 | use crate::{Reply, State, UserEvent, commands, settings}; | |
| 7 | 7 | use canvas::date::DateField; |
| 8 | 8 | use std::{ |
| 9 | 9 | cell::{Cell, RefCell}, |
| ... | ... | @@ -1816,7 +1816,7 @@ pub fn dictionary_arrived(name: String, affix: String, words: String) { |
| 1816 | 1816 | /// Parks the text area while the page takes no text, keeping it writable for the |
| 1817 | 1817 | /// interface's fields. |
| 1818 | 1818 | fn 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() { | |
| 1820 | 1820 | place_input(0.0, 0.0, 1.0, state.ui.focused().is_some()); |
| 1821 | 1821 | } |
| 1822 | 1822 | } |
crates/snowbound/tests/replay.rs+262| ... | ... | @@ -1524,3 +1524,265 @@ fn an_icloud_notebook_offers_delete_in_place_of_close() { |
| 1524 | 1524 | "{menu}" |
| 1525 | 1525 | ); |
| 1526 | 1526 | } |
| 1527 | ||
| 1528 | /// The line of `tree` that starts, past its indent, with `start`. | |
| 1529 | fn 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] | |
| 1538 | fn 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. | |
| 1622 | fn 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. | |
| 1629 | fn 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] | |
| 1635 | fn 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] | |
| 1662 | fn 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] | |
| 1699 | fn 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] | |
| 1725 | fn 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] | |
| 1756 | fn 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 | } |