This guide provides a quick look at the most commonly used high-level APIs in Nebble.
All UI and system resources use Managed Handles which utilize Nim's ARC for automatic cleanup.
| Handle Type | Creation | Underlying Layer Access |
|---|---|---|
| WindowHandle | newWindow() | h.rootLayer() |
| TextLayerHandle | newTextLayer(frame) | h.getLayer() |
| BitmapLayerHandle | newBitmapLayer(frame) | h.getLayer() |
| ActionBarLayerHandle | newActionBarLayer() | h.getLayer() |
| MenuLayerHandle | newMenuLayer(frame) | h.getLayer() |
| SimpleMenuLayerHandle | newSimpleMenuLayer(...) | h.getLayer() |
| ScrollLayerHandle | newScrollLayer(frame) | h.getLayer() |
| StatusBarLayerHandle | newStatusBarLayer() | h.getLayer() |
| RotBitmapLayerHandle | newRotBitmapLayer(bmp) | h.getLayer() |
| GPathHandle | newGPath(points) | N/A |
| TimerHandle | after(ms, callback) | N/A |
| DataLoggingSessionHandle | newDataLoggingSession(...) | N/A |
| AppSyncHandle | newAppSyncHandle(...) | N/A |
| ActionMenuHandle | openActionMenu(config) | N/A |
| ContentIndicatorHandle | newContentIndicator() | N/A |
| GBitmapRef | newBitmapRef(resource) | h.bitmap |
The recommended way to define your app structure.
nebbleApp: window: backgroundColor = GColorBlack textLayer: id = titleLabel fullWidth = true y = center h = 30 text = "Hello!" alignment = GTextAlignmentCenter clicks: BUTTON_ID_SELECT = selectHandler
Use FixedString to avoid memory fragmentation. Use .cstr to safely convert to cstring for Pebble APIs.
var s: FixedString[32] s.f("Steps: ", steps) label.text = s.cstr # Use .cstr template for safety
var timeStr: FixedString[16] timeStr.formatTime(tickTime) # Uses default format # or timeStr.formatTime("%H:%M", tickTime) # Custom format timeLayer.text = timeStr.cstr
Inside a LayerUpdateProc:
# Send a message let outbox = beginOutbox() if outbox.success: discard dictWriteInt(outbox.iter, key, value) discard outboxSend() # Receive onInboxReceived(proc(iter: ptr DictionaryIterator, ctx: pointer) {.cdecl.} = let value = readInt32(iter, amkMyKey) )
In src/pkjs.nim:
All callbacks MUST use the {.cdecl.} pragma to be compatible with the Pebble C SDK.
proc myHandler(r: ClickRecognizerRef, c: pointer) {.cdecl.} = discard