# <canvas-tool>

A drawing tool written in HAM and loaded into a draw pad as a plugin: touch handlers, state and options.

Category: Display. Also written `<draw-tool>`.

```ham
<canvas-tool name="lasso"
             label="Lasso"
             icon="gesture"
             cursor="crosshair"
             @on.touch.start="$tool.points = $event.doc_x + ',' + $event.doc_y"
             @on.touch.move="$tool.points = $tool.points + ' ' + $event.doc_x + ',' + $event.doc_y"
             @on.touch.end="#pad.select.path:$tool.points; $tool.points = ''">
    <state points=""/>
    <options>
        <column style="gap-8 p-12 w-full h-220">
            <text style="font-semibold">Lasso</text>
            <button action="#pad.selection.fill">Fill</button>
            <button action="#pad.selection.delete">Delete</button>
            <button action="#pad.select.clear">Done</button>
        </column>
    </options>
</canvas-tool>
```

How Hype Apps draws it on a phone: [light](https://hypeapps.dev/img/tags/canvas-tool-light.webp), [dark](https://hypeapps.dev/img/tags/canvas-tool-dark.webp).

## Attributes

| Name | What it does | Default |
|---|---|---|
| `cursor` | The pointer shown over the pad (crosshair, grab …). |  |
| `icon` | A Material symbol for the tool. |  |
| `label` | The name shown in a tool list. |  |
| `name` | The tool's name, a word (#id.tool:name, $id.tool). |  |

Any tag also takes gestures: `@on.tap`, `@on.longpress`, `@on.doubletap` and `@on.swipeleft` (and right, up and down). `@click` runs on a tap too.

## Related tags

- [`<state>`](https://hypeapps.dev/docs/reference/state.md): Declares a draw tool's own variables and starting values, read and written as $tool.* by its handlers.
- [`<options>`](https://hypeapps.dev/docs/reference/options.md): Inside a drawing tool written in HAM, the tool's options popover.
- [`<column>`](https://hypeapps.dev/docs/reference/column.md): Stacks its children top to bottom, with a gap between them and an alignment across.
- [`<text>`](https://hypeapps.dev/docs/reference/text.md): A run of text; with @text it shows an expression that updates as its variables change.
- [`<button>`](https://hypeapps.dev/docs/reference/button.md): A tappable button that runs an action: a fetch, a navigation or a statement.
- [`<ad>`](https://hypeapps.dev/docs/reference/ad.md): An ad slot in the page, filled with a banner from AdMob in a built app.
- [`<avatar>`](https://hypeapps.dev/docs/reference/avatar.md): A round avatar from a photo, initials or an icon, in any size and color.
- [`<badge>`](https://hypeapps.dev/docs/reference/badge.md): A small count or dot pinned to the corner of an icon or any other element.

All tags: https://hypeapps.dev/docs/reference.md · The full reference: https://hypeapps.dev/llms.txt
