Merge branch 'pdf-port/fwb11-b' into pdf-port/followups

This commit is contained in:
Dylan M. Taylor
2026-11-20 10:42:40 -05:00
16 changed files with 198 additions and 25 deletions
@@ -58,9 +58,8 @@ pub trait Pointer {
/// pass, when it was the topmost accepting target under the pointer last pass and accepts now.
fn drop_target<P: Send + Sync + 'static, T: DropTarget<P>>(&mut self, target: &T) -> Option<T::Drop>;
/// Registers `target` over the whole window of the running viewport for this pass, in `update`; a target over a
/// component beats it wherever that accepts. The payload is read without a pointer position, so files hovered
/// before the pointer has a position reach it. OS file drops (`OsFiles`) land on it wherever no other target
/// takes them.
/// component beats it wherever that accepts. By default the payload is read without a pointer position; a target
/// that requires one waits for it so the target at that position can take the drop.
fn window_drop_target<P: Send + Sync + 'static, T: WindowDropTarget<P>>(&mut self, target: &T) -> Option<T::Drop>;
/// The operation of a drop of this component's payload, in the pass after the drop; `None` while dragging, when the
/// drag was cancelled and when no target took it.
@@ -157,6 +156,9 @@ impl Pointer for CxCore<'_> {
}
fn window_drop_target<P: Send + Sync + 'static, T: WindowDropTarget<P>>(&mut self, target: &T) -> Option<T::Drop> {
if target.requires_pointer() && self.dragging::<P>().is_none() {
return None;
}
let payload = drag::active::<P>(&self.ctx).filter(|_| !drag::moves_viewport(&self.ctx))?;
let op = drag::current_operation(&self.ctx, craft_behavior::CopyKeys::Alt);
let drop = target.accept(&payload, op)?;
@@ -74,9 +74,9 @@ impl<C: Collection> ItemsHooks<'_, '_, C> {
}
/// AccessKit requests on an item row's node or on a section row's collection node (`report_section_node`): Focus
/// moves the lead to the row and key focus to the collection; Click does that and picks an item or activates a
/// section, as a press does; Expand and Collapse open and close a row that has children.
pub(super) fn node_by_access(&mut self, comp: &C, cx: &mut Cx<'_, C>, layout: &C::ItemLayout, place: Placement) {
/// moves the lead to the row and key focus to the collection; Click also picks an item and activates it when the
/// collection activates on click, or activates a section; Expand and Collapse open and close rows with children.
pub(super) fn node_by_access(&mut self, comp: &C, cx: &mut Cx<'_, C>, props: &crate::contract::CollectionProps, layout: &C::ItemLayout, place: Placement) {
use craft_behavior::AccessAction;
let (_, built) = self.built(layout, place.rect, place.offset);
let rows: Vec<(u64, usize)> = built
@@ -109,6 +109,9 @@ impl<C: Collection> ItemsHooks<'_, '_, C> {
self.events.push(CollectionEvent::Activate(key));
} else {
self.pick(comp, at, false, false);
if matches!(props.activate, crate::contract::ActivateOn::Click) {
self.events.push(CollectionEvent::Activate(key));
}
}
}
}
@@ -441,7 +441,7 @@ impl<C: Collection> ShapeHooks<C> for ItemsHooks<'_, '_, C> {
self.context_key(cx, &layout, at, lead_at);
self.delete_key(cx, &props, lead_at);
self.toggle_by_access(cx, &layout, at);
self.node_by_access(comp, cx, &layout, at);
self.node_by_access(comp, cx, &props, &layout, at);
self.reorder_and_rename(comp, cx, &props, lead_at);
self.requested_rename(comp, cx, &props, &layout);
self.requested_reveal(comp, &layout);
+1 -1
View File
@@ -422,7 +422,7 @@ pub(crate) fn run<C: Component>(
let ink = if enabled { ink } else { crate::style::rgba_color(crate::runtime::env::Env::of(ui).tokens.color.text.disabled) };
let held = cx.popup(EDIT_MENU).is_open_in(&mut cx.core);
serve_access(cx, &mut state, widget, &decl.shown, read_only);
let select_all = std::mem::take(&mut state.select_all);
let select_all = (std::mem::take(&mut state.select_all) || decl.options.select_all) && !crate::runtime::ime::composing(&ctx, widget);
if select_all {
let len = state.draft.as_deref().unwrap_or(&decl.shown).chars().count();
adapter::select(&ctx, widget, 0, len);
@@ -73,6 +73,8 @@ pub struct TextOptions {
pub steps_value: bool,
/// The whole text is selected when the field takes focus, whatever the codec's caret rule says.
pub select_on_focus: bool,
/// Selects the current text before this pass's typing, unless an IME composition is active.
pub select_all: bool,
/// Enter does something in the field itself (it saves or runs a search): the field takes the `Submit` intent, so the
/// enclosing dialog's default button does not act on it.
pub submits: bool,
@@ -133,6 +135,7 @@ impl Default for TextOptions {
enabled: true,
steps_value: false,
select_on_focus: false,
select_all: false,
submits: false,
mixed: false,
centred: false,
+7 -2
View File
@@ -123,12 +123,17 @@ pub trait DropTarget<P: ?Sized> {
}
}
/// What a component registers with `Pointer::window_drop_target`: a target over the whole window, which needs no
/// pointer position.
/// What a component registers with `Pointer::window_drop_target`: a target over the whole window, optionally waiting
/// for a pointer position before it accepts.
pub trait WindowDropTarget<P> {
/// What a drop on this target carries to the component's caller.
type Drop;
/// Whether this target waits for a pointer position before taking a drop.
fn requires_pointer(&self) -> bool {
false
}
/// `None` rejects. `op` is the operation the held modifiers pick, which a target may refuse.
fn accept(&self, payload: &P, op: DropOperation) -> Option<Self::Drop>;
+56
View File
@@ -207,6 +207,18 @@ impl DropTarget<OsFiles> for OnRow {
/// A drop of files anywhere in the window.
struct OnWindow;
struct OnPositionalWindow;
impl WindowDropTarget<OsFiles> for OnPositionalWindow {
type Drop = Vec<String>;
fn requires_pointer(&self) -> bool { true }
fn accept(&self, files: &OsFiles, _: DropOperation) -> Option<Self::Drop> { Some(names(files)) }
fn mark(&self, _: &Self::Drop) -> DropMark { DropMark::Into(WINDOW) }
}
impl WindowDropTarget<OsFiles> for OnWindow {
type Drop = Vec<String>;
@@ -241,6 +253,50 @@ struct WindowOnly<'a> {
landed: &'a RefCell<Landed>,
}
#[derive(Component)]
struct PositionalWindow<'a> {
#[common]
common: Common,
landed: &'a RefCell<Landed>,
}
impl Component for PositionalWindow<'_> {
const ROLE: Role = Role::GROUP;
type Style = PlainStyle;
type Output = Response;
fn style(_: &StyleCx<'_>, _: PositionalWindowStyleKey) -> PlainStyle { PlainStyle::default() }
fn measure(&mut self, _: &MeasureCx<'_, Self>) -> Vec2 { WINDOW.size() }
fn update(&mut self, cx: &mut Cx<'_, Self>) {
if let Some(files) = cx.window_drop_target(&OnPositionalWindow) {
self.landed.borrow_mut().window.push(files);
}
}
fn finish(self, cx: Cx<'_, Self>) -> Response { cx.response.clone() }
}
#[trial]
fn positional_window_waits_for_pointer_to_choose_a_row() {
let landed = RefCell::new(Landed::default());
let mut frames = Frames::new();
let mut show = |ui: &mut Ui| {
PositionalWindow { common: Common::new(), landed: &landed }.id_salt("window").show_at(ui, WINDOW);
RowOnly { common: Common::new(), landed: &landed }.id_salt("rows").show_at(ui, LIST);
};
frames.idle(2, &mut show);
frames.hover_files(&["a.png"]);
frames.frame(vec![], &mut show);
frames.idle(2, &mut show);
frames.drop_files(&["a.png"]);
frames.frame(vec![], &mut show);
frames.idle(2, &mut show);
assert!(landed.borrow().window.is_empty(), "the window waits while the pointer is unknown");
frames.frame(vec![moved(LIST.center())], &mut show);
frames.idle(3, &mut show);
assert_eq!(landed.borrow().rows.len(), 1, "the row under the pointer takes the drop");
assert!(landed.borrow().window.is_empty());
}
impl Component for WindowOnly<'_> {
const ROLE: Role = Role::GROUP;
type Style = PlainStyle;
+39
View File
@@ -18,6 +18,45 @@ use std::rc::Rc;
type Log = Rc<RefCell<Vec<StartAction>>>;
#[trial]
fn recent_files_follow_the_supplied_list_when_cleared() {
let files = Rc::new(RefCell::new(vec![
RecentFile::new("/tmp/first", "First document"),
RecentFile::new("/tmp/second", "Second document"),
RecentFile::new("/tmp/third", "Third document"),
]));
let supplied = files.clone();
let mut fixture = Fixture::new(move |ui| {
let (mut view, mut sort) = (RecentView::List, RecentSort::Opened);
let current = supplied.borrow().clone();
let out = StartScreen::new(Bind::bound(&mut view), Bind::bound(&mut sort), &current)
.drop_hint("Drop files here")
.section(StartPlace::BeforeRecent, |ui, _| { Text::new("Welcome").show(ui); })
.show(ui);
for action in out.actions {
match action {
StartAction::RemoveRecent(path) => supplied.borrow_mut().retain(|file| file.path != path),
StartAction::ClearRecent => supplied.borrow_mut().clear(),
_ => {}
}
}
});
fixture.room(egui::Vec2::new(1100.0, 700.0)).settle();
let row = fixture.by_label("Second document, /tmp").expect("the recent row");
fixture.frame(vec![moved(row.center())]).idle(2);
let remove = fixture.by_label("Remove Second document from Recent").expect("the remove button");
fixture.click(&remove).idle(2);
assert_eq!(files.borrow().len(), 2);
let row = fixture.by_label("First document, /tmp").expect("the recent row");
let at = row.center();
fixture.frame(vec![moved(at)]).frame(vec![secondary(at, true)]).frame(vec![secondary(at, false)]).idle(2);
let clear = fixture.by_label("Clear Recent Files").expect("the recent menu");
fixture.click(&clear).idle(3);
assert!(files.borrow().is_empty());
assert!(fixture.by_label("First document, /tmp").is_none(), "removed files no longer appear");
assert!(fixture.by_label("Drop files here").is_some(), "the empty hint appears");
}
/// A start screen of two recent files and a link in a room wide enough for the rail; every action it reports goes to
/// the log.
fn screen() -> (Fixture, Log) {
+23 -2
View File
@@ -117,18 +117,30 @@ impl Outcome for DropVeilOutput {
/// the files nothing else in their window took use it too.
pub struct WholeWindow {
rect: Rect,
positional: bool,
}
impl WholeWindow {
/// A target over the window, marked with `rect` while files hover.
pub fn new(rect: Rect) -> Self {
WholeWindow { rect }
WholeWindow { rect, positional: false }
}
/// Waits for the pointer so a more specific target can take the drop at that position.
#[must_use]
pub fn positional(mut self) -> Self {
self.positional = true;
self
}
}
impl WindowDropTarget<OsFiles> for WholeWindow {
type Drop = OsFiles;
fn requires_pointer(&self) -> bool {
self.positional
}
fn accept(&self, payload: &OsFiles, _op: DropOperation) -> Option<OsFiles> {
(!payload.files.is_empty()).then(|| payload.clone())
}
@@ -152,6 +164,7 @@ pub struct DropVeil {
#[container]
props: ContainerProps,
hovering: bool,
positional: bool,
/// The files dropped this pass: `update` writes them before the body runs, the body and `finish` read them. A veil
/// is built anew every pass, so nothing outlives it.
dropped: Arc<Mutex<Option<OsFiles>>>,
@@ -163,7 +176,14 @@ impl DropVeil {
/// A veil saying `label` ("Import 3 photos") while files hover.
pub fn new(label: impl Into<Label>) -> Self {
let props = ContainerProps::new().sizing(Sizing::Fill).pad(Pad::None);
DropVeil { common: Common::new(), props, hovering: false, dropped: Arc::default(), card: None }.label(label)
DropVeil { common: Common::new(), props, hovering: false, positional: false, dropped: Arc::default(), card: None }.label(label)
}
/// Waits for the pointer before accepting a drop, allowing a target under it to take the files first.
#[must_use]
pub fn positional(mut self) -> Self {
self.positional = true;
self
}
/// Shows the veil over `body`, which gets the files dropped on the window in this pass, if any.
@@ -206,6 +226,7 @@ impl Component for DropVeil {
fn update(&mut self, cx: &mut Cx<'_, Self>) {
let held = drag::active::<OsFiles>(&cx.ctx).is_some_and(|files| !files.files.is_empty());
let target = WholeWindow::new(cx.rect);
let target = if self.positional { target.positional() } else { target };
let (id, ordinal) = (cx.id, drag::next_ordinal(&cx.ctx, cx.id));
let dropped = cx.window_drop_target::<OsFiles, _>(&target);
// The veil shows only while it is the target that would take the drop.
@@ -16,3 +16,10 @@ fn drop_veil(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
.response
.into()
}
#[story(DropVeil, covers = [], drive = Drive::Never)]
fn positional_drop_veil(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
DropVeil::new("Drop files").positional().show(ui, |ui, _| {
Checkbox::new(Bind::given(true)).label("Keep originals").show(ui);
}).output.response.into()
}
@@ -23,7 +23,7 @@ fn document_tabs(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
}
/// Hover text on a tab cut to fit, which shows its full name then the text, and on a short tab, which shows the text
/// alone. Document tabs keep whole titles, so the cut one is the shown tab, named longer than the strip is wide.
/// alone. The long title is cut to fit the strip.
#[story(DocumentTabs<'static, usize>, covers = [], drive = Drive::Never)]
fn document_tabs_with_tooltips(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
const LONG: &str = "Quarterly report for the board of directors, final revision with every appendix, the audit letter, the \
+4 -4
View File
@@ -7,7 +7,7 @@ use craft_host::target::Os;
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum TabKind {
/// Document tabs: whole titles, a close button on every closable tab, every document in the overflow menu.
/// Document tabs: shrinking titles, a close button on every closable tab, every document in the overflow menu.
#[default]
Document,
/// Panel tabs: tabs shrink before they overflow, no close button, only the hidden tabs in the overflow menu.
@@ -59,11 +59,11 @@ pub enum OverflowMenu {
}
impl TabKind {
/// How tab widths are fitted: whole titles for document and text tabs, shrinking for panel tabs.
/// How tab widths are fitted: whole titles for text tabs, shrinking for document and panel tabs.
pub fn fit_mode(self) -> FitMode {
match self {
Self::Document | Self::Text => FitMode::Whole,
Self::Panel => FitMode::Shrink,
Self::Text => FitMode::Whole,
Self::Document | Self::Panel => FitMode::Shrink,
}
}
+1 -8
View File
@@ -72,8 +72,6 @@ pub struct TextField<'a, C: Codec + Clone + 'static = PlainText> {
/// the id the collection is built with (`Props::id`), so a pattern can name a collection it shows after the field.
#[prop]
drives: Option<Id>,
/// The whole text is selected in this pass unless the field is composing text (`select_all`).
select_all: bool,
}
impl<'a> TextField<'a, PlainText> {
@@ -108,7 +106,6 @@ impl<'a, C: Codec + Clone + 'static> TextField<'a, C> {
leading: Vec::new(),
arrow: false,
drives: None,
select_all: false,
}
.label(label)
}
@@ -157,7 +154,7 @@ impl<'a, C: Codec + Clone + 'static> TextField<'a, C> {
/// request made during a composition is dropped.
#[must_use]
pub fn select_all(mut self, on: bool) -> Self {
self.select_all = on;
self.options.select_all = on;
self
}
@@ -357,10 +354,6 @@ impl<C: Codec + Clone + 'static> Component for TextField<'_, C> {
{
cx.set(empty);
}
// Selecting during a composition would make its commit replace the whole text, so the request is dropped.
if self.select_all && !cx.text(&text_part::<C::Value>()).is_some_and(|outcome| outcome.composing) {
cx.select_all_text();
}
}
fn paint(&mut self, ui: &mut PaintUi<'_>, cx: &Cx<'_, Self>) {
+19
View File
@@ -54,6 +54,25 @@ fn list_row_declares_and_accepts_access_click() {
assert!(seen.borrow().iter().any(|event| matches!(event, CollectionEvent::Selection(_))), "Click selects the row");
}
#[trial]
fn access_click_activates_a_single_click_list_row() {
use craft_ui::contract::ActivateOn;
use craft_ui::testing::focus::AccessActionKind;
let seen = Rc::new(RefCell::new(Vec::new()));
let held = seen.clone();
let mut fixture = Fixture::new(move |ui| {
let keys = [0_usize, 1];
let source = keyed(&keys, |key: &usize| *key);
let out = List::new("Rows").activate(ActivateOn::Click).show_items(ui, &source, &mut |key, _| ListRow::new(NAMES[*key]));
held.borrow_mut().extend(out.events);
});
fixture.settle();
let row = fixture.by_label(NAMES[1]).expect("the row");
seen.borrow_mut().clear();
fixture.access(AccessActionKind::Click, &row).settle();
assert!(seen.borrow().iter().any(|event| matches!(event, CollectionEvent::Activate(1))));
}
/// The rects of the three rows of a list shown with `rows`.
fn row_rects(rows: RowHeight) -> Vec<egui::Rect> {
let mut fixture = Fixture::new(move |ui| {
+7
View File
@@ -14,6 +14,13 @@ use std::rc::Rc;
const TITLES: [&str; 3] = ["One", "Two", "Three"];
#[trial]
fn document_tabs_shrink_before_overflow() {
let fit = TabKind::Document.fit_mode().fit(&[100.0, 100.0, 100.0], 0, 240.0, 50.0, 20.0);
assert!(fit.overflow.is_empty(), "tabs that can shrink into the strip remain visible");
assert!(fit.shown.iter().all(|(_, width)| *width < 100.0));
}
/// An arrow moves the focus to the next tab without showing it; Enter shows it.
#[trial]
fn an_arrow_moves_the_focus_and_enter_shows_the_tab() {
@@ -37,6 +37,24 @@ fn clearing_a_search_field_with_a_draft_leaves_it_empty_after_blur() {
assert_eq!(*text.borrow(), "", "leaving the field commits nothing back");
}
#[trial]
fn select_all_after_typing_selects_the_complete_new_draft() {
let text = Rc::new(RefCell::new("4".to_owned()));
let request = Rc::new(Cell::new(false));
let (shown, select) = (text.clone(), request.clone());
let mut fixture = Fixture::new(move |ui| {
TextField::new("Name", Bind::bound(&mut *shown.borrow_mut())).select_on_focus().select_all(select.replace(false)).show(ui);
});
fixture.settle();
fixture.key(Key::Tab, Modifiers::NONE).settle();
*text.borrow_mut() = "iv".to_owned();
request.set(true);
fixture.type_text("2");
assert_eq!(*text.borrow(), "2", "typing replaces the replacement value");
fixture.type_text("x").settle();
assert_eq!(*text.borrow(), "2x", "the next input appends to the new draft");
}
/// A letter typed into a text field is the field's own: the field gets the text, the app reads no press of it, and
/// `focus_holds` names the letter, and Space, before they are typed.
#[trial]