Canvas:onPaint() event


This event is fired continuously to redraw the Canvas. You can put all your drawing operations inside this event handler function.

Notes

  • This event is thrown asynchronously by a Task, so be sure to call sleep() if you use an ui.update() loop.
  • When drawing operations are executed inside an event or in a Task, Canvas.begin() and Canvas.flip() must be called to preserve the Direct2D drawing state across Tasks.

Return value

This event returns no value.

Example

local ui = require "ui" require "canvas" -- create a fixed Window local win = ui.Window("Canvas:onPait() sample", "fixed", 320, 200) -- create a Canvas local canvas = ui.Canvas(win) canvas.align = "all" -- set the onPaint() event handler to draw on the canvas function canvas:onPaint() self:begin() self:clear() self:print("Hello World !", 10, 10) self:flip() end -- shows the Window and wait for it to be closed ui.run(win):wait()