Theming and internationalization
Widgets get their theme and locale from Env while they are being built. The theme supplies values such as colour, typography, spacing, radius, motion and component styling. Internationalisation (i18n) supplies translations and locale-aware text. Keeping both in Env makes them explicit inputs to the view instead of hidden global state.
Theme types
| | |
|---|
| | Contains primitive tokens, component themes, and the resolved design-system metadata. |
| | Contains colors, spacing, typography, radius, elevation, motion, and data-visualization tokens. |
| Widget-ready component styles | Contains typed styles for buttons, inputs, badges, tabs, modals, cards, tooltips, progress bars, and related components. |
| Trait implemented by generated design systems | Produces metadata, token records, component specs, pattern specs, asset manifests, and light/dark themes. |
| | |
| Runtime copy of generated design-system metadata | Useful for diagnostics, tooling, docs, and theme inspection. |
The normal entry points are Theme::default() and Theme::dark(). Those use Fission's bundled default design system.
For a generated package, use the generated type:
use fission::theme::{DesignMode, DesignSystem, FissionDefaultDesignSystem};
let light = FissionDefaultDesignSystem::theme(DesignMode::Light);
let dark = FissionDefaultDesignSystem::theme(DesignMode::Dark);
Bundled design-system presets
Fission includes these build-time generated presets:
| | |
|---|
| FissionDefaultDesignSystem | crates/core/fission-theme/design/default |
| FissionMaterialDesign3DesignSystem | crates/core/fission-theme/design/material3 |
| FissionFluent2DesignSystem | crates/core/fission-theme/design/fluent2 |
| FissionLiquidGlassDesignSystem | crates/core/fission-theme/design/liquid-glass |
| FissionCupertinoDesignSystem | crates/core/fission-theme/design/cupertino |
| | crates/core/fission-theme/design/ember |
| FissionGraphiteDesignSystem | crates/core/fission-theme/design/graphite |
Each preset is a normal Design System Package JSON input. The runtime does not parse those JSON files. The fission-theme build script runs the same design-system generator available to application projects and compiles the resulting Rust into the crate.
Use a preset when it matches the platform or brand direction you want. Copy it into your app and generate your own AppDesignSystem when the product needs different tokens.
Environment flow
Env carries the active theme, internationalization registry, locale, and other
app-wide presentation context. During Compose build, widgets read these
values through cx.view.env() or cx.view.theme(). A reducer context is a
different phase; record state transitions there and resolve display copy in
the view.
Desktop, Mobile, Web, and Terminal expose both with_env(...) and
with_sync_env(...). Browser islands expose the same pair. Static site and SSR
apps expose with_env(...), i18n(...), translation_bundle(...),
default_locale(...), and locale_resolver(...). SSR additionally exposes
with_request_env(...) for request-owned environment values.
Use with_env(...) to seed a base environment before the first frame, such as one that already contains translation bundles.
Use with_sync_env(...) when app state should update environment values before
build, such as mirroring a user-selected theme mode or locale. Window-title
configuration is a shell concern, not a field of Env.
Use translation_bundle(...) or i18n(...) on FissionServerApp to register server-side bundles. Use default_locale(...) for the fallback locale and locale_resolver(...) when request data should select the locale before SSR, such as choosing from a path prefix, route parameter, header, cookie, or session. Use with_request_env(...) for other request-owned Env values. The server shell uses the resolved request Env for both widget building and lowering, so TextContent::Key resolves consistently in rendered HTML.
DesktopApp::new(MyApp)
.with_env(create_env()?)
.with_sync_env(|state: &MyState, env: &mut Env| {
env.theme = AppDesignSystem::theme(state.theme_mode);
env.locale = state.locale.clone();
})
.run()?;
The setup is identical for a Web app:
WebApp::new(MyApp)
.with_env(create_env()?)
.with_sync_env(|state: &MyState, env: &mut Env| {
env.theme = AppDesignSystem::theme(state.theme_mode);
env.locale = state.locale.clone();
})
.run()?;
Terminal supports the same design-system and environment data. Packaged font
registration is the deliberate exception: the terminal emulator owns the font
used for its cell grid, so Fission cannot install an app font there.
Internationalization types
| | |
|---|
| Active language and region identifier | Examples include en-US and fr-FR. |
| Translated key-value messages for one locale | Usually loaded from app-owned files at startup. |
| Registry of translation bundles | Stored on Env so widgets can resolve keyed text. |
| Text content resolved through the active locale | Use for product copy that should be translated. |
| Text content rendered exactly as given | Use for already-translated strings, user data, file names, ids, or counts. |
The recommended translation file format for application code is YAML. Keep translation files in the repository, embed them with include_str!, parse them at startup into TranslationBundle values, add those bundles to env.i18n, and store the current locale choice in GlobalState.
The runtime contract is still TranslationBundle, not YAML itself. Advanced applications may generate bundles another way, but Fission documentation and examples use YAML plus include_str! as the default because it is deterministic, readable, and works consistently across every target.
Practical rules
Keep durable user choices such as locale preference, theme mode, and selected brand variant in GlobalState.
Keep loaded theme objects and translation bundles in Env because widgets need them as app-wide presentation context.
Avoid hard-coding unrelated color, spacing, and typography values inside widgets. If a value should be consistent across the product, it belongs in the design system or active theme.
Use TextContent::Key for product copy and TextContent::Literal for data. A label such as settings.title should be keyed. A user name, file path, generated count, or pasted message should usually be literal.
Related pages
Font assets
Generated design systems can expose packaged fonts through
DesignSystem::font_faces(). Each PackagedFont contains the family, weight,
style, format, embedded bytes, and optional variation axes. Canvas/native
shells register those fonts for rendering. Terminal uses the terminal
emulator's font. Static site and SSR omit packaged CSS fonts by default;
choose [web].font_delivery = "external" or "inline" explicitly when needed.