Nebble provides a powerful, macro-based Domain Specific Language (DSL) called nebbleApp (or its alias nebbleWatchface). This DSL eliminates repetitive Pebble boilerplate and enables a more modern, reactive-style UI definition.
The DSL transforms a declarative block into optimized C code that handles:
import nebble nebbleApp: window: backgroundColor = GColorBlack textLayer: id = timeLabel fullWidth = true y = center h = 30 text = "12:00" alignment = GTextAlignmentCenter font = FONT_KEY_GOTHIC_28_BOLD init: logInfo("App started!")
The DSL supports all major Pebble layers:
The actionBarLayer DSL block automatically manages action bar icons as reference-counted bitmaps. Icons are created from resource IDs and their lifetime is automatically managed by the DSL.
Example:
nebbleApp: actionBarLayer: id = actionBar backgroundColor = GColorWhite icons: up = RESOURCE_ID_IMAGE_UP down = RESOURCE_ID_IMAGE_DOWN select = RESOURCE_ID_IMAGE_SELECT
The DSL creates internal GBitmapRef variables for each icon and manages their lifecycle, ensuring proper cleanup when the app exits. This eliminates memory leaks from unmanaged bitmap creation.
The DSL introduces high-level layout properties that make cross-platform development (Chalk, Emery, Basalt) significantly easier:
| Property | Description |
|---|---|
| fullWidth = true | Sets width to 100% of the parent (usually the window). |
| fullHeight = true | Sets height to 100% of the parent. |
| fullScreen = true | Sets both width and height to 100% of the parent. |
| x = center | Horizontally centers the layer relative to its parent. |
| y = center | Vertically centers the layer relative to its parent. |
| parent = handle | Attaches this layer to another layer instead of the root window. |
Register click handlers directly within the DSL block:
proc selectHandler(recognizer: ClickRecognizerRef; context: pointer) {.cdecl.} = vibes.shortPulse() nebbleApp: # ... layers ... clicks: BUTTON_ID_SELECT = selectHandler
Subscribe to time updates:
proc onTick(tickTime: ptr tm, units: TimeUnits) {.cdecl.} = # Update UI discard nebbleApp: # ... layers ... tickTimer: handler = onTick unit = TimeUnitsMinute
Standard Pebble C apps require careful ordering of window_create, layer_add_child, and window_stack_push. A mistake in this order often leads to nil pointer dereferences. The nebbleApp macro enforces the correct order and ensures every resource is safely tracked by Nim's ARC.