2D drawing primitives and text rendering for the 320x240 LCD
All drawing operations write to a double-buffered framebuffer in PSRAM. Call flush() once per frame to transfer the buffer to the physical display via DMA. Drawing functions use pixel coordinates (0,0 at top-left) and RGB565 color format. Use rgb(r,g,b) to convert from 8-bit RGB values.
ez.display.clear()
ez.display.draw_text(10, 10, "Hello", colors.WHITE)
ez.display.flush()
| Parameter | Description |
|---|---|
| width | Sprite width in pixels |
| height | Sprite height in pixels |
local overlay = ez.display.create_sprite(200, 100)
overlay:set_transparent_color(0xF81F)
overlay:clear(0xF81F)
overlay:fill_round_rect(0, 0, 200, 100, 10, colors.DARK_GRAY)
overlay:draw_text(20, 40, "Popup Menu", colors.WHITE)
overlay:push(60, 70, 200) -- Draw at 78% opacity
| Parameter | Description |
|---|---|
| x | X position in pixels |
| y | Y position in pixels |
| percent | Battery percentage (0-100) |
local battery = ez.system.get_battery()
ez.display.draw_battery(290, 2, battery.percent)
| Parameter | Description |
|---|---|
| x | X position |
| y | Y position |
| width | Bitmap width in pixels |
| height | Bitmap height in pixels |
| data | Raw RGB565 pixel data (2 bytes per pixel, big-endian) |
local data = ez.storage.read_bytes("/icons/logo.raw")
ez.display.draw_bitmap(100, 50, 64, 64, data)
| Parameter | Description |
|---|---|
| x | X position |
| y | Y position |
| width | Bitmap width in pixels (original size) |
| height | Bitmap height in pixels (original size) |
| data | Packed 1-bit data (MSB first, row by row) |
| scale | Scale factor (1, 2, 3, etc.) - optional, default 1 |
| color | RGB565 color for "on" pixels - optional, default WHITE |
-- 8x8 icon(8 bytes), scaled 3x, cyan color
display.draw_bitmap_1bit(10, 10, 8, 8, icon_data, 3, colors.CYAN)
| Parameter | Description |
|---|---|
| x | X position |
| y | Y position |
| width | Bitmap width in pixels |
| height | Bitmap height in pixels |
| data | Raw RGB565 pixel data |
| transparent_color | RGB565 color to treat as transparent |
local data = ez.storage.read_bytes("/sprites/player.raw")
-- Treat magenta(0xF81F) as transparent
ez.display.draw_bitmap_transparent(100, 100, 32, 32, data, 0xF81F)
| Parameter | Description |
|---|---|
| x | X position in character cells |
| y | Y position in character cells |
| w | Width in character cells |
| h | Height in character cells |
| title | Optional title string |
| border_color | Border color (optional) |
| title_color | Title color (optional) |
-- Dialog box with title
ez.display.draw_box(5, 3, 30, 10, "Confirm", colors.BORDER, colors.HIGHLIGHT)
| Parameter | Description |
|---|---|
| x | X position in pixels |
| y | Y position in pixels |
| char | Character to draw (first char of string) |
| color | Character color (optional) |
ez.display.draw_char(100, 100, ">", colors.GREEN) -- Cursor
ez.display.draw_char(50, 50, "X", colors.RED) -- Close icon
| Parameter | Description |
|---|---|
| x | Center X position |
| y | Center Y position |
| r | Radius |
| color | Circle color (optional) |
-- Ring around a point
ez.display.draw_circle(160, 120, 50, colors.CYAN)
| Parameter | Description |
|---|---|
| x | X position in pixels |
| y | Y position in pixels |
| bars | Fix quality (0-3 bars filled) |
| Parameter | Description |
|---|---|
| x | X start position in pixels |
| y | Y position in pixels |
| w | Width in pixels |
| color | Line color (RGB565) |
| Parameter | Description |
|---|---|
| x | X position |
| y | Y position |
| width | Bitmap width in pixels |
| height | Bitmap height in pixels |
| data | Packed 3-bit pixel indices (8 pixels packed into 3 bytes) |
| palette | Table of 8 RGB565 color values |
local palette = {0x0000, 0x2104, 0x4208, 0x630C, 0x8410, 0xC618, 0xE71C, 0xFFFF}
display.draw_indexed_bitmap(0, 0, 256, 256, tile_data, palette)
| Parameter | Description |
|---|---|
| x | Destination X position |
| y | Destination Y position |
| dest_w | Destination width |
| dest_h | Destination height |
| data | Packed 3-bit pixel indices (256x256 source assumed) |
| palette | Table of 8 RGB565 color values |
| src_x | Source X offset in pixels |
| src_y | Source Y offset in pixels |
| src_w | Source width to sample |
| src_h | Source height to sample |
| Parameter | Description |
|---|---|
| x | X position on screen |
| y | Y position on screen |
| data | JPEG file data as a string (from async_read or file load) |
| scale_x | Horizontal scale factor (default 1.0) |
| scale_y | Vertical scale factor (default = scale_x) |
| off_x | Source image X offset (pan, default 0) |
| off_y | Source image Y offset (pan, default 0) |
| max_w | Maximum output width (default 0 = unlimited) |
| max_h | Maximum output height (default 0 = unlimited) |
| Parameter | Description |
|---|---|
| x1 | Start X position |
| y1 | Start Y position |
| x2 | End X position |
| y2 | End Y position |
| color | Line color (optional) |
-- Diagonal line
ez.display.draw_line(0, 0, 319, 239, colors.WHITE)
-- Horizontal separator
ez.display.draw_line(10, 100, 310, 100, colors.GRAY)
| Parameter | Description |
|---|---|
| x | X position in pixels |
| y | Y position in pixels |
| color | Pixel color (optional) |
-- Plot a point
ez.display.draw_pixel(160, 120, colors.RED)
| Parameter | Description |
|---|---|
| x | X position in pixels |
| y | Y position in pixels |
| w | Width in pixels |
| h | Height in pixels |
| progress | Progress value (0.0 to 1.0) |
| fg_color | Foreground color (optional) |
| bg_color | Background color (optional) |
-- Download progress at 75%
ez.display.draw_progress(20, 150, 280, 12, 0.75, colors.GREEN, colors.DARK_GRAY)
| Parameter | Description |
|---|---|
| x | X position in pixels |
| y | Y position in pixels |
| w | Width in pixels |
| h | Height in pixels |
| color | Outline color (optional) |
-- Focus border around selected item
ez.display.draw_rect(10, 50, 300, 25, colors.HIGHLIGHT)
| Parameter | Description |
|---|---|
| x | X position |
| y | Y position |
| w | Width |
| h | Height |
| r | Corner radius |
| color | Outline color (optional) |
-- Rounded button outline
ez.display.draw_round_rect(100, 180, 120, 40, 8, colors.WHITE)
| Parameter | Description |
|---|---|
| x | X position in pixels |
| y | Y position in pixels |
| bars | Signal strength (0-4 bars) |
-- Strong signal
ez.display.draw_signal(270, 2, 4)
-- Weak signal
ez.display.draw_signal(270, 2, 1)
| Parameter | Description |
|---|---|
| x | X position in pixels |
| y | Y position in pixels |
| text | Text string to draw |
| color | Text color (optional, defaults to TEXT) |
ez.display.draw_text(10, 20, "Hello World", colors.WHITE)
ez.display.draw_text(10, 40, "Status: OK", colors.GREEN)
| Parameter | Description |
|---|---|
| x | X position in pixels |
| y | Y position in pixels |
| text | Text string to draw |
| fg_color | Text color |
| bg_color | Background color |
| padding | Padding around text (optional, defaults to 1) |
-- Label with dark background for contrast
ez.display.draw_text_bg(50, 100, "GPS: Locked", colors.GREEN, colors.BLACK, 2)
| Parameter | Description |
|---|---|
| y | Y position in pixels |
| text | Text string to draw |
| color | Text color (optional, defaults to TEXT) |
ez.display.draw_text_centered(10, "Settings", colors.WHITE)
ez.display.draw_text_centered(120, "No messages", colors.GRAY)
| Parameter | Description |
|---|---|
| x | X position in pixels |
| y | Y position in pixels |
| text | Text string to draw |
| fg_color | Text color |
| shadow_color | Shadow color (optional, defaults to black) |
| offset | Shadow offset in pixels (optional, defaults to 1) |
-- Title with drop shadow
ez.display.draw_text_shadow(20, 10, "ezOS", colors.WHITE, colors.DARK_GRAY, 2)
| Parameter | Description |
|---|---|
| x1 | First vertex X |
| y1 | First vertex Y |
| x2 | Second vertex X |
| y2 | Second vertex Y |
| x3 | Third vertex X |
| y3 | Third vertex Y |
| color | Outline color (optional) |
-- Arrow pointing right
ez.display.draw_triangle(100, 110, 100, 130, 120, 120, colors.WHITE)
| Parameter | Description |
|---|---|
| x | X position in pixels |
| y | Y position in pixels |
| bars | Signal strength (0-3 bars filled) |
| Parameter | Description |
|---|---|
| x | Center X position |
| y | Center Y position |
| r | Radius |
| color | Fill color (optional) |
-- Status indicator dot
ez.display.fill_circle(300, 10, 5, colors.GREEN)
| Parameter | Description |
|---|---|
| x | X position in pixels |
| y | Y position in pixels |
| w | Width in pixels |
| h | Height in pixels |
| color | Fill color (optional) |
-- Selection highlight
ez.display.fill_rect(0, 50, 320, 20, colors.SELECTION)
-- Button background
ez.display.fill_rect(100, 200, 120, 30, colors.BLUE)
| Parameter | Description |
|---|---|
| x | X position in pixels |
| y | Y position in pixels |
| w | Width in pixels |
| h | Height in pixels |
| color | Fill color |
| density | Percentage of pixels filled (0-100, default 50 for checkerboard) |
-- Semi-transparent overlay
ez.display.fill_rect_dithered(0, 0, 320, 240, colors.BLACK, 50)
-- Light shadow effect
ez.display.fill_rect_dithered(5, 5, 100, 50, colors.BLACK, 25)
| Parameter | Description |
|---|---|
| x | X position in pixels |
| y | Y position in pixels |
| w | Width in pixels |
| h | Height in pixels |
| color | Fill color |
| spacing | Line spacing (2 = 50%, 3 = 33%, etc., default 2) |
-- Retro scanline effect
ez.display.fill_rect_hlines(0, 0, 320, 240, colors.BLACK, 2)
| Parameter | Description |
|---|---|
| x | X position in pixels |
| y | Y position in pixels |
| w | Width in pixels |
| h | Height in pixels |
| color | Fill color |
| spacing | Line spacing (2 = 50%, 3 = 33%, etc., default 2) |
-- Vertical stripe pattern
ez.display.fill_rect_vlines(10, 10, 100, 100, colors.BLUE, 3)
| Parameter | Description |
|---|---|
| x | X position |
| y | Y position |
| w | Width |
| h | Height |
| r | Corner radius |
| color | Fill color (optional) |
-- Button background
ez.display.fill_round_rect(100, 180, 120, 40, 8, colors.BLUE)
ez.display.draw_text(130, 190, "OK", colors.WHITE)
| Parameter | Description |
|---|---|
| x1 | First vertex X |
| y1 | First vertex Y |
| x2 | Second vertex X |
| y2 | Second vertex Y |
| x3 | Third vertex X |
| y3 | Third vertex Y |
| color | Fill color (optional) |
-- Play button triangle
ez.display.fill_triangle(130, 100, 130, 140, 170, 120, colors.GREEN)
ez.display.clear()
ez.display.draw_text(10, 10, "Frame complete", colors.GREEN)
ez.display.flush() -- Push to screen
local cols = ez.display.get_cols() -- e.g., 40 with 8px font
local fh = ez.display.get_font_height() -- e.g., 16 for medium font
for i, line in ipairs(lines) do
ez.display.draw_text(10, 10 + (i-1) * fh, line, colors.WHITE)
end
local fw = ez.display.get_font_width() -- e.g., 8 for medium font
local x = 10 + 5 * fw -- Position after 5 characters
local h = ez.display.get_height() -- Returns 240
local rows = ez.display.get_rows() -- e.g., 15 with 16px font
local w = ez.display.get_width() -- Returns 320
| Parameter | Description |
|---|---|
| r | Red component (0-255) |
| g | Green component (0-255) |
| b | Blue component (0-255) |
local purple = ez.display.rgb(128, 0, 255)
local orange = ez.display.rgb(255, 165, 0)
ez.display.fill_rect(10, 10, 50, 50, purple)
| Parameter | Description |
|---|---|
| path | File path on SD card (e.g., "/screenshots/screen_001.bmp") |
local ok = display.save_screenshot("/screenshots/capture.bmp")
| Parameter | Description |
|---|---|
| fwd_nudge | optional world-space distance to shift billboards |
| Parameter | Description |
|---|---|
| level | Brightness level (0-255) |
ez.display.set_brightness(200) -- Bright, good for indoor use
ez.display.set_brightness(50) -- Dim, saves battery
ez.display.set_brightness(0) -- Backlight off
| Parameter | Description |
|---|---|
| x | Left edge of clip region |
| y | Top edge of clip region |
| w | Width of clip region |
| h | Height of clip region |
| Parameter | Description |
|---|---|
| size | Font size string: "tiny", "small", "medium", or "large" |
ez.display.set_font_size("large")
ez.display.draw_text(10, 10, "Big Title", colors.WHITE)
ez.display.set_font_size("small")
ez.display.draw_text(10, 30, "Small details", colors.GRAY)
| Parameter | Description |
|---|---|
| style | One of "regular", "bold", "italic", or "bold_italic" |
ez.display.set_font_size("small_aa")
ez.display.set_font_style("bold")
ez.display.draw_text(10, 10, "Heading", colors.WHITE)
ez.display.set_font_style("regular")
| Parameter | Description |
|---|---|
| text | Text string to measure |
local text = "Hello World"
local width = ez.display.text_width(text)
local x = (320 - width) / 2 -- Center on 320px display
ez.display.draw_text(x, 100, text, colors.WHITE)
string Color scheme nameez.bus.subscribe("theme/colors", function(scheme)
self.bg_color = ThemeManager.colors.background
end)
string Icon pack nameez.bus.subscribe("theme/icons", function(pack)
self:reload_icons()
end)
string Wallpaper name (e.g., "clouds", "mountains", "none")ez.bus.subscribe("theme/wallpaper", function(name)
print("Wallpaper changed to: " .. name)
end)