# Fingers, gestures and the wheel

hotty 0.10 tells a program which kind of pointer the user points with, gives
each finger a drag of its own, reports two fingers on an element as one
gesture, and gives an element the wheel in pixels (SPEC §9, §9.1, §9.8,
§9.9). The handlers take them beside `surf.Click` and `surf.Drag`; the
`surfui/canvas` component puts them together as a whiteboard or a map does.

## Handlers

```templ
<div class="map" { surf.On(ctx, "map",
	surf.Drag(a.drag), surf.Gesture(a.pinch), surf.Wheel(a.wheel))... }>
```

`surf.On` writes the `data-on` words they need (`drag gesture wheel`); a
template never writes them.

- **`surf.Drag`** hears each finger's drag on its own: a `DragEvent`
  carries its `Finger` (-1 for the mouse's and a pen's), the kind of
  `Pointer` that began it, on every call, and `Cut` at an End the host cut
  short (a gesture took the fingers over, a new document). A whiteboard
  keys its strokes in progress by `Finger`, and throws away one a pinch cut
  short.
  A touch drags only where `touch-action` pans nothing (SPEC §9.1).
- **`surf.Gesture`** hears two fingers on the element, or a touchpad's
  pinch over it: a `GestureEvent` from its Start to its End, each with
  the whole transform since the start (`Scale`, `Angle`), where the
  fingers' centre is (`Col`, `Row`, and `X`, `Y` on an element with
  `data-steps`), and its start's `Mods` and `Pointer`. Over it, two
  fingers are never the host's.
- **`surf.Wheel`** hears the wheel and a touchpad's scroll over the
  element, in CSS pixels summed over a frame (`DX`, `DY`), with `Precise`
  for a touchpad and `Mods` (Ctrl with a touchpad's scroll is a browser's
  pinch). Nothing scrolls there.

A 0.9 host reports neither gestures nor the wheel, and its drags carry no
finger and no kind: `Gesture` and `Wheel` are never called there, and two
fingers and the wheel are the host's.

## The canvas

`canvas.View` is a view over the app's own drawing, an SVG the app writes as
its children, in the drawing's units. The canvas owns the camera: it pans
and zooms the drawing with one SVG transform, and the app's tool hears its
drags where they are in the drawing.

```templ
<div class="h-64">
	@canvas.View(&a.view, canvas.Props{ID: "pad", OnDrag: a.draw}) {
		for _, s := range a.strokes {
			<path d={ s.D } fill="none" stroke="currentColor" stroke-width="2"></path>
		}
	}
</div>
```

```go
func (a *App) draw(d canvas.Drag) {
	switch {
	case d.Start:
		a.live[d.Finger] = a.newStroke(d.X, d.Y)
	case d.Discard: // a pinch's first finger: no mark
		a.remove(a.live[d.Finger])
	default:
		a.live[d.Finger].add(d.X, d.Y)
	}
}
```

What it does by default:

| Input | Does |
| --- | --- |
| a wheel's notches | zoom about the pointer, about 15% a notch |
| a touchpad's two fingers | pan, times `Sensitivity` (2) |
| Ctrl (or Cmd) and the wheel | zoom about the pointer; a touchpad's, times `Sensitivity` |
| Shift and a wheel's notches | pan across |
| a pinch | zoom and pan with its centre: a touchpad's times `Sensitivity`, a touchscreen's under the fingers |
| the middle button | pan |
| the left button, a pen, one finger | the app's tool (`OnDrag`), each finger a drag of its own; with `Hand`, the left button and a finger pan, and a pen still draws |
| the right button | a context menu's; with `RightButton`, the tool's (`Drag.Button` 2) |
| back, forward | `OnAuxClick`, or, moved, the tool's |
| `0` | home: the drawing's origin at the top left, at 100% |
| `+` or `=`, `-` | zoom about the centre |
| the arrows | pan |

- **Overriding:** `Props` sets the sensitivity, the zoom's bounds
  (`MinZoom`, `MaxZoom`), `Hand`, `RightButton`, and `DiscardCut`, how
  long a stroke a gesture cut short may have lasted and still end with
  `Discard` (400ms). The keys are the canvas's
  kit defaults: a `surfui.KeyScope` around it takes any of them first, and
  binds others (`{Key: "h", Name: "home", Run: a.view.Home}`).
- **The keyboard:** a press on the canvas gives it the keyboard
  (`tabindex="0"`), and from then on its keys are the surface's. An app
  whose keys come from the terminal binds them in a `surfui.KeyScope`
  around the canvas, or the canvas has them while it has the focus.
- **Its stylesheet alone:** `canvas.CSS()` is the canvas's own rules,
  without the kit's, for an app with its own CSS and no Basecoat sheet:
  `surf.New("board", page, appCSS+canvas.CSS())`.
- **The camera** is `State.Camera()`: the drawing's origin at `X`, `Y` in
  the canvas, drawn `Zoom` times its size. `State.Home`, `State.ZoomBy`
  (about the centre, as `+` and `-`) and `State.SetCamera` move it from the
  app's own controls, within `MinZoom` and `MaxZoom`.
- **Its size** is the host's: the canvas hears its area in cells (SPEC
  §9.5) and sizes its steps in pixels by the host's cell (`cellcss`),
  following each `caps` that changes it. A canvas sized in whole cells,
  such as one that fills its surface, is exact to the pixel.
- **A 0.9 host** sends no wheel and no gesture: the canvas draws and pans
  with drags (the middle button, or the hand), and zooms with its keys.
- **Every move renders the view.** A drawing of many strokes is a compiled
  component (`surf.Compile`, [compiled components](https://hotty.neuroplast.io/docs/hotty-surf/compiled)), so a
  pan sends only the transform.
