Instead of writing 'fiddly' code to handle geometry, feedback, and animations for every unique drag interaction, developers can now use 'declarative dragging' to specify what an element should become. This shift, implemented in the Dragology library, allows the system to automatically synthesize smooth, responsive interactions by speculatively rendering the application's future states.

A screenshot of a figure explaining how Dragology enables model-driven dragging to create higher-quality interactions with less manual coding.
A conceptual overview of how Dragology automates the synthesis of drag-and-drop behaviors through a model-driven approach.declarative-dragging.github.io

This image provides a high-level summary of the library's primary goal: simplifying the creation of complex UI interactions.

Inverting the Drag-and-Drop Problem

Traditional drag-and-drop design often requires developers to program specific visual behaviors directly, which can be labor-intensive for complex geometries. This barrier often prevents educators, mathematicians, and game designers from creating rich tactile interactions.

Declarative dragging inverts this process. Rather than programming the movement, an interface author specifies which future model states should be accessible by dragging a specific element. The system then handles the heavy lifting of visual synthesis.

“Rather than programming all that visual behavior directly, you simply say, for each element you want to make draggable, which future states of your application dragging it should lead to.”

— Declarative Dragging

The Mechanism of Speculative Rendering

The Dragology engine operates by taking a model state and rendering it to a view. When a user begins a drag, the engine speculatively renders the various future states that the drag could lead to.

By analyzing these speculative renderings, the system extracts the position of the dragged element in each view to determine valid drop zones. It then combines these 'possible worlds' into a single, fluid interaction without requiring the author to define the paths manually.

A diagram showing how a model state is rendered to a view and how speculative renderings of target states determine drop zones for an animated drag.
The Dragology engine identifies valid drop zones by speculatively rendering possible future states of the application model.declarative-dragging.github.io

This diagram illustrates the core mechanism of speculative rendering where the system analyzes multiple 'possible worlds' to synthesize a fluid interaction.

Composability and Real-World Applications

Dragology is designed to be composable, meaning simple model-driven behaviors can be combined. Developers can layer modifiers to add features like snapping to a grid, floating elements, or specific transition animations.

The system has already been used to create interactive mathematical 'explorables,' such as twisted trees and braid diagrams. It is also being integrated into Hazel, an academic programming environment where it allows refactorings to become tangible and discoverable through physical interaction.

A screenshot of a figure showing a map of a walk in Seattle and hand-drawn lattices of trees with strands running between them.
Visual representations of order-preserving maps between trees, illustrating the types of mathematical structures the system can handle.declarative-dragging.github.io

This visual supports the mention of mathematical 'explorables' and the specific types of diagrams the technology can facilitate.

Limitations and Technical Trade-offs

While the system simplifies the creation of high-quality interactions, the source material does not provide specific performance benchmarks regarding frame rates or the computational overhead of speculative rendering.

The current implementation is specifically built for SVG interfaces on the web, and its scalability for extremely high-frequency state changes remains an area for further exploration.

What Hacker News readers are saying

  • Alternative: One commenter suggested that the Hazel programming environment serves as a similar example of prior art for this type of interaction. comment ↗
  • Experience: A reader expressed that the interactive demos provided in the article were visually delightful and served as a genuinely educational experience. comment ↗

Summarized opinions from the Hacker News thread, not verified facts. Read the full discussion ↗