ui-contract: drag::register takes a target's reach as one TargetReach; collections report an item's output through one helper

This commit is contained in:
bflatastic committed 2026-11-24 08:23:57 +07:00
1 parent daed17160c
commit 7002b2ec8f
5 files changed
+42 -52

No files matched your search

@@ -197,7 +197,8 @@ impl Pointer for CxCore<'_> {
let op = drag::current_operation(&self.ctx, craft_behavior::CopyKeys::Alt);
let drop = target.accept(&payload, op)?;
let ordinal = drag::next_ordinal(&self.ctx, self.id);
drag::register(&self.ctx, self.id, self.response.layer_id, target.mark(&drop), op, self.env.shared_tokens(), true, target.under_modal());
let reach = drag::TargetReach { window: true, under_modal: target.under_modal() };
drag::register(&self.ctx, self.id, self.response.layer_id, target.mark(&drop), op, self.env.shared_tokens(), reach);
drag::take_drop(&self.ctx, self.id, ordinal, op, TypeId::of::<P>()).then_some(drop)
}
+2 -12
View File
@@ -8,8 +8,7 @@ use super::{Held, ITEM_NODE, ItemsHooks, LastLayout, Lead, Placement, Renaming,
use super::{request, rows};
use crate::contract::ValueOf;
use crate::contract::collection::{
CollectionEvent, CollectionProps, ColumnLayout, ContextMenuRequest, DropAt, Gestures, HoverLead, ItemsOut, OpenChange, PendingDrop, Rename,
RowState, ShownRow,
CollectionEvent, CollectionProps, ColumnLayout, DropAt, Gestures, HoverLead, ItemsOut, PendingDrop, Rename, RowState, ShownRow,
};
use crate::contract::cx::{BodyCx, CxCore, Pointer as _};
use crate::contract::run::{Measuring, ShapeHooks, ShowAt};
@@ -644,16 +643,7 @@ impl<C: Collection> ShapeHooks<C> for ItemsHooks<'_, '_, C> {
if let Some(row) = shown_rows.last_mut() {
row.openers = self.item_openers(&row_ui, &ctx, id, cx.core.resolved.enabled, openers);
}
if let Some(ask) = out.open_request() {
self.events.push(CollectionEvent::Open(OpenChange { key: key.clone(), open: ask.open, all: ask.all }));
}
if let Some(rect) = out.menu_request() {
crate::runtime::keys::request_context(&ctx, id, rect, None);
self.ask_menu(ContextMenuRequest { key: key.clone(), at: self.on_screen(rect.left_bottom()), column: None, part: None });
}
if let Some(event) = out.into_event() {
self.events.push(CollectionEvent::Item(key.clone(), event));
}
self.report_item_output(&ctx, id, &key, out);
if state.renaming {
self.rename_row(comp, &mut row_ui, (&ctx, id, rtl), (at, &key), label);
}
@@ -2,7 +2,7 @@
//! arena, updated, painted and finished at their rows, reported as sub-nodes of the collection.
use super::{ITEM_NODE, ItemsHooks, key_hash};
use crate::contract::collection::{CollectionEvent, ContextMenuRequest, OpenChange, ShownRow};
use crate::contract::collection::ShownRow;
use crate::contract::run;
use crate::contract::{Collection, Component as _, Cx, Internal, ItemOpener, ItemOutput as _, Meta as _};
use crate::primitives::sensing::{self, MemberSpec};
@@ -87,16 +87,7 @@ impl<'r, C: Collection> ItemsHooks<'_, 'r, C> {
shown.openers = self.item_openers(ui, ctx, id, enabled, openers);
}
let label = output.label_rect().unwrap_or(row);
if let Some(ask) = output.open_request() {
self.events.push(CollectionEvent::Open(OpenChange { key: key.clone(), open: ask.open, all: ask.all }));
}
if let Some(rect) = output.menu_request() {
crate::runtime::keys::request_context(ctx, id, rect, None);
self.ask_menu(ContextMenuRequest { key: key.clone(), at: self.on_screen(rect.left_bottom()), column: None, part: None });
}
if let Some(event) = output.into_event() {
self.events.push(CollectionEvent::Item(key.clone(), event));
}
self.report_item_output(ctx, id, &key, output);
if renaming {
self.rename_row(comp, ui, (ctx, id, rtl), (at, &key), label);
}
+16 -2
View File
@@ -3,8 +3,8 @@
use super::drag::SlowClick;
use super::lead::PickBy;
use super::{ItemsHooks, Placement, RowPress, SECTION};
use crate::contract::collection::{ActivateOn, CollectionEvent, CollectionProps, ContextMenuRequest, LeadSource, RowPressed, SelectMode};
use crate::contract::{Collection, Cx, ItemOpener};
use crate::contract::collection::{ActivateOn, CollectionEvent, CollectionProps, ContextMenuRequest, LeadSource, OpenChange, RowPressed, SelectMode};
use crate::contract::{Collection, Cx, ItemOpener, ItemOutput};
use crate::runtime::egui::response;
use crate::runtime::env::ArenaId;
use crate::runtime::focus;
@@ -380,6 +380,20 @@ impl<C: Collection> ItemsHooks<'_, '_, C> {
self.events.push(CollectionEvent::ContextMenu(request));
}
/// Reports what the shown item `key` asked for: opening or closing its children, its menu, and its event.
pub(super) fn report_item_output(&mut self, ctx: &Context, id: Id, key: &C::Key, output: impl ItemOutput<C::ItemEvent>) {
if let Some(ask) = output.open_request() {
self.events.push(CollectionEvent::Open(OpenChange { key: key.clone(), open: ask.open, all: ask.all }));
}
if let Some(rect) = output.menu_request() {
crate::runtime::keys::request_context(ctx, id, rect, None);
self.ask_menu(ContextMenuRequest { key: key.clone(), at: self.on_screen(rect.left_bottom()), column: None, part: None });
}
if let Some(event) = output.into_event() {
self.events.push(CollectionEvent::Item(key.clone(), event));
}
}
/// The response of each part an item asked to open a menu from (`ItemCx::part_opener`).
pub(super) fn item_openers(&self, ui: &Ui, ctx: &Context, id: Id, enabled: bool, openers: Vec<ItemOpener>) -> Vec<(ItemOpener, egui::Response)> {
item_openers(ui, ctx, id, enabled, openers)
+20 -26
View File
@@ -74,7 +74,7 @@ pub enum DropMark {
},
}
crate::stays!(Arc<crate::style::UiTokens>, DropOperation);
crate::stays!(Arc<crate::style::UiTokens>, DropOperation, TargetReach);
impl crate::runtime::Shift for DropMark {
fn shifted(&self, by: &egui::RecordShift) -> Self {
@@ -301,10 +301,16 @@ struct Registration {
op: DropOperation,
/// The tokens of the target's region.
tokens: Arc<UiTokens>,
reach: TargetReach,
}
/// Where a drop target takes drops beyond its own mark.
#[derive(Clone, Copy, Debug, PartialEq)]
pub(crate) struct TargetReach {
/// The target covers the whole window: any target over a component beats it.
window: bool,
pub(crate) window: bool,
/// The target takes OS files under a modal layer (`DropTarget::under_modal`).
under_modal: bool,
pub(crate) under_modal: bool,
}
/// A viewport's registrations: this pass's, and the target that won last pass.
@@ -635,24 +641,12 @@ pub(crate) fn show_mark(ctx: &Context, mark: Option<DropMark>) {
}
/// Records that `owner`'s `ordinal`th target on `layer` accepts at the pointer a drop doing `op`, with its mark in
/// layer space and the tokens of the target's region. A `window` target covers the whole window; an `under_modal` one
/// takes OS files under a modal layer.
pub(crate) fn register(
ctx: &Context,
owner: Id,
layer: Layer,
mark: DropMark,
op: DropOperation,
tokens: Arc<UiTokens>,
window: bool,
under_modal: bool,
) {
/// layer space, the tokens of the target's region and its `reach`.
pub(crate) fn register(ctx: &Context, owner: Id, layer: Layer, mark: DropMark, op: DropOperation, tokens: Arc<UiTokens>, reach: TargetReach) {
crate::runtime::replay::journal(
ctx,
|| (owner, layer, mark, op, tokens.clone(), (window, under_modal)),
|ctx, (owner, layer, mark, op, tokens, (window, under_modal))| {
register(ctx, *owner, *layer, *mark, *op, tokens.clone(), *window, *under_modal)
},
|| (owner, layer, mark, op, tokens.clone(), reach),
|ctx, (owner, layer, mark, op, tokens, reach)| register(ctx, *owner, *layer, *mark, *op, tokens.clone(), *reach),
);
let mark = match areas::layer_map(ctx, layer) {
Some(map) => mark.mapped(|point| map.to_screen(point)),
@@ -661,7 +655,7 @@ pub(crate) fn register(
let scope = overlay::drawing_parent(ctx);
PerViewport::<Targets>::with(ctx, pass::current_viewport(ctx), |targets| {
let ordinal = targets.this.iter().filter(|registration| registration.owner == owner).count() as u32;
targets.this.push(Registration { owner, ordinal, layer, scope, mark, op, tokens, window, under_modal });
targets.this.push(Registration { owner, ordinal, layer, scope, mark, op, tokens, reach });
});
}
@@ -747,7 +741,7 @@ pub(crate) fn target_of<T: DropTarget<dyn Any + Send + Sync>>(
let op = current_operation(ctx, target.copy_keys());
let drop = target.accept(&*payload, at, op)?;
let ordinal = next_ordinal(ctx, owner);
register(ctx, owner, zone.layer, target.mark(&drop), op, tokens, false, target.under_modal());
register(ctx, owner, zone.layer, target.mark(&drop), op, tokens, TargetReach { window: false, under_modal: target.under_modal() });
take_drop(ctx, owner, ordinal, op, payload_type).then_some(drop)
}
@@ -811,7 +805,7 @@ pub(crate) fn end_pass(ctx: &Context) {
// that takes them there.
let os = carries_os_files(ctx);
let scopes: Vec<(Option<Id>, bool)> = PerViewport::<Targets>::with(ctx, viewport, |targets| {
targets.this.iter().map(|registration| (registration.scope, os && registration.under_modal)).collect()
targets.this.iter().map(|registration| (registration.scope, os && registration.reach.under_modal)).collect()
});
let open: Vec<bool> =
scopes.iter().map(|(scope, through)| *through || overlay::key_layer(ctx, scope.as_slice(), None) != LayerKeys::Blocked).collect();
@@ -823,10 +817,10 @@ pub(crate) fn end_pass(ctx: &Context) {
.iter()
.enumerate()
.filter(|(at, _)| open[*at])
.max_by_key(|(at, registration)| (!registration.window, areas::layer_position(ctx, registration.layer), *at))
.max_by_key(|(at, registration)| (!registration.reach.window, areas::layer_position(ctx, registration.layer), *at))
.map(|(_, registration)| registration);
targets.component = best.is_some_and(|registration| !registration.window);
targets.winner_window = best.is_some_and(|registration| registration.window);
targets.component = best.is_some_and(|registration| !registration.reach.window);
targets.winner_window = best.is_some_and(|registration| registration.reach.window);
targets.pointer = position;
let best =
best.map(|registration| ((registration.owner, registration.ordinal), (registration.mark, registration.op, registration.tokens.clone())));
@@ -909,7 +903,7 @@ pub(crate) fn held_elsewhere(ctx: &Context) -> bool {
let viewport = pass::current_viewport(ctx);
pass::live_viewports(ctx).into_iter().filter(|other| *other != viewport).any(|other| {
PerViewport::<Targets>::with(ctx, other, |targets| {
(targets.winner.is_some() && targets.component) || targets.this.iter().any(|registration| !registration.window)
(targets.winner.is_some() && targets.component) || targets.this.iter().any(|registration| !registration.reach.window)
})
})
}