Menu Builder DSL
Nim-friendly, zero-allocation DSL for building menus declaratively.
This module provides a compile-time macro defineMenu that generates a fully initialized BuiltMenu with static storage, ensuring memory safety and adhering to the project's zero-heap-allocation policy.
Features:
- Zero heap allocation (uses static arrays)
- Compile-time validation
- Type-safe integration with variables
- Automatic C++ pointer handling
Example:
var volume: cfloat = 50.0 var mute: bool = false # Generates 'mainMenu' variable in current scope defineMenu mainMenu: value "Volume", volume, 0.0, 100.0 checkbox "Mute", mute action "Save", saveSettings submenu "Advanced", advancedMenu close "Back"
Usage: Pass mainMenu (or mainMenu.menu) to ui.openPage().
Macros
macro defineMenu(varName: untyped; body: untyped): untyped
-
Define a statically allocated menu.
Parameters:
- varName: Name of the variable to declare
- body: DSL block defining menu items
Generates:
- var varName: BuiltMenu[N]
- Initialization code