1. Reference
  2. Display

<canvas-tool>

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

Display

This tag has more than one name. Every spelling is the same tag, so write whichever feels natural. Pick one and every example on this page uses it.

canvas-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>
The snippet drawn by Hype Apps on a phone, in light mode The snippet drawn by Hype Apps on a phone, in dark mode
This snippet as Hype Apps draws it on a phone. It follows this page's light or dark theme.

Attributes

NameWhat it doesDefault
cursor The pointer shown over the pad (crosshair, grab …).
string
icon A Material symbol for the tool.
string
label The name shown in a tool list.
string
name The tool's name, a word (#id.tool:name, $id.tool).
string

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.

This page is also Markdown, and all of HAM is in llms.txt.