mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-27 03:35:15 +00:00
Format merged framework changes
This commit is contained in:
@@ -134,18 +134,27 @@ fn delete_over_unfocused_thumbnails_acts_on_the_pick() {
|
||||
fixture.click_at(tile(&fixture, 2)).settle();
|
||||
let other = fixture.by_label("Other").expect("other control");
|
||||
for _ in 0..3 {
|
||||
if craft_ui::testing::access::focused_key(fixture.tree()) == other.node { break; }
|
||||
if craft_ui::testing::access::focused_key(fixture.tree()) == other.node {
|
||||
break;
|
||||
}
|
||||
fixture.key(egui::Key::Tab, egui::Modifiers::NONE).settle();
|
||||
}
|
||||
assert_eq!(craft_ui::testing::access::focused_key(fixture.tree()), other.node, "the other control owns focus");
|
||||
let at = tile(&fixture, 2);
|
||||
fixture.frame(vec![craft_ui::testing::pointer::moved(at)]).key(egui::Key::Delete, egui::Modifiers::NONE).settle();
|
||||
assert!(events.borrow().iter().any(|event| matches!(event, ThumbnailEvent::Delete(pages) if pages.as_slice() == [1])), "Delete reaches the picked page");
|
||||
assert!(
|
||||
events.borrow().iter().any(|event| matches!(event, ThumbnailEvent::Delete(pages) if pages.as_slice() == [1])),
|
||||
"Delete reaches the picked page"
|
||||
);
|
||||
let deletes = events.borrow().iter().filter(|event| matches!(event, ThumbnailEvent::Delete(_))).count();
|
||||
let field = fixture.by_label("Draft").expect("text field");
|
||||
fixture.click(&field).settle();
|
||||
fixture.frame(vec![craft_ui::testing::pointer::moved(at)]).key(egui::Key::Backspace, egui::Modifiers::NONE).settle();
|
||||
assert_eq!(events.borrow().iter().filter(|event| matches!(event, ThumbnailEvent::Delete(_))).count(), deletes, "the text field keeps its editing key");
|
||||
assert_eq!(
|
||||
events.borrow().iter().filter(|event| matches!(event, ThumbnailEvent::Delete(_))).count(),
|
||||
deletes,
|
||||
"the text field keeps its editing key"
|
||||
);
|
||||
}
|
||||
|
||||
#[trial]
|
||||
@@ -162,13 +171,18 @@ fn delete_over_unfocused_thumbnails_uses_the_current_page_when_unpicked() {
|
||||
fixture.room(vec2(600.0, 600.0)).settle();
|
||||
let other = fixture.by_label("Other").expect("other control");
|
||||
for _ in 0..3 {
|
||||
if craft_ui::testing::access::focused_key(fixture.tree()) == other.node { break; }
|
||||
if craft_ui::testing::access::focused_key(fixture.tree()) == other.node {
|
||||
break;
|
||||
}
|
||||
fixture.key(egui::Key::Tab, egui::Modifiers::NONE).settle();
|
||||
}
|
||||
assert_eq!(craft_ui::testing::access::focused_key(fixture.tree()), other.node);
|
||||
let at = tile(&fixture, 2);
|
||||
fixture.frame(vec![craft_ui::testing::pointer::moved(at)]).key(egui::Key::Delete, egui::Modifiers::NONE).settle();
|
||||
assert!(events.borrow().iter().any(|event| matches!(event, ThumbnailEvent::Delete(pages) if pages.as_slice() == [1])), "Delete reaches the current page");
|
||||
assert!(
|
||||
events.borrow().iter().any(|event| matches!(event, ThumbnailEvent::Delete(pages) if pages.as_slice() == [1])),
|
||||
"Delete reaches the current page"
|
||||
);
|
||||
}
|
||||
|
||||
#[trial]
|
||||
|
||||
@@ -12,7 +12,8 @@ pub use events::{
|
||||
CollectionEvent, ColumnEvent, ColumnRequest, ContextMenuRequest, HeaderMenuRequest, ListDrag, OpenChange, Rename, ReorderMove, ToggleEdit,
|
||||
};
|
||||
pub use props::{
|
||||
ActivateOn, CollectionProps, DeleteTarget, DragPayload, ItemKeys, LeadOnOpen, LeadSource, ReorderRule, RowHeight, RowPressed, RowState, SelectMode, SpaceAction,
|
||||
ActivateOn, CollectionProps, DeleteTarget, DragPayload, ItemKeys, LeadOnOpen, LeadSource, ReorderRule, RowHeight, RowPressed, RowState,
|
||||
SelectMode, SpaceAction,
|
||||
};
|
||||
pub(crate) use response::Gestures;
|
||||
pub(crate) use response::ItemsOut;
|
||||
|
||||
@@ -482,7 +482,8 @@ impl<C: Collection> ItemsHooks<'_, '_, C> {
|
||||
}
|
||||
let nav = layout.nav();
|
||||
let hit = layout.hit(Self::logical(layout, rect, rtl, at), offset);
|
||||
let across = !matches!(nav, NavShape::Flat | NavShape::Tree | NavShape::WrappedGrid { columns: 1, .. } | NavShape::BoundedGrid { columns: 1, .. });
|
||||
let across =
|
||||
!matches!(nav, NavShape::Flat | NavShape::Tree | NavShape::WrappedGrid { columns: 1, .. } | NavShape::BoundedGrid { columns: 1, .. });
|
||||
// With no item under the pointer, a point after the last item in reading order is over the last item. Across a
|
||||
// row-wise layout that is beyond the last item's end edge on its row, or below its row.
|
||||
let past = hit.is_none() && {
|
||||
|
||||
@@ -398,8 +398,11 @@ impl<C: Collection> ShapeHooks<C> for ItemsHooks<'_, '_, C> {
|
||||
}
|
||||
let lead_at = self.lead.key.as_ref().and_then(|key| self.index_of(key));
|
||||
let props = comp.items().clone();
|
||||
if cx.core.resolved.enabled && props.deletable && props.delete_target == crate::contract::DeleteTarget::FocusOrHover
|
||||
&& !cx.core.memory.is_peek() && !crate::runtime::measure::active(&cx.core.ctx)
|
||||
if cx.core.resolved.enabled
|
||||
&& props.deletable
|
||||
&& props.delete_target == crate::contract::DeleteTarget::FocusOrHover
|
||||
&& !cx.core.memory.is_peek()
|
||||
&& !crate::runtime::measure::active(&cx.core.ctx)
|
||||
{
|
||||
crate::runtime::keys::register_hover_delete(&cx.core.ctx, cx.core.id);
|
||||
}
|
||||
@@ -426,7 +429,10 @@ impl<C: Collection> ShapeHooks<C> for ItemsHooks<'_, '_, C> {
|
||||
self.switch_page(comp, cx, &props, &layout);
|
||||
let lead_at = self.lead.key.as_ref().and_then(|key| self.index_of(key)).or(lead_at);
|
||||
if matches!(props.select, crate::contract::SelectMode::Multi | crate::contract::SelectMode::Cells)
|
||||
&& !header_held && self.renaming.key.is_none() && cx.core.intents.untaken(&Intent::Cancel) && !self.placed().rows().is_empty()
|
||||
&& !header_held
|
||||
&& self.renaming.key.is_none()
|
||||
&& cx.core.intents.untaken(&Intent::Cancel)
|
||||
&& !self.placed().rows().is_empty()
|
||||
&& cx.core.intents.take(Intent::Cancel)
|
||||
{
|
||||
self.change(craft_behavior::SelectionChange::Clear);
|
||||
|
||||
@@ -53,9 +53,9 @@ pub use body::pad_of;
|
||||
pub use body::{STRIP_BACK, STRIP_FORWARD};
|
||||
pub use collection::{
|
||||
ActivateOn, CollectionEvent, CollectionProps, CollectionResponse, ColumnAlign, ColumnEvent, ColumnKind, ColumnLayout, ColumnRequest, ColumnSort,
|
||||
ColumnSpec, ContextMenuRequest, DeleteTarget, DragPayload, DropAt, DropKind, DropPayload, DropPlace, EdgePress, HeaderMenuRequest, ItemKeys, LeadOnOpen,
|
||||
LeadSource, ListDrag, OpenChange, PendingDrop, Rename, ReorderMove, ReorderRule, RowHeight, RowPressed, RowState, SelectMode, ShownRow,
|
||||
SpaceAction, ToggleColumn, ToggleEdit,
|
||||
ColumnSpec, ContextMenuRequest, DeleteTarget, DragPayload, DropAt, DropKind, DropPayload, DropPlace, EdgePress, HeaderMenuRequest, ItemKeys,
|
||||
LeadOnOpen, LeadSource, ListDrag, OpenChange, PendingDrop, Rename, ReorderMove, ReorderRule, RowHeight, RowPressed, RowState, SelectMode,
|
||||
ShownRow, SpaceAction, ToggleColumn, ToggleEdit,
|
||||
};
|
||||
#[doc(hidden)]
|
||||
pub use container::InBar;
|
||||
|
||||
@@ -32,17 +32,31 @@ pub(crate) fn begin(ctx: &Context, press_captured: bool) -> EscapeRouting {
|
||||
stage.last_open_edits = std::mem::take(&mut stage.open_edits);
|
||||
stage.last_nodes = std::mem::take(&mut stage.nodes);
|
||||
let fired = std::mem::take(&mut stage.fired_claims);
|
||||
(std::mem::take(&mut stage.batch), stage.last_nodes.clone(), std::mem::take(&mut stage.captures), held_claims, fired, std::mem::take(&mut stage.hover_deletes))
|
||||
(
|
||||
std::mem::take(&mut stage.batch),
|
||||
stage.last_nodes.clone(),
|
||||
std::mem::take(&mut stage.captures),
|
||||
held_claims,
|
||||
fired,
|
||||
std::mem::take(&mut stage.hover_deletes),
|
||||
)
|
||||
});
|
||||
let modal = overlay::any_open(ctx, overlay::OpenFilter::Modal);
|
||||
let hover_delete = if !modal && !ctx.text_edit_focused() && target.as_ref().is_none_or(|rec| !rec.stop.text && !matches!(rec.stop.keys.owner, OwnerClass::Text | OwnerClass::Recorder)) {
|
||||
let hover_delete = if !modal
|
||||
&& !ctx.text_edit_focused()
|
||||
&& target.as_ref().is_none_or(|rec| !rec.stop.text && !matches!(rec.stop.keys.owner, OwnerClass::Text | OwnerClass::Recorder))
|
||||
{
|
||||
crate::runtime::pointer::with_hover(ctx, crate::runtime::egui::pass::current_viewport(ctx), |under, captured| {
|
||||
if captured { return None; }
|
||||
if captured {
|
||||
return None;
|
||||
}
|
||||
let under = under?;
|
||||
let owner = under.press.click.or(under.press.drag).or(under.hover_top).map(|(_, owner)| owner)?;
|
||||
hover_deletes.contains(&owner).then_some(owner)
|
||||
})
|
||||
} else { None };
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let canvas = if target.is_some() { None } else { unfocused_canvas(ctx) };
|
||||
let stale_repeat = |stale: &mut bool, press: &Press| {
|
||||
if press.key != Key::Enter || !press.mods.is_none() {
|
||||
@@ -69,7 +83,8 @@ pub(crate) fn begin(ctx: &Context, press_captured: bool) -> EscapeRouting {
|
||||
if let Some(rec) = &target {
|
||||
for (press, taken) in batch.presses.iter().zip(&mut consumed).filter(|(press, _)| !press.canvas) {
|
||||
*taken = if let Some(id) = hover_delete.filter(|id| Some(*id) != target.as_ref().map(|rec| rec.stop.id))
|
||||
&& press.mods.is_none() && matches!(press.key, Key::Delete | Key::Backspace)
|
||||
&& press.mods.is_none()
|
||||
&& matches!(press.key, Key::Delete | Key::Backspace)
|
||||
{
|
||||
push(&mut routed, Some(id), Intent::delete(press.key == Key::Delete, craft_behavior::Granularity::Unit), false);
|
||||
Taken::Hover
|
||||
@@ -106,7 +121,10 @@ pub(crate) fn begin(ctx: &Context, press_captured: bool) -> EscapeRouting {
|
||||
// arrows with the modifiers it acts on (`KeyUse::nudge_mods`); the others are the app's.
|
||||
let declared = |mods: Mods| canvas.as_ref().is_none_or(|canvas| canvas.stop.keys.nudge_mods.contains(mods));
|
||||
for (press, taken) in batch.presses.iter().zip(&mut consumed).filter(|(press, _)| !press.canvas) {
|
||||
if let Some(id) = hover_delete && press.mods.is_none() && matches!(press.key, Key::Delete | Key::Backspace) {
|
||||
if let Some(id) = hover_delete
|
||||
&& press.mods.is_none()
|
||||
&& matches!(press.key, Key::Delete | Key::Backspace)
|
||||
{
|
||||
push(&mut routed, Some(id), Intent::delete(press.key == Key::Delete, craft_behavior::Granularity::Unit), false);
|
||||
*taken = Taken::Hover;
|
||||
} else if press.key == Key::Enter && press.mods.is_none() && !press.repeat {
|
||||
@@ -252,7 +270,8 @@ fn owned_shortcuts(ctx: &Context, target: Option<&StopRec>, batch: &Batch, consu
|
||||
// The canvas's Space is never the focused stop's; a press the unfocused window's canvas took is the canvas's.
|
||||
.map(|(press, taken)| {
|
||||
!press.canvas
|
||||
&& (matches!(*taken, Taken::Canvas | Taken::Hover) || holds_press(owner, target, press, *taken == Taken::Yes, press.text.is_some_and(|at| taken_texts[at])))
|
||||
&& (matches!(*taken, Taken::Canvas | Taken::Hover)
|
||||
|| holds_press(owner, target, press, *taken == Taken::Yes, press.text.is_some_and(|at| taken_texts[at])))
|
||||
})
|
||||
.collect();
|
||||
// A shortcut without a press of its own (a release, or the clipboard event that stands for ⌘C) follows the owner by
|
||||
|
||||
@@ -59,8 +59,7 @@ fn retry_starts_with_an_empty_password() {
|
||||
let seen = Rc::clone(&answers);
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
let mut open = true;
|
||||
let shown = PasswordDialog::new(PasswordPurpose::permissions("poster.pdf"))
|
||||
.opened(craft_ui::contract::Bind::bound(&mut open)).show(ui);
|
||||
let shown = PasswordDialog::new(PasswordPurpose::permissions("poster.pdf")).opened(craft_ui::contract::Bind::bound(&mut open)).show(ui);
|
||||
if let Some(answer) = shown.answer {
|
||||
seen.borrow_mut().push(answer.secret.expose().to_owned());
|
||||
}
|
||||
|
||||
@@ -453,7 +453,8 @@ impl<'a> Notice<'a> {
|
||||
let text_offset = (line - first) / 2.0;
|
||||
// The head includes the complete wrapped message; details and stacked actions follow it.
|
||||
let head = (text_offset + title.map_or(0.0, |size| size.y) + message.y).max(line);
|
||||
let with_actions = head + lines_height + leaves_height + if actions.is_empty() || inline_actions { 0.0 } else { stack.max(gap) + actions_height };
|
||||
let with_actions =
|
||||
head + lines_height + leaves_height + if actions.is_empty() || inline_actions { 0.0 } else { stack.max(gap) + actions_height };
|
||||
let (needs, height) = if row {
|
||||
((icon_width + text_width + dismiss_width + action_width).max(lines_width), with_actions)
|
||||
} else {
|
||||
|
||||
@@ -126,7 +126,9 @@ fn context_menu_paste_delivers_image_at_the_requested_point() {
|
||||
fixture.frame(vec![egui::Event::PasteImage(std::sync::Arc::new(egui::ColorImage::filled([2, 2], egui::Color32::RED)))]).settle();
|
||||
let fired = take_output(fixture.ctx()).fired;
|
||||
assert!(
|
||||
fired.iter().any(|fired| fired.pasted.as_ref().is_some_and(|content| content.image.is_some()) && fired.paste_at == Some(egui::pos2(120.0, 180.0))),
|
||||
fired
|
||||
.iter()
|
||||
.any(|fired| fired.pasted.as_ref().is_some_and(|content| content.image.is_some()) && fired.paste_at == Some(egui::pos2(120.0, 180.0))),
|
||||
"{fired:?}"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -137,8 +137,7 @@ fn a_row_notice_wraps_actions_onto_further_rows_inside_its_bounds() {
|
||||
fn a_wide_notice_wraps_its_message_beside_its_actions() {
|
||||
let message = "A long message about the document and the restrictions that apply to its content and editing features.";
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
Notice::new(Tone::Info, message).dismiss().action(NoticeAction::new("Security settings"))
|
||||
.action(NoticeAction::new("Unlock")).show(ui);
|
||||
Notice::new(Tone::Info, message).dismiss().action(NoticeAction::new("Security settings")).action(NoticeAction::new("Unlock")).show(ui);
|
||||
});
|
||||
fixture.room(Vec2::new(500.0, 200.0)).settle();
|
||||
let text = fixture.texts().iter().find(|run| run.text == message).expect("message painted").rect;
|
||||
|
||||
Reference in New Issue
Block a user