lcdui.canvas — Creates a canvas


lcdui.canvas [-autoflush 1 | 0 ] [-cmdbg color ] [-cmdfg color ] [-eventhandler code ] [-fullscreen 1 | 0 ] [-title title] [-suppresskeys 1 | 0 ]

$canvascmd [cget -optname ] [configure -optname optval ] [flush [x y width height] ] [graphics] [repaint] [servicerepaints]


The lcdui.canvas command creates a canvas that can be used to draw arbitrary items, such as rectangles, text, circles, and respond to keyboard events. For an in-depth look at the Java code that this command is based on, see:

The options describing the canvas are as follows:

  • -autoflush: Takes a boolean argument (1 or 0) indicating FIXME

  • -cmdbg: Selects a background color for the command background.

  • -cmdfg: Selects a background color for the command foreground.

  • -eventhandler: The Hecl code to execute when an event is generated.

  • -fullscreen: A boolean switch specifying whether to run in "full screen" mode. "Full screen" mode means that commands, which would normally be accessible via certain keys on the cell phone, are not accessible, and that those keys generate regular events instead of calling commands.

  • -suppresskeys: A boolean switch specifying whether to suppress key events or not. Suppressing these events, if the application does not need to keep track of them, may improve performance some.

The lcdui.canvas command returns an object that is itself a command, and can be called with several subcommands:

  • flush: With no argument, flushes (displays) the off-screen buffer to the visible display. With arguments x y width height, flushes the specified section to the screen.

  • graphics: Returns a graphics object that acts as a command to manipulate the Canvas' graphics buffer.

  • repaint: Repaints the entire canvas.

  • servicerepaints: Forces any repaints that haven't occured yet to be performed immediately.


set canvas [lcdui.canvas -title "Test Canvas" -commandaction backToMainMenu \
    -eventhandler canvasEvents]
set graphics [$canvas graphics]
$graphics frect [list 10 10] [list 10 80]
$graphics frect [list 80 10] [list 10 80]
$graphics frect [list 10 50] [list 80 10]
$canvas setcurrent

Live example: