Your First Hera Kit Application
Create a small stateful interface and connect it to the server with AppHost.
The application in this guide displays a counter and updates it when the user activates a button. Its view body reads mounted state and returns a description of the interface, while AppHost supplies the connection, surface, and UI thread that bring the description into Hera's retained scene.
Add the Dependency
For an application at apps/example in this repository, use a path relative to that application's manifest:
[dependencies]
hera-kit = { path = "../../crates/kit" }
tokio = { version = "1", features = ["full"] }For a workspace application, also add the package to the workspace configuration as appropriate. Cargo names the dependency hera-kit, while Rust imports it as hera_kit. This example implements a view directly, so it works whether or not the optional macros feature is enabled.
Define and Host the Interface
use hera_kit::{
button, text, v_stack, AppHost, Size,
View, ViewContext, ViewError, ViewExt,
};
struct Counter;
impl View for Counter {
fn body(&self, cx: &mut ViewContext<'_>) -> Result<impl View, ViewError> {
let count = cx.state("count", || 0u32);
let value = cx.read(&count);
Ok(v_stack()
.spacing(16.0)
.child(text("Counter").ui_font(28.0))
.child(button(text(format!("Count: {value}")), move |ctx| {
count.update(ctx.runtime, |value| *value += 1);
}))
.padding(24.0))
}
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
AppHost::new(|_, _| Counter)
.with_window("Counter", Size::new(480.0, 320.0))
.run("/tmp/hera.sock")
.await?;
Ok(())
}The main function connects the host to /tmp/hera.sock; change that path to match your deployment. It also names the window and supplies an initial logical size through with_window. Once connected, the host follows geometry changes from the server, which remains authoritative over the surface's dimensions.
Button Action Lifecycle
The first evaluation at the counter's mounted identity creates the count slot with an initial value of zero. Later evaluations reuse that slot, and cx.read supplies its current value for the button label. The action captures the binding so it can update the same storage when activated.
Activation runs the action on the UI thread, where it increments the model value and causes the UI loop to request evaluation. Kit then rebuilds the description, resolves layout, and reconciles the new label against the accepted scene. When CommitAccepted arrives, the candidate becomes the next baseline; the server can render and present it afterward.
Keep the body focused on describing the current model. Since evaluation can repeat or produce a candidate that is rejected, external side effects belong in actions or application services rather than in the body itself.
Run with Consistent Fonts
The server renders glyphs selected by the client, so both processes need the same registered font assets and manifest. The example's .ui_font selects the toolkit's UI face; explicit font keys need matching registrations on both sides. The text guide explains how to configure those faces.
Continue with state and bindings, or compare handwritten authoring with the attribute macro.
Source Reference
The following files in the Hera checkout define the behavior described on this page.
crates/kit/src/host/mod.rscrates/kit/src/view/context.rscrates/kit/tests/attributes.rs