Reintent

Dragging

Read a drag on the picture as a value of a choice, a decision when it lands on a possibility.

The card has a sticker, in the corner. Sam drags it next to the title. The sticker has three places it can be, and the drag ends near one of them, so the drag says which. No sentence and no model are needed. When the drag ends far from every place, it says something new: a place the card does not have yet.

You will learn

  • How a choice says which drag reaches it
  • How drop reads where a drag lets go: a possibility, a new value, or nothing
  • How the view shows the drag while it is on

A choice a drag reaches

The sticker's places are a vocabulary, each with its point on the card:

import { createIntent, entity, host, useChoose } from '@reintent/core';
import { vocab } from '@reintent/lib/vocab';

const Place = vocab({
  corner: { label: 'in the corner', words: ['corner'], at: [330, 40] },
  side: { label: 'by the title', words: ['by the title'], at: [60, 120] },
  bottom: { label: 'at the bottom', words: ['bottom'], at: [190, 480] },
});
const card = entity('card', {
  sticker: Place.decl({
    label: 'the sticker',
    aka: ['sticker'],
    default: 'corner',
    judge: false,
    gesture: { path: 'card.sticker', field: 'at' },
    view: ['card.sticker'],
  }),
});
const Card = card(function Card() {
  return host('card', { sticker: useChoose(card.sticker) });
});
const intent = createIntent({ program: <Card /> });

gesture and view go into the choice's about, with label, aka and thing. Together they are the vocabulary's AboutOptions, part of what Place.decl and Place.read take. view lists the paths in the picture the choice moves. gesture is a Gesture: the view's path it answers to (that path, or one under it, such as card.sticker.shadow), and the field of the possibilities' data the drag moves, here at. A point is a Pt, [x, y] in the view's units.

Two more fields shape what a drag gives. axis: { x0, x1, max } makes the drag a number along the view's x, from 0 to max, for a choice whose field is a number. depth: [y0, s0, y1, s1] gives a point its scale at two depths, so things further back are smaller.

Letting go

The view knows the path under the finger and where the drag went. gestureFor(reads, path) finds the choice it reaches, and drop(read, from, to) reads where it let go:

import { drop, gestureFor } from '@reintent/lib/gesture';

const { read, gesture } = gestureFor(intent.realize().reads, 'card.sticker')!;
gesture; // { path: 'card.sticker', field: 'at' }

// Sam drags the sticker from the corner to just by the title.
const landing = drop(read, [330, 40], [70, 128]);
if (landing.outcome === 'snap') intent.decide(landing.reach.id, landing.reach.kind);
intent.realize().reads[0].value; // { kind: 'side', at: [60, 120] }

The drag moves the current place's point by as much as the finger moved, to [70, 128]. Each possibility within reach is a Reach: the choice, the possibility, and d, its distance in units of the tolerance. A point is within reach at DOCK (70 view units) or less, a number at SNAP (0.1). The result is a Landing:

outcomewhere the drag let gowhat the app does
snapnear a possibility, reachintent.decide(reach.id, reach.kind)
valuenear none, and the choice holds any point (gesture.value)intent.decide(id, value): C changes
freenear none: a value the card lacksa new program, with it as a possibility
noopnothing to readnothing

Sam drops the sticker in the middle of the card, [200, 300]. No place is near, and the landing is free with { at: [200, 300] }. The card's places are named variants, and none is there: a new variant is a change of the program. The host edits the sticker's element to hold the place (A program System Two wrote) and offers it, and once accepted, the drop is a decision for it (Words and sentences calls that a weak need).

A choice whose value is any point of a fixed type says so with an open possibility, named in its gesture (gesture: { …, value: 'spot' }). A drop near none of its named places is then value, { kind: 'spot', value: { at: [200, 300] } }: a new coordinate within the type it has, which the app decides. The choices change, the program does not.

gestureFor(reads, path, focus) puts the thing in focus first, when two choices answer to the same path. A path no gesture answers to gives null.

While the drag is on

Until Sam lets go, the sticker follows the finger. That is the view's own state, and nothing is written to the intent:

import { dragValue, preview } from '@reintent/lib/gesture';

const dragged = dragValue(read, [330, 40], [250, 90]); // { at: [250, 90] }
preview(read, dragged!); // { kind: 'corner', at: [250, 90] }

dragValue(read, from, to) gives where the drag leaves the field, a Dragged: { at, scale? } for a point, { value } on an axis. scaleAt(depth, y) gives the scale at depth y. preview(read, dragged) is the current value with the dragged field in it, for the view to draw.

drop is these steps together. reaches(read, dragged) lists each possibility's distance, nearest first. land(reaches, free) takes the nearest within reach, else what free gives. dataOf(read, dragged) gives the data a dragged value would give a new possibility, { at: [200, 300] }.

Recap

  • gesture and view in a declaration say which drag reaches a choice and which field it moves.
  • gestureFor(reads, path) finds the choice; drop(read, from, to) snaps to a possibility within DOCK or SNAP, gives a value of its open possibility, a free value, or nothing.
  • A snap and a value are a person's decision (C); a free value is a new variant, for a new program.
  • dragValue and preview show the drag while it is on, without writing anything.

Last updated on

Edit on GitHub