Skip to main content

Crate rok_ui

Crate rok_ui 

Source
Expand description

§rok-ui

A shadcn/ui-style component system for GPUI desktop apps, with a React-like developer experience:

React / shadcn/uirok-ui
function Card(props) { … }#[component] fn Card(…) -> impl IntoElement { … }
<Button variant="outline" size="sm">Button::new("id").outline().small()
props.children#[children] children: Vec<AnyElement>
className="w-full mt-4".w_full().mt_4() on any component
onClick={() => …}.on_click(|event, window, cx| …)
const [n, setN] = useState(0)let n = use_state(window, cx, || 0)
CSS variables (--primary)cx.theme().colors.primary
use rok_ui::prelude::*;

struct MyView;

impl Render for MyView {
    fn render(&mut self, _: &mut Window, _: &mut Context<Self>) -> impl IntoElement {
        AppRoot::new().child(Button::new("hello").label("Hello"))
    }
}

fn main() {
    Application::new().with_assets(rok_ui::Assets).run(|cx: &mut App| {
        rok_ui::init(cx);
        cx.open_window(WindowOptions::default(), |_, cx| cx.new(|_| MyView)).unwrap();
    });
}

Re-exports§

pub use cx::Cx;
pub use icon::Assets;
pub use icon::AssetsWithFallback;
pub use icon::Icon;
pub use icon::IconName;
pub use keyed::Keyed;
pub use gpui;

Modules§

bidi
Right-to-left and mixed-direction text (Arabic, Persian, Hebrew).
blocbloc
Architecture: BLoC
components
Every rok-ui component. Each one follows the same conventions:
context
Values scoped to part of the tree: Provide makes a value available to every component below it, and cx.context::<T>() reads the nearest one (React’s context, Flutter’s InheritedWidget).
cx
Cx: one context handle for app code.
dbdb
Database
devtoolsdevtools
Devtools (feature devtools): an overlay that shows the router history, the query cache, recent mutation runs and the live forms (status, submits and errors).
fonts
Custom fonts: bundled Google Fonts and helpers to register your own.
formform
Forms
hooks
React-style hooks on top of GPUI’s element state.
httphttp
HTTP
icon
Built-in stroke icons (24px grid, 2px stroke, round caps, in the Lucide style) and the asset source that serves them to GPUI.
keyed
Keyed: stable identity for an element in a list.
motion
Motion: keyframe animations, transitions and enter / exit presence.
persistpersist
Stores saved to disk (feature persist).
platform
Small platform helpers: the clipboard, and saving bytes where the user chooses.
prelude
use rok_ui::prelude::*; brings in GPUI’s prelude, every component, the theme, the hooks and the #[component] macro.
queryquery
Data: queries, mutations and procedures
routerrouter
Routing
runtimeruntime
The shared background runtime.
statestate
Reactive state
styles
Shared styling helpers: sizes and className-style overrides.
sx
StyleX-style styling: style objects defined once, merged at use, last wins.
theme
Design tokens and the active theme.

Macros§

children
A Vec<AnyElement> from mixed element types, with control flow:
implement_style_overrides
Implement Styled (and .sx(..)) for a component that stores style_overrides: StyleRefinement and sx: Sx fields, so callers can chain .w_full(), .mt_4() and the rest of the GPUI style API, or pass styles! styles.
keyframes
Define keyframe sequences for Motion.
query_keyquery
Build a QueryKey from parts. Any Debug value is a part: strings, numbers, ids and search structs.
routesrouter
Include the route tree that rok_ui_build::routes(..).generate() wrote in build.rs: a routes module with one typed route per page file and routes::tree().
style
One inline style object, for one-off or dynamic values: style! { width: {px(width)}, background: primary/90 }.
styles
Define StyleX-style style objects once, at module level.
sx
sx![A.base, condition => A.extra, other]: merge styles, including some only when a condition holds. Produces an owned Sx.
typed_routerouter
Declare a typed route: a struct whose fields are the pattern’s parameters.
view
JSX-like markup compiled to builder calls.

Functions§

init
Install the default theme and the key bindings rok-ui components rely on (text editing, Tab focus navigation). Call once at startup.

Attribute Macros§

component
Turn a function into a reusable component, React style.
memoizequery
Memoize an async function: calls with the same arguments share one in-flight future and its result, until rok_ui::query::memo::invalidate forgets it. Arguments are owned and Debug (they form the cache key); the output is Clone + Send + Sync.
procedurequery
Declare a typed async command: a Procedure with optional queries to invalidate after it succeeds.