Using the Standard Library
std is the library every Kagari program is compiled with. It is written in Kagari; items marked
#[builtin] are provided by the compiler or the engine.
The design follows what visual-novel studios actually build: characters with named slots,
background transitions through rule images or a colour, preset motions, title cards, BGM with an
intro and a loop, voice bound to the line, galleries unlocked from what the player has seen. What
other engines leave to studio macros, std provides as typed, checked values.
Modules
| Module | Contents | Kind | Page |
|---|---|---|---|
std | String, Vec, Range, Rat, Decimal, Option, Result, Eq, Integer, RandChoose, Asset, the asset types, asset, system_font | const fn | std |
std::prelude | the names imported into every module | — | std::prelude |
std::time | Duration, ZERO, ms, secs | const fn | std::time |
std::narrative | Step, push_step, rng_choose, Say, Choice, Meta, Narrative and its records | pushdown fn (push_step, rng_choose, Meta::write); fn (Narrative, Meta::get/set); const fn (meta) | std::narrative |
std::narrative::text | Text, the t![…] builtins, ToText, text effects, TextStyle | const fn | std::narrative::text |
std::screen | Screen, entities, properties, layers, Hud, camera, choice menu, geometry, colours | const fn | std::screen |
std::screen::anim | Easing, Tween, Transition, Motion and presets | const fn | std::screen::anim |
std::screen::audio | channels, loops, sounds, fades | const fn | std::screen::audio |
std::stage | Character, hide_all, side_face | const fn | std::stage |
std::system | System, Settings, Setting, modes, seen sets, bindings | fn (handles, seen sets); const fn (constructors) | std::system |
std::system::nav | navigation between modes; starting and loading the story | fn | std::system::nav |
std::system::saves | save slots and their information | fn | std::system::saves |
std::ui | Element, signals, components, the targets of the UI forms | fn | std::ui |
std::ui::style | Paint, Look, ButtonStyle, SliderStyle | const fn | std::ui::style |
The prelude
Every module imports the prelude implicitly: the names of
std::prelude are in scope without a use. A name declared in the module, or
imported by it, takes precedence over a prelude name.
Everything else is imported by path:
use std::screen::anim::rule_with;use std::narrative::text::speed;Design rules
Every item of the library follows these rules. They tell you what to expect from an item you have not looked up yet.
- Kinds.
- Everything that builds or changes a
Screen, every animation, transition and text-effect value, and every geometry helper is aconst fn. - The engine’s view of a running game, settings and meta reads, navigation, saves and UI are
fn. push_step,rng_chooseandMeta::writeare the onlypushdown fn.- Engine-owned state with timeline semantics is a
#[builtin]type with#[builtin]methods. Plain data (geometry, colours, tweens, styles) are ordinary structs withpubfields plusconst fnbuilders.
- Everything that builds or changes a
- Units.
- Positions and lengths are
i32/u32pixels in the design resolutionSystem::resolution. - Times are
time::Duration, whole milliseconds. - Fractions (anchor, scale, opacity, volume) are
Decimal, with literals like0.5; opacity and volume range over0.0..=1.0. - Settings volumes are
Int<0, 100>. - There are no unit strings, and there is no second scale for any quantity.
- Positions and lengths are
- No hidden defaults. Every animation constructor takes its duration explicitly. The only
implicit values are the neutral ones: easing
Linear, delay 0, rule softness 0, repeat 1, identity transforms. - Changes need animations. Every visible property is a
Prop<T>(interpolated, takes aTween) or a layer (ImageLayer,LabelLayer,MovieLayer, swapped with aTransition). Only non-interpolable layout settings (set_plane,set_z,set_anchor,set_flip,set_fill_size,gate) are direct setters.Change<T>,SwapandChannelChangeare#[must_use]: a change with noapply_animationdoes not happen (warningW3023). - Animations never change the start or end state. The logical screen of a step is the
persistent state after its render: entities with their components, plus the Hud, camera,
screen filter and audio channels. That is what snapshots, equality and the consistency check
use.
- A
TweenorTransitionalways runs from the old value to the value set bychange. - A
Motionis a relative path that must end at identity (offset 0, scale 1, rotation 0); otherwise it is a const-evaluation error. - The timeline, scheduled animations, one-shot sounds and the choice menu belong to the step only and are not part of the logical screen.
- So a click (which completes the step’s timeline), skip, or the
animationssetting being off can never change the logical screen.
- A
- Fixed component set. Studios add no components. They extend the library with
const fnhelpers and constant data.std::stageis an example of such a layer. - Type-checkable without overloading or coercion. Asset-typed functions use a trait bound;
interpolation uses a trait bound. The few special signatures (
nav::start) are listed in Compiler Rules for std Items. Onlystddeclares traits, all#[builtin]:Eq,Integer,RandChoose,Asset,Step,ToText,ShaderArgandShader. Games never implement them;Eqis automatic, andShaderArgcomes with#[shader_arg]. - References are shared pointers. In
const fnandfncode they may be bound to locals, so a render names an entity once and changes it in several statements. In apushdown fnthey are parameters only.
For example:
const fn hanako_appears(mut screen: Screen) -> Screen { let hanako = screen.entity(HANAKO); hanako.image().change(HANAKO::SMILE).apply_animation(cut()); hanako.opacity().change(1.0).apply_animation(tween(ms(300))); screen}Last updated Oct 29, 2026