mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 02:09:00 +00:00
fw sync: review/pages/draw/text compile: comment selection and status fields, note popup scope, story binds, memoized-view preview trial, trials registered
This commit is contained in:
@@ -50,9 +50,9 @@ fn skewed_page(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
/// shield dims the frame outside the quad.
|
||||
#[story(PerspectiveCropQuad<'static>, covers = [], drive = Drive::Drag(Grip::part(CORNER.at(0))))]
|
||||
fn bounded_quad(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let quad = data.value("quad", Some(PAGE));
|
||||
let (quad, quad_at) = data.value_at("quad", Some(PAGE));
|
||||
on_canvas(ui, |ui, at| {
|
||||
PerspectiveCropQuad::new("Perspective crop", Bind::bound(&mut *quad))
|
||||
PerspectiveCropQuad::new("Perspective crop", quad_at.bind(&mut *quad))
|
||||
.show_grid(false)
|
||||
.shield(CropShield::PERSPECTIVE)
|
||||
.bounds(FRAME)
|
||||
|
||||
@@ -10,7 +10,7 @@ pub(crate) mod stories;
|
||||
use super::view::{PageViewOutput, PageViewState};
|
||||
use craft_behavior::Proposal;
|
||||
use craft_ui::canvas::{SplitAt, SplitLayout, SplitViews};
|
||||
use craft_ui::contract::{Bind, EditResponse, Outcome, Pad, Props as _, Show as _, ShowContainer as _};
|
||||
use craft_ui::contract::{Bind, EditResponse, Outcome, Pad, Show as _, ShowContainer as _};
|
||||
use craft_ui::display::{Elide, Shade, Text};
|
||||
use craft_ui::layout_components::Stack;
|
||||
use craft_ui::runtime::env::Label;
|
||||
|
||||
@@ -189,11 +189,6 @@ fn glyph_rects(text: &dyn PageTextSource, glyphs: &[usize]) -> Vec<Rect> {
|
||||
runs(glyphs).into_iter().flat_map(|run| text.line_rects(run)).collect()
|
||||
}
|
||||
|
||||
/// The glyphs of a run, both ends included.
|
||||
fn run_range(anchor: usize, head: usize) -> Range<usize> {
|
||||
anchor.min(head)..anchor.max(head).saturating_add(1)
|
||||
}
|
||||
|
||||
/// `glyphs` as ranges of consecutive indices.
|
||||
fn runs(glyphs: &[usize]) -> Vec<Range<usize>> {
|
||||
let mut runs: Vec<Range<usize>> = Vec::new();
|
||||
|
||||
@@ -1781,7 +1781,7 @@ fn near_pages(placed: &Placed, continuous: bool, visible: &Range<usize>, count:
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
pub(crate) mod tests {
|
||||
use super::clamp_between;
|
||||
use craft_ui::testing::trial;
|
||||
|
||||
|
||||
@@ -141,7 +141,7 @@ 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);
|
||||
let owner = ui.id().with("page_pictures");
|
||||
let owner = ui.scope_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));
|
||||
shown.inner.map(StoryOutput::from).unwrap_or_default()
|
||||
|
||||
@@ -248,7 +248,7 @@ fn strip_drag_inserts_after_the_lower_half_of_a_page() {
|
||||
/// drag lands its move on its release as any drag does.
|
||||
#[trial]
|
||||
fn after_a_cancelled_drag_the_next_drag_lands_its_move() {
|
||||
let id = egui::Id::new("organize");
|
||||
let id = egui::Id::unique("organize");
|
||||
let (mut fixture, events, _) = organize_rig(4, id, 0);
|
||||
let (from, to) = (tile(&fixture, 1), tile(&fixture, 3));
|
||||
let reorders = |events: &RefCell<Vec<ThumbnailEvent>>| events.borrow().iter().filter(|event| matches!(event, ThumbnailEvent::Reorder(_))).count();
|
||||
@@ -266,7 +266,7 @@ fn after_a_cancelled_drag_the_next_drag_lands_its_move() {
|
||||
#[trial]
|
||||
fn a_modified_click_on_an_empty_pick_starts_from_the_current_page() {
|
||||
for (modifiers, want) in [(egui::Modifiers::COMMAND, vec![1, 3]), (egui::Modifiers::SHIFT, vec![1, 2, 3])] {
|
||||
let (mut fixture, _, picked) = organize_rig(5, egui::Id::new("organize"), 1);
|
||||
let (mut fixture, _, picked) = organize_rig(5, egui::Id::unique("organize"), 1);
|
||||
let page = tile(&fixture, 4);
|
||||
fixture.hold(modifiers).click_at(page).settle();
|
||||
fixture.hold(egui::Modifiers::NONE);
|
||||
|
||||
@@ -829,21 +829,34 @@ fn the_preview_takes_page_keys_when_first_opened() {
|
||||
assert_eq!(*at.borrow(), 2, "Page Down steps the newly opened preview");
|
||||
}
|
||||
|
||||
#[trial]
|
||||
fn the_preview_in_a_settled_region_takes_page_keys_when_opened() {
|
||||
let at = Rc::new(RefCell::new(1_usize));
|
||||
let kept = Rc::clone(&at);
|
||||
/// The memoized view that holds the Preview button and, once it was pressed, the preview.
|
||||
#[derive(craft_ui::contract::MemoProps)]
|
||||
struct PreviewRegion {}
|
||||
|
||||
thread_local! {
|
||||
/// What the preview region shows: whether the preview is open, and the page it is at.
|
||||
static PREVIEW_REGION: RefCell<(bool, usize)> = const { RefCell::new((false, 1)) };
|
||||
}
|
||||
|
||||
fn preview_region(_: &mut PreviewRegion, ui: &mut egui::Ui) {
|
||||
if craft_ui::contract::clicked(&craft_ui::buttons::Button::new("Preview").show(ui)) {
|
||||
PREVIEW_REGION.with(|region| region.borrow_mut().0 = true);
|
||||
}
|
||||
let pages = DemoPages::new(5);
|
||||
let mut open = false;
|
||||
PREVIEW_REGION.with(|region| {
|
||||
let (open, at) = &mut *region.borrow_mut();
|
||||
if *open {
|
||||
PagePreview::new(&pages, &[0, 1, 2, 3, 4], at, PAPER).show(ui);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// A preview opened inside a settled memoized view (a docked panel's body) takes the page keys.
|
||||
#[trial]
|
||||
fn the_preview_in_a_settled_view_takes_page_keys_when_opened() {
|
||||
PREVIEW_REGION.with(|region| *region.borrow_mut() = (false, 1));
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
craft_ui::contract::Lazy::new("region", 0.0).settles(true).show(ui, |ui| {
|
||||
if craft_ui::contract::clicked(&craft_ui::buttons::Button::new("Preview").show(ui)) {
|
||||
open = true;
|
||||
}
|
||||
if open {
|
||||
PagePreview::new(&pages, &[0, 1, 2, 3, 4], &mut kept.borrow_mut(), PAPER).show(ui);
|
||||
}
|
||||
});
|
||||
craft_ui::contract::MemoView::new("region", PreviewRegion {}, preview_region).show(ui);
|
||||
});
|
||||
fixture.room(vec2(900.0, 600.0)).settle();
|
||||
let button = fixture.by_label("Preview").expect("preview button");
|
||||
@@ -851,7 +864,7 @@ fn the_preview_in_a_settled_region_takes_page_keys_when_opened() {
|
||||
// Focus entered this modal after the command board last recorded its vantage.
|
||||
craft_ui::runtime::commands::clear_focus_vantage(fixture.ctx());
|
||||
fixture.key(Key::PageDown, Modifiers::NONE);
|
||||
assert_eq!(*at.borrow(), 2, "Page Down steps the preview in a settled region");
|
||||
assert_eq!(PREVIEW_REGION.with(|region| region.borrow().1), 2, "Page Down steps the preview in a settled view");
|
||||
}
|
||||
|
||||
#[trial]
|
||||
|
||||
@@ -240,7 +240,7 @@ impl<'a> CommentBalloons<'a> {
|
||||
}
|
||||
for thread in pressed {
|
||||
if state.selected.lead != Some(thread.id) {
|
||||
state.reveal(thread);
|
||||
state.reveal(thread.id);
|
||||
edits.push(CommentEdit::Select(vec![thread.id]));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ fn thread(id: u64, author: &str, text: &str, locked: bool) -> CommentThread {
|
||||
text: text.into(),
|
||||
reactions: Vec::new(),
|
||||
read: true,
|
||||
deletable: true,
|
||||
};
|
||||
CommentThread {
|
||||
id: ThreadId(id),
|
||||
@@ -32,7 +33,8 @@ fn thread(id: u64, author: &str, text: &str, locked: bool) -> CommentThread {
|
||||
kind: None,
|
||||
color: None,
|
||||
messages: vec![message(author, text), message("Bo", "Agreed.")],
|
||||
status: ReviewStatus::None,
|
||||
statuses: Vec::new(),
|
||||
reply_statuses: Vec::new(),
|
||||
marked: false,
|
||||
locked,
|
||||
resolved: false,
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
//! ```
|
||||
|
||||
mod mention;
|
||||
mod note_popup;
|
||||
pub(crate) mod note_popup;
|
||||
pub(crate) mod pins;
|
||||
pub(crate) mod popover;
|
||||
#[cfg(feature = "suite")]
|
||||
|
||||
@@ -117,7 +117,7 @@ impl NoteBody<'_, '_> {
|
||||
// The tint goes in behind the body's content, over the window's surface.
|
||||
let tint = ui.painter().add(egui::Shape::Noop);
|
||||
// The body sits on the note's pale tint, so it reads in the light palette whatever the theme: light fields, dark ink.
|
||||
Stack::new().fill_width().theme(ThemeScope::mode(Mode::Light)).show(ui, |ui, _| {
|
||||
Stack::new().fill_width().theme(ThemeScope::new().mode(Mode::Light)).show(ui, |ui, _| {
|
||||
if let Some(note) = messages.first() {
|
||||
if self.allowed && note.editable {
|
||||
self.note_text(ui, note, words);
|
||||
|
||||
@@ -16,8 +16,9 @@ fn thread(id: u64, text: &str) -> CommentThread {
|
||||
anchor: CommentAnchor::Page { page: 0, at: [0.0, 0.0] },
|
||||
kind: None,
|
||||
color: None,
|
||||
messages: vec![CommentMessage { author: "Ana".into(), created: 0, modified: None, text: text.into(), reactions: Vec::new(), read: true }],
|
||||
status: ReviewStatus::None,
|
||||
messages: vec![CommentMessage { author: "Ana".into(), created: 0, modified: None, text: text.into(), reactions: Vec::new(), read: true, deletable: true }],
|
||||
statuses: Vec::new(),
|
||||
reply_statuses: Vec::new(),
|
||||
marked: false,
|
||||
locked: false,
|
||||
resolved: false,
|
||||
@@ -115,7 +116,7 @@ fn selecting_a_card_and_posting_a_reply_report_the_matching_edits() {
|
||||
let card = shown.card(1);
|
||||
shown.fixture.click_at(card.center()).settle();
|
||||
assert!(
|
||||
shown.edits.borrow().iter().any(|edit| matches!(edit, CommentEdit::Select(thread) if *thread == ThreadId(1))),
|
||||
shown.edits.borrow().iter().any(|edit| matches!(edit, CommentEdit::Select(threads) if threads == &[ThreadId(1)])),
|
||||
"a click on a card reports its selection: {:?}",
|
||||
shown.edits.borrow()
|
||||
);
|
||||
@@ -159,7 +160,7 @@ fn reselecting_a_card_keeps_its_edit_draft() {
|
||||
#[trial]
|
||||
fn an_edit_that_opens_takes_the_keyboard() {
|
||||
let threads = vec![(thread(1, "First"), 100.0)];
|
||||
let selected = CommentsPanelState { selected: Some(ThreadId(1)), ..CommentsPanelState::default() };
|
||||
let selected = CommentsPanelState { selected: craft_behavior::Selection::single(ThreadId(1)), ..CommentsPanelState::default() };
|
||||
let mut shown = Shown::new(threads, selected, BalloonPlace::Column, room(), Direction::Ltr);
|
||||
let words = CommentsWords::default();
|
||||
// The app opens the edit of the selected card's comment, as on a click on its balloon.
|
||||
@@ -184,7 +185,7 @@ fn an_edit_that_opens_takes_the_keyboard() {
|
||||
#[trial]
|
||||
fn a_read_only_card_takes_no_typing() {
|
||||
let threads = vec![(thread(1, "First"), 100.0)];
|
||||
let selected = CommentsPanelState { selected: Some(ThreadId(1)), ..CommentsPanelState::default() };
|
||||
let selected = CommentsPanelState { selected: craft_behavior::Selection::single(ThreadId(1)), ..CommentsPanelState::default() };
|
||||
let mut shown = Shown::with(threads, selected, BalloonPlace::Column, room(), Direction::Ltr, true);
|
||||
let words = CommentsWords::default();
|
||||
assert!(shown.fixture.by_label(words.reply.as_str()).is_none(), "a read-only card shows no reply field");
|
||||
@@ -200,7 +201,7 @@ fn a_read_only_card_takes_no_typing() {
|
||||
#[trial]
|
||||
fn a_selected_card_in_buttons_form_reports_reply_resolve_reopen_and_delete() {
|
||||
let words = CommentsWords::default();
|
||||
let selected = || CommentsPanelState { selected: Some(ThreadId(1)), ..CommentsPanelState::default() };
|
||||
let selected = || CommentsPanelState { selected: craft_behavior::Selection::single(ThreadId(1)), ..CommentsPanelState::default() };
|
||||
let open = vec![(thread(1, "Open"), 100.0)];
|
||||
let mut shown = Shown::new(open.clone(), selected(), BalloonPlace::Column, room(), Direction::Ltr);
|
||||
|
||||
@@ -246,7 +247,7 @@ fn balloons_stack_without_overlap_clip_long_bodies_and_keep_the_next_card_in_vie
|
||||
let mut locked = thread(4, "Locked body");
|
||||
locked.locked = true;
|
||||
let threads = vec![(thread(1, &long), 100.0), (thread(2, "Short."), 110.0), (thread(3, &long), 120.0), (locked, 130.0)];
|
||||
let state = CommentsPanelState { selected: Some(ThreadId(3)), ..CommentsPanelState::default() };
|
||||
let state = CommentsPanelState { selected: craft_behavior::Selection::single(ThreadId(3)), ..CommentsPanelState::default() };
|
||||
let shown = Shown::new(threads, state, BalloonPlace::Column, vec2(900.0, 1100.0), Direction::Ltr);
|
||||
let texts = shown.fixture.texts().to_vec();
|
||||
let line = texts.iter().find(|text| text.text == "Short.").map(|text| text.rect.height()).expect("the short card's body");
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
use std::ops::Range;
|
||||
|
||||
use craft_text::find::FindMatches;
|
||||
use craft_ui::testing::trial;
|
||||
|
||||
/// Ranges from `(start, end)` pairs.
|
||||
fn ranges(pairs: &[(usize, usize)]) -> Vec<Range<usize>> {
|
||||
@@ -14,7 +15,7 @@ fn current(found: &FindMatches) -> Option<(usize, Range<usize>)> {
|
||||
found.current_match().map(|found| (found.page, found.range.clone()))
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[trial]
|
||||
fn following_takes_the_first_match_from_the_start_page_whatever_order_pages_arrive_in() {
|
||||
let mut found = FindMatches::new(1);
|
||||
assert!(found.set_page(2, ranges(&[(0, 6)])), "the only known match is shown while the start page is pending");
|
||||
@@ -28,7 +29,7 @@ fn following_takes_the_first_match_from_the_start_page_whatever_order_pages_arri
|
||||
assert_eq!((found.len(), found.from()), (3, Some(1)), "every page's matches are listed and following goes on");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[trial]
|
||||
fn a_step_or_pick_ends_following_and_later_pages_keep_the_users_match() {
|
||||
let mut stepped = FindMatches::new(0);
|
||||
stepped.set_page(1, ranges(&[(0, 3), (5, 8)]));
|
||||
|
||||
@@ -276,7 +276,7 @@ fn a_body_hides_the_pointer_over_the_canvas_over_the_tools_cursor_while_it_asks(
|
||||
let view = CanvasView::new(room, Point::new(600.0, 450.0), 1.0);
|
||||
Canvas::new("Document").document(DOCUMENT).view(view).show_at(ui, room.shrink(40.0), |ui, body| {
|
||||
if let Some(pass) = tool_pass(&body.env) {
|
||||
ToolHost::new().run(ui, &pass, &mut *tool.borrow_mut());
|
||||
let _ = ToolHost::new().run(ui, &pass, &mut *tool.borrow_mut());
|
||||
if asks.get() {
|
||||
pass.hide_pointer(ui);
|
||||
}
|
||||
|
||||
@@ -708,7 +708,7 @@ fn a_settled_collapsed_window_runs_no_more_passes_than_an_expanded_one() {
|
||||
fn a_floating_window_clears_the_top_inset_and_follows_it() {
|
||||
let inset = Rc::new(Cell::new(0.0_f32));
|
||||
let seen = Rc::clone(&inset);
|
||||
let layout = Layout::new(Some(Node::tabs(vec![DOCKED], 0)), vec![Floating::single(vec![WINDOW], 0, Rect::from_min_size(Pos2::new(130.0, 0.0), Vec2::new(200.0, 120.0)))]);
|
||||
let layout = Layout::new(Some(Node::tabs(vec![DOCKED], 0)), vec![Floating::single(103, vec![WINDOW], 0, Rect::from_min_size(Pos2::new(130.0, 0.0), Vec2::new(200.0, 120.0)))]);
|
||||
let held = Rc::new(RefCell::new(Arc::new(Workspace::new(layout))));
|
||||
let (shown, specs) = (Rc::clone(&held), Tracked::new(Numbered));
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
|
||||
Reference in New Issue
Block a user