tiramisu/ui
Lustre UI integration for Tiramisu.
This module provides bidirectional message passing between Tiramisu games and Lustre UI overlays.
Setup
- In your Lustre init, register to receive messages from the game:
import tiramisu/ui
fn init(_) {
#(model, ui.register())
}
- Send messages from game to UI:
// In Tiramisu update
ui.dispatch_to_lustre(UpdateScore(new_score))
- Send messages from UI to game:
// In Lustre update
StartGame -> #(Model(..model, playing: True), ui.send_to_game(Resume))
Values
pub fn dispatch_to_lustre(msg: ui_msg) -> effect.Effect(game_msg)
Dispatch a message from Tiramisu game to Lustre UI.
Use this in your Tiramisu update function to send state updates to the UI.
Example
// In Tiramisu update
fn update(model, msg, ctx) {
#(
new_model,
effect.batch([
effect.tick(Tick),
ui.dispatch_to_lustre(UpdateScore(model.score)),
])
)
}
pub fn dispatch_to_tiramisu(
msg: game_msg,
) -> effect.Effect(ui_msg)
Send a message from Lustre UI to Tiramisu game.
Use this in your Lustre update function to control the game.
Example
// In Lustre update
fn update(model, msg) {
case msg {
StartGame -> #(
Model(..model, playing: True),
ui.dispatch_to_tiramisu(Resume)
)
PauseGame -> #(
Model(..model, playing: False),
ui.dispatch_to_tiramisu(Pause)
)
}
}
pub fn register_lustre() -> effect.Effect(a)
Register your Lustre app to receive messages from Tiramisu.
Call this in your Lustre app’s init function.