fw-pages-review: merge origin/next into the port's pages, review and text editor

Pages: the port's page view keeps its pass (pre-draw tool callback, pager, GoTo, its picture stores) and takes
upstream's editor and inactive edits, snap and tool regions, rulers strips, picture reach with resident counts,
the zoom anchor and non-easing reflow, the thumb tip and Go To placement; PlacedPage::new takes upstream's
four arguments with showing() for the picture; page spacing is the theme insets for Creative and upstream's for
Productivity. Review: comment rows keep badges, lead and submit key beside upstream's balloon actions, body rows
and push buttons; a new lead keeps its own edit draft. Text: editor keeps holds_drafts with upstream's focus
scope. Module lists, stories and trials are the union.
This commit is contained in:
Dylan M. Taylor committed 2026-11-22 23:05:47 -05:00
1 parent cb3101725c
commit fd94fad305
24 files changed
+208 -674

No files matched your search

+1 -8
View File
@@ -20,11 +20,7 @@ workspace = true
suite = ["screen-testing", "craft-ui/suite"]
default = []
# The page widgets (`craft_pages::ui`), on craft-ui.
<<<<<<< HEAD
ui = ["dep:craft-behavior", "dep:craft-keymap", "dep:craft-ui","dep:craft-theme", "dep:egui", "dep:serde_json"]
=======
ui = ["dep:craft-behavior", "dep:craft-keymap", "dep:craft-ui", "dep:craft-theme", "dep:egui", "craft-text/ui"]
>>>>>>> origin/next
ui = ["dep:craft-behavior", "dep:craft-keymap", "dep:craft-ui", "dep:craft-theme", "dep:egui", "dep:serde_json", "craft-text/ui"]
# The stories and the integration tests (`tests/it`).
screen-testing = ["ui", "craft-ui/testing"]
@@ -36,10 +32,7 @@ serde = { workspace = true }
# `ui::range` keeps a page-range row's value as a dialog's JSON field.
serde_json = { workspace = true, optional = true }
craft-behavior = { workspace = true, optional = true }
<<<<<<< HEAD
# The arrows the page view reads come with the modifiers held.
=======
>>>>>>> origin/next
craft-keymap = { workspace = true, optional = true }
craft-ui = { workspace = true, optional = true }
craft-theme = { workspace = true, optional = true }
-5
View File
@@ -36,16 +36,11 @@ pub use layout::{
parse_display_token, place_pages, shown_row, spread_first,
};
pub use numbering::{NumberStyle, PAGE_NUMBER_STYLES, PageNumbering};
<<<<<<< HEAD
pub use range::{PageRange, PageRangeError, PageScope, Subset, format_pages, parse_pages};
pub use setup::{MARGIN_PRESETS, MarginPreset, Margins, Orientation, PAPER_SIZES, PageSetup, PageVerticalAlign, PaperSize, paper_named};
=======
pub use range::{PageRange, PageRangeError, Subset, format_pages, parse_pages};
pub use setup::{
DocumentGrid, GridKind, MARGIN_PRESETS, MAX_GRID_COUNT, MarginPreset, Margins, Orientation, PAPER_SIZES, PageSetup, PageVerticalAlign, PaperSize,
paper_named,
};
>>>>>>> origin/next
/// The stories and trials this crate registers.
#[cfg(feature = "screen-testing")]
+1 -5
View File
@@ -1,12 +1,8 @@
//! Pages for stories and tests: a document of US Letter pages with generated pictures.
use super::view::{PageSource, PlacedPage};
<<<<<<< HEAD
use craft_ui::primitives::textures::{FakeThumbSource, Revision, TextureState, ThumbRender, ThumbRequest, ThumbSource};
=======
use craft_behavior::CanvasView;
use craft_ui::primitives::textures::{FakeThumbSource, Revision, ThumbRender, ThumbRequest, ThumbSource};
>>>>>>> origin/next
use craft_ui::primitives::textures::{FakeThumbSource, Revision, TextureState, ThumbRender, ThumbRequest, ThumbSource};
use craft_ui::style::DataColor;
use egui::{Color32, Pos2, Rect, Vec2, pos2};
use kurbo::Size;
-6
View File
@@ -11,12 +11,6 @@ use craft_ui::runtime::env::{Message, UnitKind};
use craft_ui::testing::{Drive, Fixture, StoryData, StoryOutput, story};
use egui::{Ui, Vec2};
<<<<<<< HEAD
/// The document point the view is centred on.
const CENTRE: Point = Point::new(180.0, 400.0);
=======
>>>>>>> origin/next
/// How far the drag moves the left edge, in drag thresholds.
const DRAG_THRESHOLDS: f32 = 12.0;
+3 -5
View File
@@ -62,8 +62,6 @@ pub use thumbnails::{
ORGANIZE_ZOOM, PageThumbnails, PageThumbnailsOutput, THUMBNAIL_ZOOM, ThumbnailArrangement, ThumbnailEvent, ThumbnailMarks, ThumbnailSection,
ThumbnailWords, moved_page,
};
<<<<<<< HEAD
pub use view::{GoTo, PageBody, PageRevision, PageSource, PageView, PageViewOutput, PageViewState, PageViewWords, PlacedPage};
=======
pub use view::{PICTURE_REACH, PageBody, PageRegion, PageSnap, PageSource, PageView, PageViewOutput, PageViewState, PageViewWords, PlacedPage};
>>>>>>> origin/next
pub use view::{
GoTo, PICTURE_REACH, PageBody, PageRegion, PageRevision, PageSnap, PageSource, PageView, PageViewOutput, PageViewState, PageViewWords, PlacedPage,
};
-20
View File
@@ -4,12 +4,7 @@ use super::{PagePicture, PagePreview};
use crate::ui::fixtures::{DemoPages, PAPER};
use crate::ui::thumbnails::PageThumbnails;
use craft_behavior::Selection;
<<<<<<< HEAD
use craft_ui::contract::{Props as _, Show as _};
=======
use craft_ui::contract::{Props as _, Show as _, ShowContainer};
use craft_ui::runtime::env::{Env, Label};
>>>>>>> origin/next
use craft_ui::testing::{Drive, StoryData, StoryOutput, story};
use egui::Ui;
@@ -50,18 +45,3 @@ fn page_picture(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
let pages = DemoPages::new(5);
PagePicture::new(&pages, 2, "Page unavailable", PAPER).label("Page 3").show(ui).into()
}
<<<<<<< HEAD
=======
#[story(PreviewLayer<'static>, covers = [Default, Open], drive = Drive::Never)]
fn preview_layer(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
let words = Env::of(ui).words::<PagePreviewWords>();
let step = Cell::new(0);
let pages = DemoPages::new(5);
let layer = PreviewLayer::new(&words, Label::from("Page 2 of 5"), 1, 4, &step, data.bind("open", true));
ShowContainer::show(layer, ui, |ui, cx| {
PagePicture::new(&pages, 1, "Page unavailable", PAPER).label("Page 2").show_at(ui, cx.rect);
})
.into()
}
>>>>>>> origin/next
+2 -8
View File
@@ -315,11 +315,6 @@ fn paint_marks(
}
}
}
<<<<<<< HEAD
if let Some(selection) = selection {
for rect in selection.rects_on(placed.page, text) {
draw.fill(&PaintShape::Rect(screen(rect), look.radius), look.selection);
=======
for area in areas.iter().filter(|area| area.page == placed.page) {
let rect = screen(area.rect);
let (fill, grow) = match area.kind {
@@ -332,10 +327,9 @@ fn paint_marks(
draw.stroke(&PaintShape::Path(vec![pos2(rect.min.x, rect.max.y), rect.max]), StrokeWidth::Thin, look.column_outline);
}
}
if let (Some(text), Some(selection)) = (text, selection.filter(|selection| selection.page == placed.page)) {
for rect in selection.rects(text) {
if let (Some(text), Some(selection)) = (text, selection) {
for rect in selection.rects_on(placed.page, text) {
fill_mark(draw, look, screen(rect), look.selection, 0.0);
>>>>>>> origin/next
}
}
});
+108 -285
View File
@@ -11,16 +11,10 @@
//! |ui, body, _| { TextMarks::new(body.pages, &marks).show_at(ui, body.rect); });
//! ```
<<<<<<< HEAD
mod pager;
mod pictures;
#[cfg(feature = "screen-testing")]
mod stories;
=======
pub(crate) mod pictures;
#[cfg(feature = "suite")]
pub(crate) mod stories;
>>>>>>> origin/next
use self::pager::wheel_turn;
use self::pictures::{PageMetrics, PagePictures, page_stores, picture_options};
@@ -30,30 +24,17 @@ use crate::layout::{
};
use craft_behavior::geometry::{SnapOptions, SnapTarget, SnapTargets};
use craft_behavior::kurbo::{Point, Rect as DocRect, Size};
<<<<<<< HEAD
use craft_behavior::{CanvasView, NavMove, PressPhase, ZoomLadder};
use craft_behavior::{Axis, CanvasView, NavMove, PressPhase, ZoomLadder};
use craft_keymap::Mods;
use craft_ui::canvas::{
BodyKeys, Canvas, CanvasOutput, CanvasScrollbars, CanvasSpace, NavigationOptions, PageBorder, PageFrame, Pasteboard, PasteboardColor, PasteboardOutput, ToolPass,
canvas_space, tool_pass, with_canvas_space,
BodyKeys, Canvas, CanvasOutput, CanvasScrollbars, CanvasSpace, NavigationOptions, PageBorder, PageFrame, Pasteboard, PasteboardColor,
PasteboardOutput, Rulers, Snap, ToolPass, ToolRegion, canvas_space, pixel_aligned, tool_pass, with_canvas_space,
};
use craft_ui::contract::{Bind, BodyCx, Held, Props as _, Show as _, ShowContainer as _};
use craft_ui::primitives::PaintSlot;
use craft_ui::primitives::textures::{Priority, TextureState, TextureStatistics, ThumbRequest, ThumbSource};
use craft_ui::primitives::{EditorPurpose, PaintSlot};
use craft_ui::runtime::env::{Env, Label};
use craft_ui::runtime::focus::NudgeMods;
=======
use craft_behavior::{Axis, CanvasView, MoveMods, NavMove, PressPhase, WheelNotch, ZoomLadder};
use craft_ui::canvas::{
BodyKeys, Canvas, CanvasOutput, CanvasScrollbars, NavigationOptions, PageFrame, PageKey, Pasteboard, PasteboardOutput, Rulers, Snap, ToolPass,
ToolRegion, canvas_space, pixel_aligned, tool_pass,
};
use craft_ui::contract::{Bind, BodyCx, Held, Props as _, Show as _, ShowContainer as _};
use craft_ui::primitives::EditorPurpose;
use craft_ui::primitives::textures::ThumbSource;
use craft_ui::runtime::env::{Env, Label};
use craft_ui::runtime::focus::EditSet;
>>>>>>> origin/next
use craft_ui::runtime::focus::{EditSet, NudgeMods};
use craft_ui::runtime::memory::Remember as _;
use craft_ui::style::DataColor;
use egui::{Rect, Ui, Vec2, pos2};
@@ -274,9 +255,16 @@ pub struct PlacedPage {
impl PlacedPage {
/// Page `page` at `rect` on screen, `scale` screen points to a page point, with `band` the visible part of its height in
/// screen points and `picture` what its picture shows.
pub fn new(page: usize, rect: Rect, scale: f64, band: (f32, f32), picture: TextureState) -> Self {
PlacedPage { page, rect, scale, band, picture, picture_revision: None }
/// screen points; its picture `Missing` until [`showing`](Self::showing) says what it shows.
pub const fn new(page: usize, rect: Rect, scale: f64, band: (f32, f32)) -> Self {
PlacedPage { page, rect, scale, band, picture: TextureState::Missing, picture_revision: None }
}
/// The page with `picture` as what its picture shows this pass.
#[must_use]
pub fn showing(mut self, picture: TextureState) -> Self {
self.picture = picture;
self
}
/// Page point (origin top-left, y down) to screen.
@@ -399,13 +387,10 @@ pub struct PageViewOutput {
/// The pasteboard outside the pages (`None` when the pass drew nothing): a secondary press or the Menu key there asks the app for Photoshop's
/// pasteboard colour menu at [`PasteboardOutput::context_at`]; a page name click is not used here.
pub pasteboard: Option<PasteboardOutput>,
<<<<<<< HEAD
/// What the page and detail picture stores hold and did this pass, summed field by field.
pub textures: TextureStatistics,
/// The spacing the pass laid the pages out with.
pub spacing: PageSpacing,
=======
frame: Frame,
resident: usize,
}
@@ -418,23 +403,6 @@ impl PageViewOutput {
pub fn resident_pictures(&self) -> usize {
self.resident
}
/// Takes the view a tool host reported (`ToolHostResponse::view`, from the Hand and Zoom tools) into `state`:
/// the scroll offset, and the zoom when it changed (a fit ends). In a continuous view the current page follows
/// the offset.
pub fn adopt(&self, state: &mut PageViewState, view: &CanvasView) {
let frame = self.frame;
if (view.zoom - frame.zoom).abs() > frame.zoom * 1e-9 {
state.fit = Fit::None;
state.zoom = (view.zoom).clamp(*ZOOM_RANGE.start(), *ZOOM_RANGE.end());
}
let size = view.rect.size();
state.offset = frame.offset_of(view.center, f64::from(size.x), f64::from(size.y));
if state.continuous && !self.layout.rects.is_empty() {
state.current = page_on_line(&self.layout, state.offset.1 + f64::from(size.y) / 2.0);
}
}
>>>>>>> origin/next
}
/// The page view, built per pass over the app's [`PageSource`] and [`PageViewState`].
@@ -443,21 +411,16 @@ impl PageViewOutput {
/// view's style, recomputed when the viewport or the pages change; the zoom is written back so it equals what
/// shows. Pages draw as [`PageFrame`]s on a [`Pasteboard`], the page picture over each through `Thumbnails` at
/// `Priority::VISIBLE`, one row either side at `Priority::NEAR`; a page larger than the texture side adds a
<<<<<<< HEAD
/// second picture of the part in view. Sharp renders wait while a zoom gesture or ease runs, and those of the part
/// in view while the view pans too. While the view scrolls, the two rows ahead are asked for instead.
/// in view while the view pans too. While the view scrolls, the two rows ahead are asked for instead. A page
/// scrolled further than [`picture_reach`](Self::picture_reach) from the view gives its picture back.
/// - Layout: a scale the fit or the app changes keeps the document point at the centre of the view in place; a new
/// room keeps the current page's top where it was. Pages (a page or spread, or a scrolling column) shorter than
/// the view without their margins sit in its middle.
/// the view without their margins sit in its middle. A zoom about the pointer keeps the point under it in place
/// relative to the page there (or, in a gap, the nearest page), and one that does not ease draws its new layout,
/// reflowed, in the pass it happens, so the next pass moves nothing.
/// - Keys: the arrows go to the app's pre-draw tool host first ([`PageBody::pass`]); the view moves with those it leaves, in
/// the same pass.
=======
/// second picture of the part in view. Sharp renders wait while a zoom gesture or ease runs. A page scrolled
/// further than [`picture_reach`](Self::picture_reach) from the view gives its picture back.
/// - Layout: a scale the fit or the app changes keeps the page at the top of the view in place. A zoom about the
/// pointer keeps the point under it in place relative to the page there (or, in a gap, the nearest page), and one
/// that does not ease draws its new layout, reflowed, in the pass it happens, so the next pass moves nothing.
>>>>>>> origin/next
/// - Scrolling: the canvas folds in the wheel (the wheel scrolls, Shift or Ctrl/Cmd + wheel scrolls sideways, Alt +
/// wheel and a pinch zoom about the pointer, as [`NavigationOptions`] say) and the view commands; the view
/// reads the result back into its state. [`CanvasScrollbars`] land in their own pass. Not continuous, a page
@@ -476,18 +439,15 @@ pub struct PageView<'a> {
bodies: Option<&'a [(f64, f64)]>,
describer: Option<&'a dyn AccessDescriber>,
paper: DataColor,
<<<<<<< HEAD
border: PageBorder,
pasteboard: PasteboardColor,
keep: &'a [usize],
=======
editor: Option<EditorPurpose>,
inactive_edits: EditSet,
snap: Option<PageSnap>,
tool_regions: Vec<PageRegion>,
rulers: bool,
reach: f32,
>>>>>>> origin/next
}
/// How far from the view, in view heights above and below it (and one view width either side), the page view keeps a
@@ -507,18 +467,15 @@ impl<'a> PageView<'a> {
bodies: None,
describer: None,
paper,
<<<<<<< HEAD
border: PageBorder::DropShadow,
pasteboard: PasteboardColor::Default,
keep: &[],
=======
editor: None,
inactive_edits: EditSet::NONE,
snap: None,
tool_regions: Vec::new(),
rulers: false,
reach: PICTURE_REACH,
>>>>>>> origin/next
}
}
@@ -571,9 +528,6 @@ impl<'a> PageView<'a> {
self
}
<<<<<<< HEAD
/// Shows the view in the room left in `ui`, and runs `body` for the app's overlays.
=======
/// Registers the canvas's editor part of `purpose`; the view's keys give it none.
#[must_use]
pub fn editor(mut self, purpose: EditorPurpose) -> Self {
@@ -624,9 +578,7 @@ impl<'a> PageView<'a> {
self
}
/// Shows the view in the room left in `ui`, and runs `body` for the app's canvas controls (margins, zones,
/// marks, grids), which it shows with `show_at(ui, body.rect)`, and its tool host, which runs on `body.pass`.
>>>>>>> origin/next
/// Shows the view in the room left in `ui`, and runs `body` for the app's overlays.
/// `body` runs on every run of the canvas body (the measuring run and the real one), so it builds what it shows
/// each time and consumes nothing.
pub fn show(self, ui: &mut Ui, mut body: impl FnMut(&mut Ui, &PageBody<'_>)) -> PageViewOutput {
@@ -639,7 +591,6 @@ impl<'a> PageView<'a> {
self.run(ui, rect, false, &mut (), |_, _, _| None, |ui, page, _| body(ui, page))
}
<<<<<<< HEAD
/// Shows the view at `rect`, registering controls and running tools in `before` before drawing.
/// Return the view reported by the tool host; `body` receives the resulting placement for overlays. The canvas's
/// own view, which the host returns when no tool changed it, is applied only once.
@@ -676,9 +627,6 @@ impl<'a> PageView<'a> {
mut before: impl FnMut(&mut Ui, &PageBody<'_>, &mut T) -> Option<CanvasView>,
mut body: impl FnMut(&mut Ui, &PageBody<'_>, &mut T),
) -> PageViewOutput {
let PageView { label, source, state, options, navigation, bodies, describer, paper, border, pasteboard, keep } = self;
=======
fn run(self, ui: &mut Ui, rect: Rect, take_room: bool, mut body: impl FnMut(&mut Ui, &PageBody<'_>)) -> PageViewOutput {
let PageView {
label,
source,
@@ -688,6 +636,9 @@ impl<'a> PageView<'a> {
bodies,
describer,
paper,
border,
pasteboard,
keep,
editor,
inactive_edits,
snap,
@@ -695,8 +646,6 @@ impl<'a> PageView<'a> {
rulers,
reach,
} = self;
>>>>>>> origin/next
let spacing = PageMetrics::new().show_at(ui, Rect::from_min_size(rect.min, Vec2::ZERO)).spacing;
let count = source.page_count();
let sizes: Vec<Size> = (0..count).map(|page| source.page_size(page)).collect();
@@ -722,56 +671,41 @@ impl<'a> PageView<'a> {
let frame = Frame::of(&geo);
let given = frame.view(rect, start.offset, geo.scale / SCREEN_POINTS_PER_POINT);
let mut navigation = navigation;
<<<<<<< HEAD
// The canvas keeps the view inside the shown row, as the pass does, so a wheel share that cannot pan a row at its
// edge leaves the gesture unmoved and a page turn can follow it.
navigation.overscroll = false;
let canvas = Canvas::new(label.clone())
// The app's page geometry, in page points, placed where its page shows in this pass's layout.
let regions: Vec<ToolRegion> = tool_regions.iter().filter_map(|region| placed_region(region, &geo, &frame)).collect();
let mut canvas = Canvas::new(label.clone())
.view(given)
.navigation(navigation)
.keys_to_body(true)
.body_nudges(KeyMoves::NUDGES)
.pasteboard(pasteboard)
.tool_regions(regions)
.document(frame.document(&geo));
let mut held = Held::new(Bind::bound(state));
let mut seen: Option<Seen> = None;
let mut canvas_body = |ui: &mut Ui, cx: &mut BodyCx<'_>| {
let inputs = Inputs { source, describer, build: &build, rect, given, paper, navigation, border, keep };
let (mut next, pending) = run_pass(ui, cx, &mut held, &inputs, |ui, page| before(ui, page, session))?;
let pass = tool_pass(&cx.env);
with_canvas_space(ui, pending.space, |ui| {
body(ui, &PageBody { rect: cx.rect, pages: &next.pages, view: next.view, pass: pass.as_ref() }, session)
});
// The body's tool host took the arrows a tool claims; the view moves with the keys it left.
pending.finish(ui.ctx(), &mut next, &inputs);
=======
navigation.overscroll = !start.continuous;
// The app's page geometry, in page points, placed where its page shows in this pass's layout.
let regions: Vec<ToolRegion> = tool_regions.iter().filter_map(|region| placed_region(region, &geo, &frame)).collect();
let mut canvas = Canvas::new(label.clone()).view(given).navigation(navigation).keys_to_body(true).tool_regions(regions);
if let Some(purpose) = editor {
canvas = canvas.editor(purpose).inactive_edits(inactive_edits);
}
if let Some(snap) = &snap {
canvas = canvas.snap(placed_snap(snap, &geo, &frame));
}
if start.continuous {
canvas = canvas.document(frame.document(&geo));
}
let mut held = Held::new(Bind::bound(state));
let mut seen: Option<Seen> = None;
let mut canvas_body = |ui: &mut Ui, cx: &mut BodyCx<'_>| {
let next = run_pass(ui, cx, &mut held, &Inputs { source, describer, build: &build, rect, given, paper, reach })?;
let inputs =
Inputs { source, describer, build: &build, rect, given, paper, navigation, border, keep, reach, strips: strips_clip.map(|_| full) };
let (mut next, pending) = run_pass(ui, cx, &mut held, &inputs, |ui, page| before(ui, page, session))?;
let pass = tool_pass(&cx.env);
let body_rect = match strips_clip {
Some(clip) => {
ui.set_clip_rect(clip);
Rect::from_min_max(full.min, cx.rect.max)
}
None => cx.rect,
};
body(ui, &PageBody { rect: body_rect, pages: &next.pages, view: next.view, pass: pass.as_ref() });
>>>>>>> origin/next
if let Some(clip) = strips_clip {
ui.set_clip_rect(clip);
}
let body_rect = inputs.body_rect(cx.rect);
with_canvas_space(ui, pending.space, |ui| {
body(ui, &PageBody { rect: body_rect, pages: &next.pages, view: next.view, pass: pass.as_ref() }, session)
});
// The body's tool host took the arrows a tool claims; the view moves with the keys it left.
pending.finish(ui.ctx(), &mut next, &inputs);
let decided = next.next.clone();
seen = Some(next);
decided
@@ -804,13 +738,9 @@ impl<'a> PageView<'a> {
scrolled: seen.scrolled,
toggle_white_space,
pasteboard: seen.pasteboard,
<<<<<<< HEAD
textures: seen.textures,
spacing,
=======
frame: seen.frame,
resident: seen.resident,
>>>>>>> origin/next
}
}
}
@@ -823,14 +753,20 @@ struct Inputs<'a> {
rect: Rect,
given: CanvasView,
paper: DataColor,
<<<<<<< HEAD
navigation: NavigationOptions,
border: PageBorder,
keep: &'a [usize],
=======
/// `PageView::picture_reach`.
reach: f32,
>>>>>>> origin/next
/// With `PageView::rulers`, the view's whole rect, strips included; the canvas shows inside the strips.
strips: Option<Rect>,
}
impl Inputs<'_> {
/// The rect the app's callbacks get as [`PageBody::rect`]: the canvas body's, and with rulers the strips too.
fn body_rect(&self, canvas: Rect) -> Rect {
self.strips.map_or(canvas, |full| Rect::from_min_max(full.min, canvas.max))
}
}
/// What a pass found out, for the output.
@@ -843,12 +779,9 @@ struct Seen {
current_changed: bool,
scrolled: bool,
pasteboard: Option<PasteboardOutput>,
<<<<<<< HEAD
textures: TextureStatistics,
=======
/// The page pictures held.
resident: usize,
>>>>>>> origin/next
/// What the caller stores after the real run.
next: Option<Next>,
}
@@ -880,11 +813,8 @@ impl Seen {
current_changed: false,
scrolled: false,
pasteboard: None,
<<<<<<< HEAD
textures: TextureStatistics::default(),
=======
resident: 0,
>>>>>>> origin/next
next: None,
}
}
@@ -987,7 +917,6 @@ fn placed_region(region: &PageRegion, geo: &Placed, frame: &Frame) -> Option<Too
Some(ToolRegion::polygon(points))
}
<<<<<<< HEAD
/// One pass of the canvas body up to the app's body: layout, the wheel, a pinch and a pan folded into the state; the
/// pasteboard, the pictures and the scroll bars drawn. The keys, the turns and the go-to wait for [`Pending::finish`],
/// after the app's body.
@@ -998,27 +927,20 @@ fn run_pass(
inputs: &Inputs<'_>,
mut before: impl FnMut(&mut Ui, &PageBody<'_>) -> Option<CanvasView>,
) -> Option<(Seen, Pending)> {
let Inputs { source, describer, build, rect, given, paper, navigation, border, keep } = *inputs;
=======
/// One pass of the canvas body: layout, scrolling, zoom and paging folded into the state; the pasteboard, the
/// pictures and the scroll bars drawn.
fn run_pass(ui: &mut Ui, cx: &mut BodyCx<'_>, held: &mut Held<'_, PageViewState>, inputs: &Inputs<'_>) -> Option<Seen> {
let Inputs { source, describer, build, rect, given, paper, reach } = *inputs;
>>>>>>> origin/next
let Inputs { source, describer, build, rect, given, paper, navigation, border, keep, reach, strips: _ } = *inputs;
let mut state = held.read(cx)?;
let started = state.clone();
state.normalise();
let mut space = canvas_space(&cx.env)?;
// The canvas's settled view decides the zoom and the pan; the view on screen, part way there while a zoom eases,
// draws.
let (target, mut shown) = (space.target(), space.view);
let (target, shown) = (space.target(), space.view);
let wheel = space.wheel();
let env = Env::of(ui);
let words = env.words::<PageViewWords>();
let mut mem = cx.memory::<Memory>().clone();
let (vw, vh) = (build.viewport.width, build.viewport.height);
let count = build.sizes.len();
<<<<<<< HEAD
// A display, continuous, cover, fit or rotation other than the layout placed last keeps the current page in
// view. Writing a field to the value it has changes nothing, and the first pass has no layout to differ from.
@@ -1026,9 +948,6 @@ fn run_pass(ui: &mut Ui, cx: &mut BodyCx<'_>, held: &mut Held<'_, PageViewState>
if state.go_to.is_none() && previous.as_ref().is_some_and(|(key, _)| key.display_differs(&state)) {
state.go_to = Some(GoTo::Top { page: state.current, fraction: 0.0 });
}
=======
>>>>>>> origin/next
// The layout the canvas was given its view for: what this pass draws, whatever the pass makes of the state.
let drawn = build.of(&state);
let drawn_frame = Frame::of(&drawn);
@@ -1070,7 +989,7 @@ fn run_pass(ui: &mut Ui, cx: &mut BodyCx<'_>, held: &mut Held<'_, PageViewState>
}
};
geo = zoom_about(build, &mut state, &geo, rect, pointer, target.zoom / given.zoom);
let (xs, ys) = (offset_range(geo.doc.x0, geo.doc.x1, vw), offset_range(geo.doc.y0, geo.doc.y1, vh));
let (xs, ys) = (offset_range(geo.doc.x0, geo.doc.x1, vw), geo.y_range(vh));
state.offset = (state.offset.0.clamp(xs.0, xs.1), state.offset.1.clamp(ys.0, ys.1));
want = state.offset;
} else {
@@ -1087,17 +1006,12 @@ fn run_pass(ui: &mut Ui, cx: &mut BodyCx<'_>, held: &mut Held<'_, PageViewState>
want = (state.offset.0 + along_x, state.offset.1 + along_y);
}
}
<<<<<<< HEAD
let mut scrolled = wheel.is_some_and(|wheel| !zooming && wheel.scroll != Vec2::ZERO);
=======
if wheel_left == 0.0 {
mem.overshoot = 0.0;
}
// A zoom that does not ease draws the layout it made in its own pass, through the view of the anchored offset: the
// pages reflow and the point under the pointer stays in the pass the zoom happens, and the next pass, given that
// view, moves nothing. (Drawing the layout the pass started with, scaled, put the reflow and the spacing that does
// not scale one pass late.) An ease draws the layout it started from, scaled, until it lands.
let (drawn, drawn_frame, shown) = if zooming && !space.easing() {
let (drawn, drawn_frame, mut shown) = if zooming && !space.easing() {
let frame = Frame::of(&geo);
let mut view = frame.view(rect, state.offset, geo.scale / SCREEN_POINTS_PER_POINT);
// As the canvas places a given view: in its own rect (inside the rulers), about the same centre.
@@ -1107,10 +1021,6 @@ fn run_pass(ui: &mut Ui, cx: &mut BodyCx<'_>, held: &mut Held<'_, PageViewState>
} else {
(drawn, drawn_frame, shown)
};
let keys = KeyMoves::of(space.keys(), &state, &geo, rect);
want.0 += keys.pan.0;
want.1 = if keys.to_end { f64::INFINITY } else { want.1 + keys.pan.1 };
>>>>>>> origin/next
// Not continuous, the wheel turns the page at the row's edge. The edge is read at the offset the pass started
// with, not at `want.1`: the share that pans a long page to its edge has not been marked moved yet, and must not
@@ -1137,14 +1047,14 @@ fn run_pass(ui: &mut Ui, cx: &mut BodyCx<'_>, held: &mut Held<'_, PageViewState>
let rect = Rect::from_min_max(shown.to_screen(Point::new(r.x0, r.y0)), shown.to_screen(Point::new(r.x1, r.y1)));
let ratio = shown.zoom / drawn_frame.zoom;
let band = (drawn.layout.bands[page].0 as f32 * ratio as f32, drawn.layout.bands[page].1 as f32 * ratio as f32);
Some(PlacedPage::new(page, rect, drawn.scale * ratio, band, TextureState::Missing))
Some(PlacedPage::new(page, rect, drawn.scale * ratio, band))
})
.collect();
let slot = PaintSlot::reserve(&ui.painter_at(cx.rect));
let pass = tool_pass(&cx.env);
// A tool host returns the canvas's own changed view when no tool moved it. That view was already
// applied above, including its page anchor; applying it again here would undo that anchoring.
let tool_view = before(ui, &PageBody { rect: cx.rect, pages: &preliminary, view: shown, pass: pass.as_ref() })
let tool_view = before(ui, &PageBody { rect: inputs.body_rect(cx.rect), pages: &preliminary, view: shown, pass: pass.as_ref() })
.filter(|view| Some(*view) != pass.as_ref().and_then(|p| p.view));
let pre_shapes = slot.take_after(ui.ctx());
if let Some(view) = tool_view {
@@ -1197,7 +1107,7 @@ fn run_pass(ui: &mut Ui, cx: &mut BodyCx<'_>, held: &mut Held<'_, PageViewState>
let band = (drawn.layout.bands[page].0 as f32 * ratio as f32, drawn.layout.bands[page].1 as f32 * ratio as f32);
let picture = ask(page, rect.width().max(rect.height()), Priority::VISIBLE);
let picture_revision = matches!(picture, TextureState::Ready(_)).then(|| source.page_revision(page)).flatten();
let mut placed = PlacedPage::new(page, rect, drawn.scale * ratio, band, picture);
let mut placed = PlacedPage::new(page, rect, drawn.scale * ratio, band).showing(picture);
placed.picture_revision = picture_revision;
placed
})
@@ -1220,8 +1130,18 @@ fn run_pass(ui: &mut Ui, cx: &mut BodyCx<'_>, held: &mut Held<'_, PageViewState>
// The bars edit the view the state keeps, the canvas's settled one: the view on screen is pixel aligned, and a
// drag handed it back would differ from the drag's own value and cancel it.
let document = drawn_frame.document(&drawn);
let bars = CanvasScrollbars::new(words.scroll_bars.clone(), Bind::given(target), DocRect::from_origin_size(Point::ZERO, document))
.show_at(ui, cx.rect);
let bars = CanvasScrollbars::new(words.scroll_bars.clone(), Bind::given(target), DocRect::from_origin_size(Point::ZERO, document));
// The tip names the page at the top of the view the thumb moved to: the bars ask for it once they know the move.
let format = env.format();
let (top_lo, top_hi) = geo.y_range(vh);
let tip = |moved: &CanvasView| {
let top = drawn_frame.offset_of(moved.center, vw, vh).1.clamp(top_lo, top_hi);
let page = if state.continuous { page_on_line(&geo.layout, top) } else { state.current };
let (label, total) = (source.page_label(page), format.integer(count as u64));
Label::from(words.page_of.fill(&[("page", label.as_str()), ("count", total.as_str())]))
};
let bars = if count > 0 { bars.tip(&tip) } else { bars };
let bars = bars.show_at(ui, cx.rect);
let bar_drag = bars.view.value().is_some();
scrolled |= bar_drag;
let bar_want = bars.view.value().map(|moved| drawn_frame.offset_of(moved.center, vw, vh));
@@ -1234,6 +1154,23 @@ fn run_pass(ui: &mut Ui, cx: &mut BodyCx<'_>, held: &mut Held<'_, PageViewState>
Some(describer) => pictures.describer(describer).show_at(ui, cx.rect),
None => pictures.show_at(ui, cx.rect),
};
// Pages scrolled out of reach give their pictures back (WordCraft #811: a long scroll held every page it had
// shown). Those drawn, those asked for ahead, the app's and those of the shown row within the reach stay; a
// part-in-view picture is only of use while its page shows.
let reach = f64::from(reach);
let around = DocRect::new(
in_view.x0 - in_view.width(),
in_view.y0 - reach * in_view.height(),
in_view.x1 + in_view.width(),
in_view.y1 + reach * in_view.height(),
);
let mut held_pages: Vec<usize> =
drawn.row.clone().filter(|&p| p < drawn.layout.rects.len() && overlaps(band_rect(&drawn.layout, p), around)).collect();
held_pages.extend(rows.iter().chain(&near).chain(keep).copied());
held_pages.sort_unstable();
held_pages.dedup();
thumbs.retain(&ctx, |page| held_pages.binary_search(page).is_ok());
details.retain(&ctx, |page| rows.contains(page));
// PLAN: assumed impl Add for TextureStatistics (pdf-canvas-w7)
let textures = thumbs.cache().statistics(&ctx) + details.cache().statistics(&ctx);
PaintSlot::reserve(&ui.painter_at(cx.rect)).extend(&ctx, bar_shapes);
@@ -1248,6 +1185,7 @@ fn run_pass(ui: &mut Ui, cx: &mut BodyCx<'_>, held: &mut Held<'_, PageViewState>
scrolled,
pasteboard: Some(pasteboard),
textures,
resident: textures.entries,
next: None,
};
let pending =
@@ -1392,15 +1330,15 @@ fn place_go_to(build: &Geometry, state: &mut PageViewState, go_to: GoTo, (vw, vh
state.zoom = (fits / SCREEN_POINTS_PER_POINT).clamp(*ZOOM_RANGE.start(), *ZOOM_RANGE.end());
}
}
<<<<<<< HEAD
let geo = build.of(state);
state.zoom = geo.scale / SCREEN_POINTS_PER_POINT;
geo
}
/// The offset that shows `go_to` in `geo`, a view `(vw, vh)` points: `want` on an axis the go-to leaves alone or
/// gives as NaN. A page top goes `spacing.margin` below the view's top; out of a continuous view, a page's own top
/// is the top of its row.
/// gives as NaN. A page's own top puts the view's top where what shows of the row above ends (the document's start
/// for the first row), so the space the layout keeps above the page shows and nothing of the page before it; a point
/// inside the page goes to the view's top. Out of a continuous view, a page's own top is the top of its row.
fn go_to_offset(go_to: GoTo, geo: &Placed, continuous: bool, want: (f64, f64), (vw, vh): (f64, f64), spacing: &PageSpacing) -> (f64, f64) {
let page = go_to.page().min(geo.layout.rects.len().saturating_sub(1));
let Some(&r) = geo.layout.rects.get(page) else { return (want.0, geo.doc.y0) };
@@ -1410,7 +1348,14 @@ fn go_to_offset(go_to: GoTo, geo: &Placed, continuous: bool, want: (f64, f64), (
match go_to {
GoTo::Top { fraction, .. } => {
let (top, bottom) = geo.layout.bands[page];
let y = if continuous || fraction > 0.0 { r.y0 + top + fraction * (bottom - top) - spacing.margin } else { geo.doc.y0 };
let start = r.y0 + top;
let y = if fraction > 0.0 {
start + fraction * (bottom - top)
} else if continuous {
geo.layout.rects.iter().zip(&geo.layout.bands).map(|(r, band)| r.y0 + band.1).filter(|&end| end <= start).fold(geo.doc.y0, f64::max)
} else {
geo.doc.y0
};
let x = if r.width() + 2.0 * spacing.side <= vw {
clamp_between(want.0, r.x1 - vw + spacing.side, r.x0 - spacing.side)
} else if r.x1 <= want.0 {
@@ -1435,129 +1380,6 @@ fn go_to_offset(go_to: GoTo, geo: &Placed, continuous: bool, want: (f64, f64), (
or_want(c.x - vw / 2.0, c.y - vh / 2.0)
}
}
=======
let go_to = keys.go_to.or(state.go_to.take());
let went = go_to.is_some();
if let Some((page, fraction)) = go_to {
state.current = page.min(count.saturating_sub(1));
geo = build.of(&state);
state.zoom = geo.scale / SCREEN_POINTS_PER_POINT;
want.1 = match geo.layout.rects.get(state.current) {
// A point inside the page goes to the view's top. The page's own top puts the view's top where what shows
// of the row above ends (the document's start for the first row), so the space the layout keeps above the
// page shows and nothing of the page before it.
Some(r) if state.continuous => {
let (top, bottom) = geo.layout.bands[state.current];
let start = r.y0 + top;
if fraction > 0.0 {
start + fraction * (bottom - top)
} else {
geo.layout
.rects
.iter()
.zip(&geo.layout.bands)
.map(|(r, band)| r.y0 + band.1)
.filter(|&end| end <= start)
.fold(geo.doc.y0, f64::max)
}
}
_ => geo.doc.y0,
};
}
// The pasteboard, the pictures and the scroll bars are drawn through the view the canvas shows; a zoom still
// under way draws the layout the view was made for, scaled.
let ratio = shown.zoom / drawn_frame.zoom;
let seen = shown.visible();
let in_view = DocRect::new(
seen.x0 * drawn_frame.zoom + drawn_frame.origin.x,
seen.y0 * drawn_frame.zoom + drawn_frame.origin.y,
seen.x1 * drawn_frame.zoom + drawn_frame.origin.x,
seen.y1 * drawn_frame.zoom + drawn_frame.origin.y,
);
let rows: Vec<usize> = drawn.row.clone().filter(|&p| overlaps(band_rect(&drawn.layout, p), in_view)).collect();
let visible = match (rows.first(), rows.last()) {
(Some(&first), Some(&last)) => first..last + 1,
_ => 0..0,
};
let to_screen = |r: &DocRect| {
let r = drawn_frame.document_rect(r);
Rect::from_min_max(shown.to_screen(Point::new(r.x0, r.y0)), shown.to_screen(Point::new(r.x1, r.y1)))
};
let pages: Vec<PlacedPage> = rows
.iter()
.map(|&page| PlacedPage {
page,
rect: to_screen(&drawn.layout.rects[page]),
scale: drawn.scale * ratio,
band: (drawn.layout.bands[page].0 as f32 * ratio as f32, drawn.layout.bands[page].1 as f32 * ratio as f32),
})
.collect();
let frames: Vec<PageFrame> = rows.iter().map(|&p| PageFrame::new(drawn_frame.document_rect(&band_rect(&drawn.layout, p))).fill(paper)).collect();
let pasteboard = Pasteboard::new(words.pasteboard.clone(), &frames).show_at(ui, cx.rect);
let near: Vec<(usize, Vec2)> = near_pages(&drawn, state.continuous, &visible, count, &build.layout_options(&state))
.into_iter()
.map(|page| {
let size = drawn.layout.rects[page].size();
(page, Vec2::new(size.width as f32, size.height as f32))
})
.collect();
// The pages whose pictures stay: those drawn, those asked for ahead, and those of the shown row within the reach.
let reach = f64::from(reach);
let around = DocRect::new(
in_view.x0 - in_view.width(),
in_view.y0 - reach * in_view.height(),
in_view.x1 + in_view.width(),
in_view.y1 + reach * in_view.height(),
);
let mut keep: Vec<usize> = drawn.row.clone().filter(|&p| p < drawn.layout.rects.len() && overlaps(band_rect(&drawn.layout, p), around)).collect();
keep.extend(rows.iter().copied().chain(near.iter().map(|&(page, _)| page)));
keep.sort_unstable();
keep.dedup();
let pictures = PagePictures::new(source, &pages, &near, &keep, paper).label(words.text.clone()).hold(zooming || ratio != 1.0);
let resident = match describer {
Some(describer) => pictures.describer(describer).show_at(ui, cx.rect),
None => pictures.show_at(ui, cx.rect),
}
.resident;
// The scroll bars come before the clamp, so a drag of this pass lands in this pass.
let document = drawn_frame.document(&drawn);
let (xs, ys) = (offset_range(geo.doc.x0, geo.doc.x1, vw), offset_range(geo.doc.y0, geo.doc.y1, vh));
let bars = CanvasScrollbars::new(words.scroll_bars.clone(), Bind::given(shown), DocRect::from_origin_size(Point::ZERO, document));
// The tip names the page at the top of the view the thumb moved to: the bars ask for it once they know the move.
let format = env.format();
let tip = |moved: &CanvasView| {
let top = drawn_frame.offset_of(moved.center, vw, vh).1.clamp(ys.0, ys.1);
let page = if state.continuous { page_on_line(&geo.layout, top) } else { state.current };
let (label, total) = (source.page_label(page), format.integer(count as u64));
Label::from(words.page_of.fill(&[("page", label.as_str()), ("count", total.as_str())]))
};
let bars = if count > 0 { bars.tip(&tip) } else { bars };
let bars = bars.show_at(ui, cx.rect);
if let Some(moved) = bars.view.value() {
want = drawn_frame.offset_of(moved.center, vw, vh);
}
let offset = (want.0.clamp(xs.0, xs.1), want.1.clamp(ys.0, ys.1));
state.offset = offset;
if state.continuous && count > 0 && !went && mem.offset.is_some_and(|last| last != offset) {
state.current = page_on_line(&geo.layout, offset.1 + vh / 2.0);
}
mem.offset = Some(offset);
mem.layout = build.cache.borrow().clone();
let current_changed = state.current != started_on;
Some(Seen {
geo: drawn,
frame: drawn_frame,
view: shown,
pages,
visible,
current_changed,
pasteboard: Some(pasteboard),
resident,
next: Some(Next { started, state, mem, edit: words.edit.as_str().to_owned() }),
})
>>>>>>> origin/next
}
/// A scroll smaller than this many screen points is the arithmetic of the view's round trip, not a scroll.
@@ -1889,6 +1711,13 @@ fn shown_most(layout: &PagedLayout, current: usize, top: f64, height: f64) -> us
}
}
/// The page whose row the horizontal line at `y` (content coordinates) crosses or lies above: the first page whose
/// shown band ends below it, the last page past the end.
fn page_on_line(layout: &PagedLayout, y: f64) -> usize {
let last = layout.rects.len().saturating_sub(1);
layout.rects.iter().zip(&layout.bands).position(|(r, &(_, bottom))| r.y0 + bottom + 0.5 > y).unwrap_or(last)
}
/// Shown heights (screen points) closer than this are equal: one page size can meet the view a fraction of a point
/// differently once the offset is applied.
const PAGE_TIE: f64 = 0.5;
@@ -1916,12 +1745,6 @@ fn zoom_about(build: &Geometry, state: &mut PageViewState, old: &Placed, rect: R
new
}
<<<<<<< HEAD
/// The pages near what shows: while a continuous view travels (`travel` down the document when positive, up when
/// negative), the two rows ahead and none behind; otherwise one row either side, or the neighbouring rows of a
/// single shown row.
fn near_pages(placed: &Placed, continuous: bool, visible: &Range<usize>, count: usize, options: &LayoutOptions, travel: f64) -> Vec<usize> {
=======
/// The page whose shown band lies nearest `p` (content coordinates); the earlier page on a tie, `None` with no pages.
fn nearest_page(layout: &PagedLayout, p: Point) -> Option<usize> {
let distance = |page: usize| {
@@ -1933,10 +1756,10 @@ fn nearest_page(layout: &PagedLayout, p: Point) -> Option<usize> {
(0..layout.rects.len().min(layout.bands.len())).min_by(|&a, &b| distance(a).total_cmp(&distance(b)))
}
/// The pages one row either side of what shows: the neighbouring rows, or the neighbouring row of a single shown
/// row.
fn near_pages(placed: &Placed, continuous: bool, visible: &Range<usize>, count: usize, options: &LayoutOptions) -> Vec<usize> {
>>>>>>> origin/next
/// The pages near what shows: while a continuous view travels (`travel` down the document when positive, up when
/// negative), the two rows ahead and none behind; otherwise one row either side, or the neighbouring rows of a
/// single shown row.
fn near_pages(placed: &Placed, continuous: bool, visible: &Range<usize>, count: usize, options: &LayoutOptions, travel: f64) -> Vec<usize> {
if continuous {
if visible.is_empty() {
return Vec::new();
+15 -89
View File
@@ -91,25 +91,19 @@ impl Component for PageMetrics {
fn style(cx: &StyleCx<'_>, _: PageMetricsStyleKey) -> PageMetricsStyle {
let tokens = cx.tokens;
<<<<<<< HEAD
let inset = tokens.space.inset;
PageMetricsStyle {
metrics: Metrics::new(),
gap: inset.page_gap,
margin: inset.page_margin,
side: inset.page_side,
white_space_pad: tokens.space.gap.inline,
seam: tokens.stroke.thin,
=======
match cx.set() {
ComponentSet::Creative => PageMetricsStyle {
metrics: Metrics::new(),
gap: tokens.space.gap.section,
margin: tokens.space.pad.roomy,
side: tokens.size.rail.width,
white_space_pad: tokens.space.gap.inline,
seam: tokens.stroke.thin,
},
// The creative set's spacing is the theme's page insets.
ComponentSet::Creative => {
let inset = tokens.space.inset;
PageMetricsStyle {
metrics: Metrics::new(),
gap: inset.page_gap,
margin: inset.page_margin,
side: inset.page_side,
white_space_pad: tokens.space.gap.inline,
seam: tokens.stroke.thin,
}
}
ComponentSet::Productivity => {
let gap = tokens.space.gap.section * PRODUCTIVITY_GAP_RATIO;
PageMetricsStyle {
@@ -121,7 +115,6 @@ impl Component for PageMetrics {
seam: tokens.stroke.thin,
}
}
>>>>>>> origin/next
}
}
@@ -165,14 +158,8 @@ pub(super) struct PagePictures<'a> {
common: Common,
source: &'a dyn PageSource,
pages: &'a [PlacedPage],
<<<<<<< HEAD
/// The page view's body, whose picture stores these are (`page_stores`).
owner: Id,
=======
near: &'a [(usize, Vec2)],
/// The pages whose pictures the stores keep, sorted; every other page's are dropped.
keep: &'a [usize],
>>>>>>> origin/next
/// The document's paper under each picture.
paper: DataColor,
/// Sharp renders of the part in view wait: the view zooms or pans.
@@ -185,13 +172,8 @@ pub(super) struct PagePictures<'a> {
}
impl<'a> PagePictures<'a> {
<<<<<<< HEAD
pub(super) fn new(source: &'a dyn PageSource, pages: &'a [PlacedPage], owner: Id, paper: DataColor) -> Self {
PagePictures { common: Common::new(), source, pages, owner, paper, hold_detail: false, describer: None }
=======
pub(super) fn new(source: &'a dyn PageSource, pages: &'a [PlacedPage], near: &'a [(usize, Vec2)], keep: &'a [usize], paper: DataColor) -> Self {
PagePictures { common: Common::new(), source, pages, near, keep, paper, hold: false, describer: None }
>>>>>>> origin/next
}
}
@@ -205,7 +187,7 @@ impl Component for PagePictures<'_> {
const SHOWS_LABEL: bool = false;
const OVERLAYS: bool = false;
type Style = PagePicturesStyle;
type Output = PagePicturesOutput;
type Output = Response;
fn style(_: &StyleCx<'_>, _: PagePicturesStyleKey) -> PagePicturesStyle {
PagePicturesStyle { metrics: Metrics::new() }
@@ -225,14 +207,8 @@ impl Component for PagePictures<'_> {
let base = painter.painter.clone();
let inside = base.clip_rect();
let side = texture_side(&ctx);
<<<<<<< HEAD
let (thumbs, details) = page_stores(&ctx, self.owner, picture_options(&ctx));
details.hold(self.hold_detail);
=======
let PictureStores { thumbs, details } = PictureStores::of(&ctx, cx);
thumbs.hold(self.hold);
details.hold(self.hold);
>>>>>>> origin/next
let ppp = painter.pixels_per_point();
let paint = ThumbPaint::default().paper(self.paper).states(StateLook::Captioned);
for placed in self.pages {
@@ -249,19 +225,6 @@ impl Component for PagePictures<'_> {
}
}
}
<<<<<<< HEAD
=======
for &(page, size) in self.near {
let request = ThumbRequest::for_cell(size.x.max(size.y), ppp);
thumbs.state(&ctx, self.source, &page, &request, Priority::NEAR);
}
// Pages scrolled out of reach give their pictures back (#811: a long scroll held every page it had shown);
// a part-in-view picture is only of use while its page shows.
let keep = self.keep;
thumbs.retain(&ctx, |page| keep.binary_search(page).is_ok());
let shown = self.pages;
details.retain(&ctx, |page| shown.iter().any(|p| p.page == *page));
>>>>>>> origin/next
}
fn access(&self, access: &mut Access, _: &Cx<'_, Self>) {
@@ -274,45 +237,8 @@ impl Component for PagePictures<'_> {
}
}
fn finish(self, cx: Cx<'_, Self>) -> PagePicturesOutput {
let ctx = cx.response.ctx.clone();
let PictureStores { thumbs, details } = PictureStores::of(&ctx, &cx);
let resident = thumbs.cache().statistics(&ctx).entries + details.cache().statistics(&ctx).entries;
PagePicturesOutput { response: cx.response.clone(), resident }
}
}
/// What the pictures report: how many page pictures their stores hold.
#[derive(Debug)]
pub(super) struct PagePicturesOutput {
response: Response,
/// The entries of both stores: the pages' own pictures and the detail pictures.
pub(super) resident: usize,
}
impl Outcome for PagePicturesOutput {
type Value = NoValue;
fn response(&self) -> &Response {
&self.response
}
}
/// The two stores of the page pictures, kept in the context under the component's id: the pages' own pictures, and
/// the pictures of the part in view of a page larger than the texture side (a store of their own, so a page's two
/// regions never share a key).
struct PictureStores {
thumbs: Thumbnails<usize>,
details: Thumbnails<usize>,
}
impl PictureStores {
fn of(ctx: &egui::Context, cx: &Cx<'_, PagePictures<'_>>) -> Self {
let options = ThumbnailOptions::new().max_side(texture_side(ctx)).store(TextureStoreOptions::pages());
PictureStores {
thumbs: Thumbnails::in_context(ctx, cx.key("pictures"), options.clone()),
details: Thumbnails::in_context(ctx, cx.key("detail"), options),
}
fn finish(self, cx: Cx<'_, Self>) -> Response {
cx.response.clone()
}
}
+12 -28
View File
@@ -16,39 +16,30 @@ use egui::{Pos2, Ui};
/// Pages in the story document: enough to scroll.
const PAGES: usize = 6;
<<<<<<< HEAD
fn view(ui: &mut Ui, data: &mut StoryData, change: impl FnOnce(&mut PageViewState)) -> StoryOutput {
view_of(ui, data, &DemoPages::new(PAGES), change)
fn view(ui: &mut Ui, data: &mut StoryData, rulers: bool, change: impl FnOnce(&mut PageViewState)) -> StoryOutput {
view_of(ui, data, &DemoPages::new(PAGES), rulers, change)
}
fn view_of(ui: &mut Ui, data: &mut StoryData, pages: &DemoPages, change: impl FnOnce(&mut PageViewState)) -> StoryOutput {
=======
fn view(ui: &mut Ui, data: &mut StoryData, rulers: bool, change: impl FnOnce(&mut PageViewState)) -> StoryOutput {
>>>>>>> origin/next
fn view_of(ui: &mut Ui, data: &mut StoryData, pages: &DemoPages, rulers: bool, change: impl FnOnce(&mut PageViewState)) -> StoryOutput {
let state = data.value("view", {
let mut state = PageViewState::default();
change(&mut state);
state
});
<<<<<<< HEAD
let out = PageView::new("Pages", pages, state, PAPER).options(LayoutOptions::ACROBAT).show(ui, |_, _| ());
=======
let pages = DemoPages::new(PAGES);
let out = PageView::new("Pages", &pages, state, PAPER).options(LayoutOptions::ACROBAT).rulers(rulers).show(ui, |_, _| ());
>>>>>>> origin/next
let out = PageView::new("Pages", pages, state, PAPER).options(LayoutOptions::ACROBAT).rulers(rulers).show(ui, |_, _| ());
out.canvas.response.into()
}
/// The pages while their pictures render: each page is captioned in place of its picture.
#[story(PageView<'static>, covers = [], drive = Drive::Never)]
fn captioned_loading(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
view_of(ui, data, &DemoPages::rendering(PAGES), |state| state.continuous = false)
view_of(ui, data, &DemoPages::rendering(PAGES), false, |state| state.continuous = false)
}
/// The pages when their pictures fail to render: each page is captioned with the failure.
#[story(PageView<'static>, covers = [], drive = Drive::Never)]
fn captioned_failed(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
view_of(ui, data, &DemoPages::failing(PAGES), |state| state.continuous = false)
view_of(ui, data, &DemoPages::failing(PAGES), false, |state| state.continuous = false)
}
#[story(PageView<'static>, covers = [], drive = Drive::Never)]
@@ -127,11 +118,12 @@ fn snapped_margins(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
];
snap.page(page, margins)
});
let out = PageView::new("Pages", &pages, state, PAPER).options(LayoutOptions::ACROBAT).snap(Some(snap)).show(ui, |ui, body| {
if let Some(pass) = body.pass {
let _ = ToolHost::new().run(ui, pass, &mut MarginSnapper);
}
});
let out = PageView::new("Pages", &pages, state, PAPER).options(LayoutOptions::ACROBAT).snap(Some(snap)).show_with(
ui,
&mut MarginSnapper,
|ui, body, tool| body.pass.and_then(|pass| ToolHost::new().run(ui, pass, tool).view),
|_, _, _| (),
);
out.canvas.response.into()
}
@@ -149,16 +141,8 @@ fn page_pictures(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
let pages = DemoPages::new(1);
let placed = demo_placed(1, Pos2::new(room.min.x + 20.0, room.min.y + 10.0));
let view = CanvasView::new(room, Point::new(f64::from(room.width()) / 2.0, f64::from(room.height()) / 2.0), 1.0);
<<<<<<< HEAD
let owner = ui.id().with("page_pictures");
let shown =
Canvas::new("Document").view(view).show_at(ui, room, |ui, body| PagePictures::new(&pages, &placed, owner, PAPER).show_at(ui, body.rect));
=======
let near: [(usize, Vec2); 0] = [];
let keep = [0];
let shown = Canvas::new("Document")
.view(view)
.show_at(ui, room, |ui, body| PagePictures::new(&pages, &placed, &near, &keep, PAPER).show_at(ui, body.rect));
>>>>>>> origin/next
shown.inner.map(StoryOutput::from).unwrap_or_default()
}
+2 -12
View File
@@ -1,22 +1,12 @@
//! The screen tests of craft-pages, folded into the lib's test target.
<<<<<<< HEAD
mod range;
mod setup;
mod size_picker;
mod sync_views;
mod text_select;
mod text_tables;
mod thumbnails;
mod views;
=======
pub(crate) mod access;
pub(crate) mod range;
pub(crate) mod rulers;
pub(crate) mod setup;
pub(crate) mod size_picker;
pub(crate) mod sync_views;
pub(crate) mod text_select;
pub(crate) mod text_tables;
pub(crate) mod thumbnails;
pub(crate) mod views;
>>>>>>> origin/next
+4 -11
View File
@@ -1,15 +1,9 @@
<<<<<<< HEAD
//! The column bar: a divider drag or an arrow key moves the two columns it divides.
//! The column bar: a divider drag or an arrow key moves the two columns it divides. The Page Setup dialog's Document
//! grid: the counts follow the kind, and a refused OK shows its reason.
use craft_pages::ui::ColumnBar;
use craft_pages::ui::reading::MAX_COLUMNS;
=======
//! The column bar: a divider drag moves the two columns it divides. The Page Setup dialog's Document grid: the counts
//! follow the kind, and a refused OK shows its reason.
use craft_pages::ui::{ColumnBar, PageSetupDialog};
use craft_pages::{DocumentGrid, GridKind, MAX_GRID_COUNT, PageSetup};
>>>>>>> origin/next
use craft_ui::contract::{Bind, Show as _};
use craft_ui::dialog::HeldAnswer;
use craft_ui::runtime::env::Label;
@@ -41,7 +35,6 @@ fn a_divider_moves_only_the_two_columns_it_divides() {
assert!(close(widths[3], EQUAL), "the column past the pair is untouched: {widths:?}");
}
<<<<<<< HEAD
/// A bar over `widths`, which every pass writes back.
fn bar(widths: Vec<f64>) -> (Fixture, Rc<RefCell<Vec<f64>>>) {
let widths = Rc::new(RefCell::new(widths));
@@ -89,7 +82,8 @@ fn an_arrow_moves_the_focused_divider_one_step_and_shift_ten() {
assert!(close(jump, 10.0 * step), "Shift moves ten steps: {jump} after a step of {step}");
let widths = widths.borrow();
assert!(close(widths.iter().sum::<f64>(), EQUAL * COLUMNS as f64), "the total stays: {widths:?}");
=======
}
#[trial]
fn the_grid_counts_follow_the_grid_kind_and_a_refused_ok_shows_its_reason() {
let start = PageSetup { grid: Some(DocumentGrid::new(GridKind::None, 40, 30)), ..PageSetup::default() };
@@ -166,5 +160,4 @@ fn page_setup_rows_stand_two_to_a_line() {
let first = rect("Different First Page");
assert!((rect("Mirror margins").min.x - first.min.x).abs() < 1.0, "Mirror margins stands at its section's start");
assert!(first.max.y <= 900.0, "the last row is in view without scrolling: {first:?}");
>>>>>>> origin/next
}
+15 -25
View File
@@ -1,27 +1,21 @@
//! The page view and the page preview: the scroll anchor under a zoom change, the wheel's page turns, the pictures
//! the view asks for, the view's page and arrow keys and its zoom commands, and the preview's keys.
<<<<<<< HEAD
use craft_behavior::{GESTURE_GAP, kurbo};
use craft_pages::layout::{Fit, LayoutOptions, PageDisplay};
use craft_pages::ui::fixtures::{DemoPages, PAPER};
use craft_pages::ui::{GoTo, PageBody, PagePreview, PageRevision, PageSource, PageView, PageViewState, PlacedPage, ReadingState, ReadingView};
use craft_ui::canvas::{CanvasTool, HandTool, NavigationOptions, ToolAction, ToolContext, ToolHost, ToolKey, ToolPath, ToolPointer, WheelScheme};
use craft_ui::contract::{Bind, Role, Show as _};
use craft_ui::primitives::textures::{Revision, TextureState, ThumbRender, ThumbRequest, ThumbSource};
=======
use craft_behavior::geometry::{CropBox, SnapKind, SnapOptions, SnapTarget};
use craft_behavior::kurbo;
use craft_behavior::{Axis, CancelReason, CanvasView, EditCommand};
use craft_behavior::{GESTURE_GAP, kurbo};
use craft_pages::layout::{Fit, LayoutOptions, PageDisplay, PagedLayout};
use craft_pages::ui::fixtures::{DemoPages, PAPER};
use craft_pages::ui::{
PagePreview, PageRegion, PageSnap, PageSource, PageView, PageViewState, PageViewWords, PlacedPage, ReadingNav, ReadingState, ReadingView,
GoTo, PageBody, PagePreview, PageRegion, PageRevision, PageSnap, PageSource, PageView, PageViewState, PageViewWords, PlacedPage, ReadingNav,
ReadingState, ReadingView,
};
use craft_theme::ComponentSet;
use craft_ui::canvas::{CanvasTool, CropOverlay, ToolAction, ToolContext, ToolHost, ToolPath, ToolPointer};
use craft_ui::canvas::{
CanvasTool, CropOverlay, HandTool, NavigationOptions, ToolAction, ToolContext, ToolHost, ToolKey, ToolPath, ToolPointer, WheelScheme,
};
use craft_ui::contract::{Bind, Role, Show as _};
>>>>>>> origin/next
use craft_ui::primitives::textures::{Revision, TextureState, ThumbRender, ThumbRequest, ThumbSource};
use craft_ui::primitives::textures::TextureStoreOptions;
use craft_ui::primitives::{Draw, EditorPurpose};
@@ -31,10 +25,7 @@ use craft_ui::runtime::focus::EditSet;
use craft_ui::testing::{Fixture, pointer, trial};
use egui::{Key, Modifiers, pos2, vec2};
use std::cell::{Cell, RefCell};
<<<<<<< HEAD
use std::ops::Range;
=======
>>>>>>> origin/next
use std::rc::Rc;
/// The default state with `change` applied.
@@ -1117,7 +1108,6 @@ fn the_reading_view_turns_on_the_wheel_but_leaves_cmd_or_ctrl_with_the_wheel_to_
assert!(state.borrow().column > 0, "the wheel alone turns");
}
<<<<<<< HEAD
/// A US Letter page, points.
const LETTER: kurbo::Size = kurbo::Size::new(612.0, 792.0);
@@ -1918,7 +1908,8 @@ fn the_pasteboard_colour_of_a_page_view_paints_the_surround() {
};
assert!(!paints_black(None), "the default surround is the theme's");
assert!(paints_black(Some(PasteboardColor::Black)), "a black pasteboard paints black round the pages");
=======
}
/// The page whose tip text (one of `expected`, the words filled for pages 1, 2, ..) is painted in the latest frame.
fn page_tip(fixture: &Fixture, expected: &[String]) -> Option<usize> {
fixture.texts().iter().find_map(|run| expected.iter().position(|text| text.as_str() == &*run.text).map(|at| at + 1))
@@ -2056,7 +2047,7 @@ fn to_doc_and_from_doc_round_trip_and_page_at_doc_takes_the_nearest_page_outside
let mut fixture = Fixture::new(move |ui| {
PageView::new("Pages", &pages, &mut state, PAPER).options(LayoutOptions::ACROBAT).show(ui, |_, body| {
let [first, second, ..] = body.pages else { return };
let last = body.pages[body.pages.len() - 1];
let last = &body.pages[body.pages.len() - 1];
let at = kurbo::Point::new(100.0, 150.0);
let doc = second.to_doc(&body.view, at);
let back = second.from_doc(&body.view, doc);
@@ -2199,7 +2190,7 @@ impl CanvasTool for Snapper {
/// page points: where the drag snapped to on screen, and where the line shows on page 2.
fn drag_beside_the_line_on_page_two(state: PageViewState) -> (f32, f32) {
let tool = Rc::new(RefCell::new(Snapper::default()));
let two: Rc<Cell<Option<(PlacedPage, CanvasView)>>> = Rc::default();
let two: Rc<RefCell<Option<(PlacedPage, CanvasView)>>> = Rc::default();
let (shown_tool, seen) = (Rc::clone(&tool), Rc::clone(&two));
let pages = DemoPages::new(4);
let mut state = state;
@@ -2207,7 +2198,7 @@ fn drag_beside_the_line_on_page_two(state: PageViewState) -> (f32, f32) {
let snap = PageSnap::new(SnapOptions::default()).page(1, vec![SnapTarget::new(Axis::Y, LINE_X, SnapKind::Guide)]);
PageView::new("Pages", &pages, &mut state, PAPER).options(LayoutOptions::ACROBAT).snap(Some(snap)).show(ui, |ui, body| {
if let Some(page) = body.pages.iter().find(|placed| placed.page == 1) {
seen.set(Some((*page, body.view)));
*seen.borrow_mut() = Some((page.clone(), body.view));
}
if let Some(pass) = body.pass {
let _ = ToolHost::new().run(ui, pass, &mut *shown_tool.borrow_mut());
@@ -2216,7 +2207,7 @@ fn drag_beside_the_line_on_page_two(state: PageViewState) -> (f32, f32) {
});
fixture.room(vec2(900.0, 700.0));
fixture.settle();
let (page, _) = two.get().expect("page 2 shows");
let (page, _) = two.borrow().clone().expect("page 2 shows");
let line = page.to_screen(kurbo::Point::new(LINE_X, 200.0));
let from = line + vec2(30.0, 0.0);
fixture.frame(vec![pointer::moved(from)]);
@@ -2224,7 +2215,7 @@ fn drag_beside_the_line_on_page_two(state: PageViewState) -> (f32, f32) {
for step in 1..=3 {
fixture.frame(vec![pointer::moved(from - vec2(9.0 * step as f32, 0.0))]);
}
let (_, view) = two.get().expect("page 2 shows");
let (_, view) = two.borrow().clone().expect("page 2 shows");
let snapped = tool.borrow().snapped.expect("the tool dragged");
(view.to_screen(snapped).x, line.x)
}
@@ -2365,7 +2356,7 @@ fn gone_to(page: usize, fraction: f64, rulers: bool) -> (Option<usize>, f64, f64
});
fixture.room(vec2(1280.0, 760.0));
fixture.settle();
state.borrow_mut().go_to = Some((page, fraction));
state.borrow_mut().go_to = Some(GoTo::Top { page, fraction });
fixture.idle(3);
let (first, before, at) = *seen.borrow();
(first, state.borrow().offset.1, before, at)
@@ -2545,5 +2536,4 @@ fn page_view_forwards_inactive_edits_to_its_editor_canvas() {
inactive.set(EditSet::NONE.with(EditCommand::Undo).with(EditCommand::Redo));
fixture.settle();
assert!(resolve(fixture.ctx(), EditCommands::Cut).enabled, "active Cut resolves enabled on focused PageView");
>>>>>>> origin/next
}
+1 -5
View File
@@ -20,11 +20,7 @@ workspace = true
suite = ["screen-testing", "craft-ui/suite"]
default = []
# The review widgets (`craft_review::ui`).
<<<<<<< HEAD
ui = ["dep:craft-keymap", "dep:craft-ui", "dep:craft-host", "dep:craft-theme", "dep:egui"]
=======
ui = ["dep:craft-keymap", "dep:craft-pages", "craft-pages/ui", "dep:craft-ui", "dep:craft-host", "dep:craft-theme", "dep:egui", "dep:image"]
>>>>>>> origin/next
ui = ["dep:craft-keymap", "dep:craft-pages", "craft-pages/ui", "dep:craft-ui", "dep:craft-host", "dep:craft-theme", "dep:egui"]
# The stories and the integration tests (`tests/it`).
screen-testing = ["ui", "craft-ui/testing", "craft-pages/screen-testing"]
+12 -33
View File
@@ -37,15 +37,11 @@ use crate::comments::{CommentFilter, CommentSort, CommentThread, PageOrder, Revi
use list::{CardKey, CommentList, RowEntry, Rows};
use menus::{card_menu, filter_menu, pages_menu, sort_menu};
<<<<<<< HEAD
pub use menus::{comments_filter_menu, comments_more_menu};
use row::{CommentRow, MORE};
=======
use row::MORE;
pub(super) use list::CardEvent;
pub(super) use row::{CardActions, CommentRow};
>>>>>>> origin/next
/// Ages under this many seconds (one week) read relative; older ones read as a date.
pub(crate) const AGE_SHOWN_AS_DATE: u64 = 7 * 24 * 60 * 60;
@@ -287,24 +283,15 @@ pub(crate) fn age_text(env: &EnvView<'_>, then: i64, now: i64) -> String {
/// - Cards in one collection, grouped under headings by [`sort_threads`]; under the Page sort a
/// heading names the page, shows the count of the page's comments before filtering and folds its
/// cards. A card shows the kind's icon, author, age (relative under a week, then the date), the
<<<<<<< HEAD
/// text, a badge per reviewer's status, the checkmark, a lock icon and the replies, each with its own "..." menu.
/// - Selected cards have the highlight; the lead (the first selected) has the accent bar, the reply box and "..."
/// (Edit, Set status, Delete, then the host's [`card_rows`](CommentsPanel::card_rows)). Locked threads and
/// `read_only` hide the editing items. A double click on a card edits its comment in place.
/// `read_only` hide the editing items. A double click on a card edits its comment in place; an inline editor
/// takes the keyboard in the pass it opens. A new lead drops the reply draft and the edit of another thread; a
/// card made the lead again keeps its own edit draft.
/// - Keyboard: Up and Down move between cards (selecting them), Enter puts the focus in the lead card's reply box,
/// the [`reply_submit`](CommentsPanel::reply_submit) key in the reply box and Cmd+Enter (Ctrl+Enter off macOS) in
/// an inline editor post, Escape in a control of a card returns to the card.
=======
/// text, a status icon, the checkmark, a lock icon and the replies, each with its own "..." menu.
/// - The selected card has the accent bar, the reply box and "..." (Edit, Set status, Delete).
/// Locked threads and `read_only` hide the editing items. An inline editor takes the keyboard in
/// the pass it opens. Selecting another card drops the reply draft and the edit of another
/// thread; a card selected again keeps its own edit draft.
/// - Keyboard: Up and Down move between cards (selecting them), Enter puts the focus in the selected
/// card's reply box, Cmd+Enter (Ctrl+Enter off macOS) in the reply box or an inline editor posts,
/// Escape in a control of a card returns to the card.
>>>>>>> origin/next
///
/// ```ignore
/// let out = CommentsPanel::new("Comments", &threads, &mut state).now(now).show(ui);
@@ -482,28 +469,18 @@ fn toggle<T: PartialEq>(list: &mut Vec<T>, value: T) {
}
}
<<<<<<< HEAD
/// Makes `next` the selection; true when its threads changed. A new lead drops the reply draft and the inline edit,
/// which belong to the old lead's card.
/// Makes `next` the selection; true when its threads changed. A new lead drops the reply draft, which belongs to the
/// old lead's card, and an edit of another thread; an edit of the new lead itself stays, so a draft the app could not
/// write back (a document that refused it) is there again, with the keyboard, when its card leads again.
fn set_selection(state: &mut CommentsPanelState, next: Selection<ThreadId>) -> bool {
let changed = next.items != state.selected.items;
if next.lead != state.selected.lead {
state.reply.clear();
state.editing = None;
state.focus_editor = false;
=======
/// Makes `thread` the selected one; false when it already was. The reply draft and an edit of another thread go; an
/// edit of `thread` itself stays, so a draft the app could not write back (a document that refused it) is there again
/// when its card is selected again.
fn select_thread(state: &mut CommentsPanelState, thread: ThreadId) -> bool {
let changed = state.selected != Some(thread);
if changed {
state.selected = Some(thread);
state.reply.clear();
if state.editing.as_ref().is_some_and(|(editing, ..)| *editing != thread) {
let kept = state.editing.as_ref().is_some_and(|(editing, ..)| Some(*editing) == next.lead);
if !kept {
state.editing = None;
}
>>>>>>> origin/next
state.focus_editor = kept;
}
state.selected = next;
changed
@@ -709,7 +686,9 @@ impl<H: Value> CommentsPanel<'_, H> {
let out = CommentList::new(label.clone(), Some(Bind::bound(&mut selection)), grouped, select_mode)
.revealing(revealing.map(CardKey::Thread))
.show_items(ui, &source, &mut |_, item| match &source.entries[item.at].1 {
RowEntry::Group { title, count, open, page } => CommentRow::heading(title.clone(), count.clone(), *open, !by_page || page.is_none()),
RowEntry::Group { title, count, open, page } => {
CommentRow::heading(title.clone(), count.clone(), *open, !by_page || page.is_none())
}
RowEntry::Card { thread, .. } => {
let name = thread
.messages
+15 -67
View File
@@ -7,12 +7,8 @@ use craft_theme::variant::{Emphasis, Tone as BadgeTone, Variant};
use craft_ui::buttons::{Button, IconButton};
use craft_ui::contract::{Bind, Common, Component, Cx, MeasureCx, PaintUi, PartsCx, Props as _, Remember as _, Role, WordSetCx as _, clicked};
use craft_ui::controls::disclosure::DisclosureGlyph;
<<<<<<< HEAD
use craft_ui::display::Badge;
use craft_ui::primitives::{HAlign, IconSpec, PaintShape, StrokeWidth, SubmitKey, TextRun, Wrap};
=======
use craft_ui::primitives::{HAlign, IconSpec, PaintShape, StrokeWidth, TextRun, Wrap};
>>>>>>> origin/next
use craft_ui::runtime::env::Label;
use craft_ui::runtime::focus::{self, FocusTarget};
use craft_ui::style::{ComponentStyle, DataColor, Ink, StyleColor, StyleCx, TypeRole};
@@ -116,17 +112,14 @@ enum Slot {
EditCancel,
ReplyField,
ReplyPost,
<<<<<<< HEAD
/// The badge of the reviewer status at this index of the thread's statuses.
Status(usize),
=======
/// The balloon button that puts the focus in the reply field.
Reply,
/// The balloon button that resolves or reopens the thread.
Resolve,
/// The balloon button that deletes the thread.
Delete,
>>>>>>> origin/next
/// The badge of the reviewer status at this index of the thread's statuses.
Status(usize),
}
/// How many push buttons a row sizes: `push_index` gives each its place.
@@ -168,10 +161,9 @@ trait Sink {
/// The "..." button of message `index` of a card: a part of the row that opens the message's menu.
pub(super) const MORE: PartKey = PartKey::new("more");
<<<<<<< HEAD
/// Reply `index` of a card: the access node that names it.
const REPLY: PartKey = PartKey::new("reply");
=======
/// What a card offers for acting on its thread.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub(crate) enum CardActions {
@@ -185,7 +177,6 @@ pub(crate) enum CardActions {
/// The message whose inline editor a row showed at its last pass, if any.
#[derive(Clone, Copy, Default)]
struct EditShown(Option<usize>);
>>>>>>> origin/next
/// A card or a heading of the card collection.
#[derive(craft_ui::contract::Component, craft_ui::contract::Props)]
@@ -206,13 +197,11 @@ pub(crate) struct CommentRow<'r> {
/// The activation key reached the card this pass: its reply box takes the focus, when it shows one.
#[prop]
focus_reply: bool,
<<<<<<< HEAD
/// The inline editor takes the focus this pass, when the card shows one.
/// The inline editor takes the focus this pass, when the card shows one: for an editor the panel opens.
#[prop]
focus_editor: bool,
/// The key that submits the reply box.
submit_key: SubmitKey,
=======
/// The inline editor opened this pass (it did not show the pass before): its field takes the keyboard, so the
/// first click that opens an edit is enough to type.
focus_edit: bool,
@@ -222,18 +211,13 @@ pub(crate) struct CommentRow<'r> {
/// Limits each message's text to `rows` rows.
#[prop(vis = "pub(crate)")]
body_rows: Option<usize>,
>>>>>>> origin/next
words: Option<Arc<CommentsWords>>,
/// The heights the editor field and the reply field measured, for the paint of the same pass.
heights: [f32; 2],
/// The sizes the push buttons measured, for the paint of the same pass.
<<<<<<< HEAD
buttons: [Vec2; 3],
buttons: [Vec2; PUSH_BUTTONS],
/// The sizes the status badges measured, in the order of the thread's statuses, for the paint of the same pass.
badges: Vec<Vec2>,
=======
buttons: [Vec2; PUSH_BUTTONS],
>>>>>>> origin/next
/// The messages whose "..." button the parts step declared.
mores: Vec<usize>,
/// Each reply's index and its rect on the screen, from the parts step.
@@ -255,21 +239,15 @@ impl<'r> CommentRow<'r> {
editing: None,
reply: "",
focus_reply: false,
<<<<<<< HEAD
focus_editor: false,
submit_key: SubmitKey::default(),
words: None,
heights: [0.0; 2],
buttons: [Vec2::ZERO; 3],
badges: Vec::new(),
=======
focus_edit: false,
actions: CardActions::default(),
body_rows: None,
words: None,
heights: [0.0; 2],
buttons: [Vec2::ZERO; PUSH_BUTTONS],
>>>>>>> origin/next
badges: Vec::new(),
mores: Vec::new(),
replies: Vec::new(),
events: Vec::new(),
@@ -398,12 +376,8 @@ impl CommentRow<'_> {
let first = thread.messages.first();
sink.kind(square(Pos2::new(pad, y), h), kind_icon(thread.kind), thread.color);
let mut end = width - pad;
<<<<<<< HEAD
if self.lead && self.editable {
=======
let menu = self.actions == CardActions::Menu;
if self.selected && self.editable && menu {
>>>>>>> origin/next
if self.lead && self.editable && menu {
end -= h;
sink.button(Slot::More(0), square(Pos2::new(end, y), h), "more", &words.more, false);
}
@@ -633,15 +607,9 @@ struct Paint<'a, 'b> {
thread: Option<ThreadId>,
resolved: bool,
heights: [f32; 2],
<<<<<<< HEAD
buttons: [Vec2; 3],
buttons: [Vec2; PUSH_BUTTONS],
badges: &'a [Vec2],
reply_submit: SubmitKey,
/// The field that takes the focus as it shows (the reply box or the inline editor), and the context the request
/// goes to.
focus: Option<(Slot, &'a egui::Context)>,
=======
buttons: [Vec2; PUSH_BUTTONS],
/// The context focus requests go to.
ctx: &'a egui::Context,
/// Set when the reply box takes the focus as it shows.
@@ -650,7 +618,6 @@ struct Paint<'a, 'b> {
focus_edit: bool,
/// The reply field's id once it is shown, for the Reply button to focus.
reply_id: Option<egui::Id>,
>>>>>>> origin/next
events: &'a mut Vec<CardEvent>,
}
@@ -756,12 +723,6 @@ impl Sink for Paint<'_, '_> {
if out.escaped && slot == Slot::EditField {
self.events.push(CardEvent::EditCancel);
}
<<<<<<< HEAD
if let Some((focused, ctx)) = self.focus
&& focused == slot
{
focus::request(ctx, FocusTarget::Id(out.response.id));
=======
if slot == Slot::ReplyField {
self.reply_id = Some(out.response.id);
if self.focus_reply {
@@ -769,7 +730,6 @@ impl Sink for Paint<'_, '_> {
}
} else if self.focus_edit {
focus::request(self.ctx, FocusTarget::Id(out.response.id));
>>>>>>> origin/next
}
height
}
@@ -862,17 +822,11 @@ impl Component for CommentRow<'_> {
muted: cx.color(color.text.muted),
highlight: cx.color(color.surface.raised),
bar: cx.color(color.accent.solid),
<<<<<<< HEAD
card: cx.color(color.surface.raised),
border: cx.color(color.line.border),
avatar: cx.color(color.line.border),
avatar_ink: cx.color(color.text.normal),
thread_line: cx.color(color.line.divider),
=======
card: cx.color(color.surface.raised),
border: cx.color(color.line.border),
avatar: cx.color(color.accent.strong),
avatar_ink: cx.color(color.text.on_strong),
sunken: cx.color(color.surface.sunken),
>>>>>>> origin/next
kind_icon: cx.tokens.size.icon.sm,
glyph: cx.glyph(),
bar_width: cx.tokens.stroke.thick,
@@ -891,11 +845,8 @@ impl Component for CommentRow<'_> {
self.words = Some(cx.words::<CommentsWords>());
let now = self.now;
let age = |then: i64| age_text(&cx.env, then, now);
<<<<<<< HEAD
let mut sink = Measure { cx, fields: [0.0; 2], buttons: [Vec2::ZERO; 3], more: Vec::new(), badges: Vec::new(), replies: Vec::new() };
=======
let mut sink = Measure { cx, fields: [0.0; 2], buttons: [Vec2::ZERO; PUSH_BUTTONS], more: Vec::new() };
>>>>>>> origin/next
let mut sink =
Measure { cx, fields: [0.0; 2], buttons: [Vec2::ZERO; PUSH_BUTTONS], more: Vec::new(), badges: Vec::new(), replies: Vec::new() };
let height = self.lay(cx.style, width, &age, &mut sink);
self.heights = sink.fields;
self.buttons = sink.buttons;
@@ -960,16 +911,13 @@ impl Component for CommentRow<'_> {
resolved: self.thread.is_some_and(|t| t.resolved),
heights: self.heights,
buttons: self.buttons,
<<<<<<< HEAD
badges: &self.badges,
reply_submit: self.submit_key,
focus: if self.focus_editor { Some((Slot::EditField, &cx.ctx)) } else { self.focus_reply.then_some((Slot::ReplyField, &cx.ctx)) },
=======
ctx: &cx.ctx,
focus_reply: self.focus_reply,
focus_edit: self.focus_edit,
// The editor the panel opens takes the focus before the reply box, as either opening does.
focus_reply: self.focus_reply && !self.focus_editor,
focus_edit: self.focus_edit || self.focus_editor,
reply_id: None,
>>>>>>> origin/next
events: &mut events,
};
self.lay(st, rect.width(), &age, &mut sink);
+1 -6
View File
@@ -6,13 +6,8 @@ use craft_ui::testing::{Drive, StoryData, StoryOutput, show_as_only_item, story}
use egui::Ui;
use super::list::{CardKey, CommentList, RowEntry, Rows};
<<<<<<< HEAD
use super::row::CommentRow;
use super::{CommentsHeader, CommentsPanel, CommentsPanelState};
=======
use super::row::{CardActions, CommentRow};
use super::{CommentsPanel, CommentsPanelState};
>>>>>>> origin/next
use super::{CommentsHeader, CommentsPanel, CommentsPanelState};
use crate::annotate::AnnotationKind;
use crate::comments::{CommentAnchor, CommentMessage, CommentThread, ReviewStatus, ReviewerStatus, ThreadId};
+1 -7
View File
@@ -1,15 +1,9 @@
//! Stories of the signature pad.
<<<<<<< HEAD
use super::{DrawPad, ScanEvent, SignaturePadDialog};
use crate::signature::{SignatureDraft, SignatureImage, SignatureTab};
use craft_ui::buttons::Button;
use craft_ui::contract::{Bind, Show as _, Validity, clicked};
=======
use super::{DrawPad, SignaturePadDialog};
use crate::signature::SignatureDraft;
use craft_ui::contract::{Show as _, Validity};
>>>>>>> origin/next
use craft_ui::contract::{Show as _, Validity, clicked};
use craft_ui::dialog::StackDialog as _;
use craft_ui::display::Text;
use craft_ui::popover::DropVeil;
-7
View File
@@ -6,18 +6,11 @@
//! ```
mod mention;
<<<<<<< HEAD
mod note_popup;
mod pins;
mod popover;
#[cfg(feature = "screen-testing")]
mod stories;
=======
pub(crate) mod pins;
pub(crate) mod popover;
#[cfg(feature = "suite")]
pub(crate) mod stories;
>>>>>>> origin/next
pub use mention::{insert_mention, mention_matches, mention_query};
pub use note_popup::{NOTE_POPUP_LIMITS, NoteDrafts, NotePopup, NotePopupMessage, NotePopupOutput};
+2 -8
View File
@@ -1,14 +1,8 @@
//! The screen tests of craft-review, folded into the lib's test target.
<<<<<<< HEAD
mod annotate;
mod collab;
mod comments;
mod note_popup;
mod signature;
=======
pub(crate) mod annotate;
pub(crate) mod balloons;
pub(crate) mod collab;
pub(crate) mod comments;
>>>>>>> origin/next
pub(crate) mod note_popup;
pub(crate) mod signature;
-4
View File
@@ -557,13 +557,9 @@ impl Component for TextEditor<'_> {
const ROLE: Role = Role::MULTILINE_TEXT_INPUT;
const INPUT: craft_ui::contract::Input = craft_ui::contract::Input::Editor;
/// Escape always ends the session, so the editor keeps it from its row and from the shortcuts while focused.
<<<<<<< HEAD
const KEYS: KeyUse = KeyUse::CODE.with_claims(&[ESCAPE]).with_holds_drafts();
=======
const KEYS: KeyUse = KeyUse::CODE.with_claims(&[ESCAPE]);
/// When the session ends, focus goes back to the stop it came from (the canvas), not to the stop before the editor.
const FOCUS_SCOPE: FocusPolicy = FocusPolicy::TAB_LAYER;
>>>>>>> origin/next
type Style = TextEditorStyle;
type Output = TextEditorOutput;
+3 -17
View File
@@ -296,13 +296,8 @@ fn on_canvas(ui: &mut Ui, data: &mut StoryData, text: &str, selection: TextSelec
/// The editor `field` over `text` with `selection` on a canvas.
fn as_field(ui: &mut Ui, data: &mut StoryData, text: &str, selection: TextSelection, field: Field) -> StoryOutput {
let mut host = data.value("text", text.to_owned()).clone();
<<<<<<< HEAD
let selection = data.value("selection", selection);
let out = over_canvas(ui, &mut host, Bind::bound(&mut *selection), field);
=======
let (selection, selection_at) = data.value_at("selection", selection);
let out = over_canvas(ui, &mut host, selection_at.bind(&mut *selection));
>>>>>>> origin/next
let out = over_canvas(ui, &mut host, selection_at.bind(&mut *selection), field);
*data.value("text", String::new()) = host;
out
}
@@ -336,13 +331,8 @@ fn composing(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
#[story(TextEditor<'static>, covers = [Mixed], drive = Drive::Never)]
fn selections_that_differ(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
let mut host = data.value("text", SAMPLE.to_owned()).clone();
<<<<<<< HEAD
let selection = data.value("selection", Mixed::<TextSelection>::Mixed);
over_canvas(ui, &mut host, Bind::bound_mixed(&mut *selection), Field::CANVAS)
=======
let (selection, selection_at) = data.value_at("selection", Mixed::<TextSelection>::Mixed);
over_canvas(ui, &mut host, selection_at.bind_mixed(&mut *selection))
>>>>>>> origin/next
over_canvas(ui, &mut host, selection_at.bind_mixed(&mut *selection), Field::CANVAS)
}
#[story(TextEditor<'static>, covers = [Invalid], drive = Drive::Never)]
@@ -353,8 +343,7 @@ fn selection_past_the_text(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
let inside = |end: &usize, selection: &TextSelection| {
if selection.caret > *end { Validity::Refuse(Message::new("The selection is past the text")) } else { Validity::Ok }
};
<<<<<<< HEAD
over_canvas(ui, &mut host, Bind::bound(&mut *selection).check(inside), Field::CANVAS)
over_canvas(ui, &mut host, selection_at.bind(&mut *selection).check_with(end, inside), Field::CANVAS)
}
/// A one-line form field with the caret after its text.
@@ -380,7 +369,4 @@ fn editor_field_lines(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
#[story(TextEditor<'static>, covers = [], drive = Drive::Never)]
fn editor_masked(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
as_field(ui, data, "hunter22", TextSelection::caret_at(8), Field { masked: true, ..Field::mode(EditorMode::FieldLine) })
=======
over_canvas(ui, &mut host, selection_at.bind(&mut *selection).check_with(end, inside))
>>>>>>> origin/next
}
+5 -4
View File
@@ -215,7 +215,9 @@ fn a_field_editor_keeps_its_draft_when_its_popup_is_used() {
CalendarPopover::new("Calendar", Bind::bound(&mut open), Bind::bound(&mut picked))
.precisions(&[DatePrecision::Day])
.overlay(|overlay| {
overlay.anchor(Anchor::Rect(bounds)).focus(FocusPolicy::POPUP.trap(false).restore(false).initial(Initial::KeepAnchor))
overlay
.anchor(Anchor::Rect(bounds))
.focus(FocusPolicy::POPUP.trap(false).restore(false).initial(Initial::KeepAnchor))
.dismiss(Dismiss::new().focus_left(false))
})
.show(ui, |_, _| {});
@@ -430,7 +432,6 @@ fn formatting_keys_follow_the_flow_and_fall_back_to_caret_moves() {
assert_eq!(plain.selection.borrow().caret, before.saturating_sub(LINE), "the step the host did not take moved the caret a line up");
}
<<<<<<< HEAD
/// A focused editor in `mode` over "abc", `masked` or not, with the caret after the text.
fn field(mode: EditorMode, masked: bool) -> Session {
let mut editor = session_on(Host { text: "abc".to_owned(), ..Host::default() }, None, false, mode, masked);
@@ -604,7 +605,8 @@ fn after_escape_closes_a_focused_editor_in_the_canvas_body_the_next_escape_reach
assert_eq!(tool.borrow().cancels, 0, "the editor's Escape is not the tool's");
fixture.frame(escape()).settle();
assert_eq!(tool.borrow().cancels, 1, "the next Escape reaches the tool");
=======
}
/// #15555: a session the app ends (Cmd+Enter, then the editor is not shown) on a canvas with rulers hands the focus back
/// to the canvas it came from, not to the stop before the editor (the rulers' corner, whose arrows move the zero point),
/// and the view stays where it was. Without rulers the canvas is that stop anyway.
@@ -651,5 +653,4 @@ fn an_ended_session_returns_the_focus_to_the_canvas_and_the_view_stays() {
assert_eq!(focused(&fixture).as_deref(), Some("Document"), "rulers {rulers}: the focus went back to the canvas");
assert_eq!(view.get(), before, "rulers {rulers}: the view stays");
}
>>>>>>> origin/next
}
+5 -9
View File
@@ -2,22 +2,18 @@
// Unwrapping, expecting and panicking on failure is fine in tests, unlike in shipped code.
#![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
<<<<<<< HEAD
mod editor;
mod find_bar;
mod find_matches;
mod format_text;
mod notes;
mod path_text;
=======
pub(crate) mod editor;
#[cfg(feature = "find")]
pub(crate) mod find;
#[cfg(feature = "find")]
pub(crate) mod find_bar;
#[cfg(feature = "find")]
pub(crate) mod find_matches;
pub(crate) mod format_text;
pub(crate) mod hyperlink;
pub(crate) mod notes;
pub(crate) mod paragraph;
pub(crate) mod path_text;
>>>>>>> origin/next
pub(crate) mod ruler;
pub(crate) mod style_options;