16#include <goodisplay/gdey029T94.h>
32 uint32_t widget_action_id)
35 .
pushCanvas(title, key_action_id, widget_action_id);
79 c->setTextInverted(inverted);
96 c->setFontId(font_id);
101 const uint8_t* candidates, uint32_t count,
102 uint8_t* out_font_id)
104 if (!text || !candidates || !out_font_id || count == 0) {
109 auto* gfx =
static_cast<Gdey029T94*
>(display->getNativeHandle());
115 for (uint32_t i = 0; i < count; ++i) {
119 gfx, cp.c_str(), max_width_px, candFonts, count,
false);
121 uint8_t pickedId = candidates[count - 1];
122 for (uint32_t i = 0; i < count; ++i) {
123 if (candFonts[i] == picked) {
124 pickedId = candidates[i];
128 *out_font_id = pickedId;
141 const char* text, uint8_t align)
153 c->drawRect(x, y, w, h, filled);
169 c->drawLine(x0, y0, x1, y1);
177 c->drawCircle(x, y, r, filled);
182 int16_t x2, int16_t y2,
bool filled)
186 c->drawTriangle(x0, y0, x1, y1, x2, y2, filled);
191 int16_t r,
bool filled)
195 c->drawRoundRect(x, y, w, h, r, filled);
200 const uint8_t* data, uint32_t len)
205 c->drawBitmap(x, y, w, h, data, len);
213 c->drawHLine(x, y, w);
221 c->drawVLine(x, y, h);
229 c->commit(full_refresh);
299 uint16_t* w, uint16_t* h)
319 c->drawSprite(x, y, sprite);
327 c->setInkWhite(white);
332 const char* text, uint16_t step_px, uint16_t frame_ms)
337 int32_t handle = c->marquee(x, y, window_w,
340 if (handle > 0)
return static_cast<int>(handle);
347 const uint8_t* frames, uint32_t len)
351 int32_t handle = c->spriteCreate(frame_w, frame_h, frame_count, frames, len);
352 if (handle > 0)
return static_cast<int>(handle);
380 uint16_t target_w, uint16_t frame_h)
384 if (!data || len == 0 || target_w == 0 || frame_h == 0) {
390 const uint16_t stride =
static_cast<uint16_t
>((target_w + 7) / 8);
391 const size_t cap = 65536;
394 uint16_t out_stride = 0, out_h = 0;
396 &out_stride, &out_h);
399 uint16_t frames = out_h / frame_h;
401 int32_t handle = c->spriteCreate(target_w, frame_h, frames, strip.get(),
402 static_cast<uint32_t
>(stride) * frame_h * frames);
403 if (handle > 0)
return static_cast<int>(handle);
418 int32_t f = c->spriteGetFrame(sprite);
420 *out =
static_cast<uint16_t
>(f);
429 return c->spriteSetFrameDurations(sprite, ms, count) ?
HOST_OK
434 uint16_t repeat, uint32_t done_action_id)
438 return c->spritePlay(sprite, mode, frame_ms, repeat, done_action_id)
478 uint32_t handle = c->animStart(tc);
479 if (handle != 0)
return static_cast<int>(handle);
507 int8_t s = c->animState(handle);
515 return c->animActiveCount();
519 uint32_t done_action_id)
523 uint32_t handle = c->animBlink(elem_id, period_ms, count, done_action_id);
524 if (handle != 0)
return static_cast<int>(handle);
531 int32_t initial, int32_t step)
543 return c->addText(widget_id, max_len, initial ? cp.c_str() :
nullptr)
590 int n = c->getText(widget_id, &tmp[0], cap);
592 tmp.resize(std::strlen(tmp.c_str()));
607 *out = c->getFocus();
615 c->setKeyRepeat(initial_ms, repeat_ms);
Singleton that owns plugin-pushed UI views (lists, confirms, inputs).
int setCanvasLongPressAction(uint32_t action_id)
int pushCanvas(const char *title, uint32_t key_action_id, uint32_t widget_action_id)
int setViewFooter(const char *hint)
cdc::ui::CanvasView * canvasView()
static PluginUiState & instance() noexcept
Generic canvas view exposed to WASM plugins for custom UIs.
int host_anim_pause(uint32_t handle, bool paused)
Pause (paused != 0) or resume a tween; delay time freezes too.
int host_anim_blink(uint32_t elem_id, uint16_t period_ms, uint16_t count, uint32_t done_action_id)
Convenience: blink an element.
int host_anim_active_count(void)
Number of live tweens plus playing sprites (>= 0).
int host_anim_start(const host_anim_t *cfg)
Start (or queue, when start_after != 0) a tween on an element.
int host_anim_cancel(uint32_t handle)
Cancel a tween and its chained successors; handle 0 cancels all of the canvas's tweens....
int host_anim_state(uint32_t handle)
Query a tween's state.
int host_image_render(const uint8_t *data, size_t len, uint16_t target_w, uint8_t *out, size_t out_size, uint16_t *out_stride_bytes, uint16_t *out_height_px)
Decode, scale to target_w (aspect preserved) and dither to 1-bpp.
int host_sprite_create(uint16_t frame_w, uint16_t frame_h, uint16_t frame_count, const uint8_t *frames, uint32_t len)
Create a sprite from a packed 1-bpp frame sheet in plugin memory.
int host_sprite_set_frame(uint32_t sprite, uint16_t frame)
Jump to a frame. A running playback continues from it.
int host_sprite_play(uint32_t sprite, uint8_t mode, uint16_t frame_ms, uint16_t repeat, uint32_t done_action_id)
Start host-driven playback from frame 0.
int host_sprite_create_from_image(const uint8_t *data, uint32_t len, uint16_t target_w, uint16_t frame_h)
Create a sprite straight from an encoded PNG/JPEG.
int host_sprite_destroy(uint32_t sprite)
Destroy a sprite and reclaim its arena bytes. Recorded draw-sprite commands referencing it are skippe...
int host_sprite_set_frame_durations(uint32_t sprite, const uint16_t *ms, uint16_t count)
Optional per-frame durations in milliseconds.
int host_sprite_set_scale(uint32_t sprite, uint8_t scale)
Integer upscale factor applied whenever the sprite is drawn.
int host_sprite_set_flags(uint32_t sprite, uint8_t flags)
Replace the sprite's flag set (HOST_SPRITE_FLAG_*).
int host_sprite_stop(uint32_t sprite)
Stop playback, keeping the current frame on screen.
int host_sprite_set_mask(uint32_t sprite, const uint8_t *mask, uint32_t len)
Attach a transparency mask plane (same sheet layout and size as the frame data). Mask bit set = pixel...
int host_sprite_get_frame(uint32_t sprite, uint16_t *out)
Read the currently displayed frame index.
int host_view_canvas_clear_ex(uint32_t flags)
Clear with options: like host_view_canvas_clear, but HOST_CANVAS_CLEAR_KEEP_SPRITES keeps the sprite ...
int host_view_canvas_get_value(uint32_t widget_id, int32_t *out)
Read the integer value of a slider widget.
int host_view_canvas_elem_show(uint32_t elem_id, bool visible)
Show or hide an element (hidden elements are skipped on replay).
int host_view_canvas_draw_round_rect(int16_t x, int16_t y, int16_t w, int16_t h, int16_t r, bool filled)
Draw a rounded rectangle outline or filled, corner radius r.
int host_view_canvas_elem_set_offset(uint32_t elem_id, int16_t ox, int16_t oy)
Set an element's replay offset relative to its recorded coordinates.
int host_view_canvas_elem_remove(uint32_t elem_id)
Remove an element and all draw commands recorded under it.
int host_view_canvas_push(const char *title, uint32_t key_action_id, uint32_t widget_action_id)
Push a new canvas view.
int host_view_canvas_get_focus(uint32_t *out)
Read the currently focused widget id, 0 if none.
int host_view_canvas_hline(int16_t x, int16_t y, int16_t w)
Draw a horizontal line.
int host_view_canvas_vline(int16_t x, int16_t y, int16_t h)
Draw a vertical line.
int host_view_canvas_clear(void)
Clear all draw state and widgets. Equals host_view_canvas_clear_ex(0).
int host_view_canvas_draw_rect(int16_t x, int16_t y, int16_t w, int16_t h, bool filled)
Draw a rectangle outline or filled rectangle.
#define HOST_FONT_COUNT
Number of defined font ids.
int host_view_canvas_set_ink(bool white)
Draw subsequent shapes in white instead of black.
int host_view_canvas_elem_move(uint32_t elem_id, int16_t dx, int16_t dy)
Shift an element's replay offset by a delta.
int host_view_canvas_elem_begin(uint32_t elem_id)
Start recording draw calls under element elem_id.
int host_view_canvas_set_text_color(bool inverted)
Switch between normal and inverted (white on black) text.
int host_view_canvas_set_font(uint8_t font_id)
Switch the canvas font to one of the canonical HOST_FONT_* ids.
int host_view_canvas_draw_bitmap(int16_t x, int16_t y, int16_t w, int16_t h, const uint8_t *data, uint32_t len)
Draw a 1-bpp bitmap; set bits render black, unset bits are transparent.
int host_view_canvas_add_button(uint32_t widget_id)
Add a focusable button widget bound to widget_id.
int host_view_canvas_draw_pixel(int16_t x, int16_t y)
Draw a single pixel.
int host_view_canvas_draw_circle(int16_t x, int16_t y, int16_t r, bool filled)
Draw a circle outline or filled circle of radius r centred at (x, y).
int host_view_canvas_marquee(int16_t x, int16_t y, int16_t window_w, const char *text, uint16_t step_px, uint16_t frame_ms)
Record a host-driven text marquee (ticker).
int host_view_canvas_set_focus(uint32_t widget_id)
Move keyboard focus to the given widget.
int host_view_canvas_get_text(uint32_t widget_id, char *out, size_t cap)
Read the text of a text-input widget.
int host_view_canvas_set_text_size(uint8_t size)
Set text size multiplier (Adafruit-GFX semantics).
int host_view_canvas_elem_get_offset(uint32_t elem_id, int16_t *ox, int16_t *oy)
Read an element's current replay offset.
int host_view_canvas_set_key_repeat(uint16_t initial_ms, uint16_t repeat_ms)
Configure key auto-repeat timing for the canvas.
int host_view_canvas_elem_get_bounds(uint32_t elem_id, int16_t *x, int16_t *y, uint16_t *w, uint16_t *h)
Bounding box of an element's recorded commands, offset applied.
int host_view_canvas_elem_end(void)
Stop recording draw calls into an element.
int host_view_canvas_draw_text_aligned(int16_t x, int16_t y, int16_t w, const char *text, uint8_t align)
Draw text within a horizontal box.
int host_view_canvas_set_footer(const char *hint)
Override the footer hint of the canvas.
int host_view_canvas_draw_text(int16_t x, int16_t y, const char *text)
Draw text at (x, y) using the current text size/colour.
int host_view_canvas_set_shade(uint8_t shade)
Set the fill ink for subsequent filled shapes (rect, circle, triangle).
int host_view_canvas_remove_widget(uint32_t widget_id)
Remove a widget previously added to the canvas.
int host_text_pick_font_that_fits(const char *text, int16_t max_width_px, const uint8_t *candidates, uint32_t count, uint8_t *out_font_id)
Pick the largest HOST_FONT_* whose rendered text fits within max_width_px. Candidates are evaluated i...
int host_view_canvas_add_text(uint32_t widget_id, uint16_t max_len, const char *initial)
Add a T9 text input widget bound to widget_id.
int host_view_canvas_set_text(uint32_t widget_id, const char *text)
Set the text of a text-input widget.
int host_view_canvas_elem_set_z(uint32_t elem_id, int8_t z)
Set an element's replay layer (z-order).
int host_view_canvas_draw_triangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, bool filled)
Draw a triangle outline or filled triangle through three points.
int host_view_canvas_set_anim_policy(uint8_t refresh_policy, uint8_t max_fps)
Configure host-driven animation pacing for the current canvas.
int host_view_canvas_set_long_press_action(uint32_t action_id)
Set the action id fired on a canvas long-press.
int host_view_canvas_draw_line(int16_t x0, int16_t y0, int16_t x1, int16_t y1)
Draw a line between two points.
int host_view_canvas_set_value(uint32_t widget_id, int32_t value)
Set the integer value of a slider widget.
int host_view_canvas_get_body_size(uint16_t *w, uint16_t *h)
Read the drawable body region (excluding header/footer).
int host_view_canvas_commit(bool full_refresh)
Flush draw state to the panel.
#define HOST_CANVAS_CLEAR_KEEP_SPRITES
int host_view_canvas_add_slider(uint32_t widget_id, int32_t min, int32_t max, int32_t initial, int32_t step)
Add an integer slider widget bound to widget_id.
int host_view_canvas_elem_clear(uint32_t elem_id)
Drop only an element's recorded draw commands, keeping the element.
int host_view_canvas_draw_sprite(int16_t x, int16_t y, uint32_t sprite)
Record a draw of a sprite's current frame at (x, y).
CDC Badge OS plugin host API - canonical C ABI contract.
#define HOST_ERR_INVALID_ARG
#define HOST_ERR_NO_MEMORY
#define HOST_ERR_NOT_FOUND
Internal UTF-8 <-> CP437 helpers for the plugin host API boundary.
PsramUniquePtr< T > psramAlloc(std::size_t count) noexcept
Allocate count elements of T in PSRAM (8-bit capable region).
IDisplay * getDisplayInstance()
Returns lazily created singleton display instance.
std::string toDisplay(const char *utf8)
Decode a UTF-8 (with optional HTML entities) string into CP437 bytes.
int copyUtf8(const char *cp437, char *out, size_t out_size)
Encode a CP437 string into a caller buffer as UTF-8.
const GFXfont * pickFontThatFits(Adafruit_GFX *gfx, const char *text, int maxWidthPx, const GFXfont *const *candidates, size_t count, bool cp437=false)
Picks the largest font from candidates whose rendered width of text fits within maxWidthPx....
const GFXfont * getGfxFont(FontId id)
Resolves a FontId to its underlying GFX font pointer.
Replay accessors: geometry, flags and pixel pointers of a sprite.
Tween start configuration (mirrors host_anim_t plus the blink shorthand).
uint16_t repeat
Extra runs; REPEAT_FOREVER = endless.
uint32_t startAfter
Predecessor tween handle; 0 = start now.
Tween description for host_anim_start(); zero-init unused fields.