Expand description
§rok-ui
A shadcn/ui-style component system for GPUI desktop apps, with a React-like developer experience:
| React / shadcn/ui | rok-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).
- bloc
bloc - Architecture: BLoC
- components
- Every rok-ui component. Each one follows the same conventions:
- context
- Values scoped to part of the tree:
Providemakes a value available to every component below it, andcx.context::<T>()reads the nearest one (React’s context, Flutter’sInheritedWidget). - cx
Cx: one context handle for app code.- db
db - Database
- devtools
devtools - 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.
- form
form - Forms
- hooks
- React-style hooks on top of GPUI’s element state.
- http
http - 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.
- persist
persist - 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.- query
query - Data: queries, mutations and procedures
- router
router - Routing
- runtime
runtime - The shared background runtime.
- state
state - 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 storesstyle_overrides: StyleRefinementandsx: Sxfields, so callers can chain.w_full(),.mt_4()and the rest of the GPUI style API, or passstyles!styles. - keyframes
- Define keyframe sequences for
Motion. - query_
key query - Build a
QueryKeyfrom parts. AnyDebugvalue is a part: strings, numbers, ids and search structs. - routes
router - Include the route tree that
rok_ui_build::routes(..).generate()wrote inbuild.rs: aroutesmodule with one typed route per page file androutes::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 ownedSx.- typed_
route router - 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.
- memoize
query - Memoize an async function: calls with the same arguments share one in-flight future and its
result, until
rok_ui::query::memo::invalidateforgets it. Arguments are owned andDebug(they form the cache key); the output isClone + Send + Sync. - procedure
query - Declare a typed async command: a
Procedurewith optional queries to invalidate after it succeeds.