ItemKey
Shared capability types for the data-source drag-and-drop + lazy protocol.
Public types
| Kind | Name |
|---|---|
trait | ItemKey — A stable, hashable identity for a row/node |
enum | RowState — Whether a realized row's data is resident yet |
enum | DropPosition — Where, relative to a target row, a drop lands |
enum | DragEligibility — Whether a row may begin a drag at all (the per-item transferable gate, Qt's Qt::ItemIsDragEnabled / TabBar's with_transferable_predicate) |
enum | DragSource — Who is dragging, from the receiving source's point of view |
struct | DropQuery — A hover-time question posed to a source: "may source drop at position relative to target?" The source answers with a DropResponse |
enum | DropResponse — A source's verdict on a DropQuery |
struct | DropCommit — A drop the user actually committed, handed to accept_drop to apply |
Detailed description
These types are the Teksilo-shaped equivalent of Qt's
flags/canDropMimeData/dropMimeData (DnD validation) and
canFetchMore/fetchMore (lazy loading), expressed as defaulted methods on
ListDataSource and
TreeDataSource. A source owns the answer to
"may this drop happen?" (can_accept) and "apply the move" (accept_drop);
the view merely renders the source's verdict and routes the commit. This is
what lets an external source of truth (e.g. an entity store) drive a
view without the view ever mutating a mirror model.
Key types
ItemKey— blanket identity trait for anyClone + Eq + Hash + Debug + 'statictype.RowState— whether a lazy row's data is resident (Ready) or still loading (Loading).DragEligibility— per-row drag gate returned byListDataSource::drag.DropPosition— where a drop lands relative to the target row.DragSource— who is dragging: the same view (intra-view reorder) or a foreign view/OS drop.DropQuery/DropResponse— hover-time can-I-drop? query and verdict.DropCommit— the committed drop handed toaccept_drop.
// Example: implementing can_accept for a custom ListDataSource
fn can_accept(&self, query: &teksilo_data::DropQuery<'_, usize>) -> teksilo_data::DropResponse {
match &query.source {
teksilo_data::DragSource::SameView { .. } => teksilo_data::DropResponse::Accept,
teksilo_data::DragSource::Foreign { .. } => teksilo_data::DropResponse::Reject,
}
}
API reference
📖 Full rustdoc API for this module
pub trait ItemKey
Import: use teksilo::data::ItemKey;
A stable, hashable identity for a row/node. Blanket-implemented for every
Clone + Eq + Hash + Debug + 'static type, so usize, NodeId, i64,
String, Uuid, … all qualify with no extra work.
In-memory models use positional keys (usize for ListModel, NodeId for
TreeModel); external sources use their own domain key (an entity id), which
is exactly what removes the need to mirror them into a built-in model.
#![allow(unused)] fn main() { pub trait ItemKey: Clone + Eq + std::hash::Hash + std::fmt::Debug + 'static { /* associated items below */ } }
pub enum RowState
Import: use teksilo::data::RowState;
Whether a realized row's data is resident yet. A windowed/lazy source returns
Loading for indices outside its resident window; the view renders a
placeholder skeleton for those and calls request_window to pull them.
#![allow(unused)] fn main() { pub enum RowState { /* variants */ } }
Variants
Ready— Item data is resident;with_item/with_entryreturnsSome.Loading— The row exists (counts againstlen/visible_count) but its data is not yet loaded;with_item/with_entryreturnsNone.
pub enum DropPosition
Import: use teksilo::data::DropPosition;
Where, relative to a target row, a drop lands. Into (reparent) is only
meaningful for trees; flat lists reject it.
#![allow(unused)] fn main() { pub enum DropPosition { /* variants */ } }
Variants
Before— Immediately before the target (sibling, same level).Into— As a child of the target (reparent — trees only).After— Immediately after the target (sibling, same level).
pub enum DragEligibility
Import: use teksilo::data::DragEligibility;
Whether a row may begin a drag at all (the per-item transferable gate, Qt's
Qt::ItemIsDragEnabled / TabBar's with_transferable_predicate).
#![allow(unused)] fn main() { pub enum DragEligibility { /* variants */ } }
Variants
CanDrag— The row can be dragged.NoDrag— The row cannot be dragged (the gesture is suppressed).
pub enum DragSource
Import: use teksilo::data::DragSource;
Who is dragging, from the receiving source's point of view.
SameView is an intra-view reorder identified by the dragged row's key.
Foreign is everything else — an in-app drag from another view or an OS
drop — carried as a type-erased DragPayload the source downcasts itself
(e.g. a designer source downcasts to its palette-drop type, a list source to
its item type, an OS drop to files). This single distinction is exactly what
TabBar already encodes via its source_bar_id.
#![allow(unused)] fn main() { pub enum DragSource<'a, K> { /* variants */ } }
Variants
SameView{ key: K }— An intra-view reorder;keyidentifies the dragged row.Foreign{ payload: &'a DragPayload }— A drag from another view or the OS; downcastpayloadto interpret it.
pub struct DropQuery
Import: use teksilo::data::DropQuery;
A hover-time question posed to a source: "may source drop at position
relative to target?" The source answers with a DropResponse.
#![allow(unused)] fn main() { pub struct DropQuery<'a, K> { /* fields */ } }
Fields
source:DragSource<'a, K>— Who is dragging.target:K— The row currently hovered.position:DropPosition— Where, relative totarget, the drop would land.
pub enum DropResponse
Import: use teksilo::data::DropResponse;
A source's verdict on a DropQuery. Drives the hover affordance and gates
the commit.
#![allow(unused)] fn main() { pub enum DropResponse { /* variants */ } }
Variants
Accept— Allowed: paint the insertion line / reparent box at this position.Reject— Forbidden: paint the no-drop affordance; the drop will be refused.Redirect(DropPosition)— Allowed, but only at a different position — the view snaps its indicator to.0(e.g. a container that accepts children but not sibling reorder redirectsBefore/After→Into).
pub struct DropCommit
Import: use teksilo::data::DropCommit;
A drop the user actually committed, handed to accept_drop to apply.
#![allow(unused)] fn main() { pub struct DropCommit<'a, K> { /* fields */ } }
Fields
source:DragSource<'a, K>— Who dragged.target:K— The row dropped onto.position:DropPosition— Where, relative totarget, the drop landed (after anyRedirect).