Newer
Older
<p align="center">
<img src="images/kayak.svg" alt="Kayak UI" width="600" />
</p>
<h1>
<p align="center">
Kayak UI
<p>
</h1>
## What is Kayak UI?
Kayak UI is a declarative UI that can be used to make user interfaces in Rust primarily targeting games. It's free an open-source!
## WARNING
Kayak UI is in the very early stages of development. Important features are missing and documentation is non-existent. There are a few weird oddities because of how the rsx proc macro works, but these could be fixed in the future. Currently kayak is built to be used inside of bevy and as such the existing renderer is built with that in mind, however Kayak UI is render agnostic and could be rendered using any modern rendering API.
## Features
- Easy to use declarative syntax using a custom proc macro
- Basic widget and global state management
- Fast and accurate layouts using morphorm: https://github.com/geom3trik/morphorm
- A few default widgets check out [src/widgets](./src/widgets)!
- Style system built to kind of mimic CSS styles.
- Image and Nine patch rendering.
- Vec widgets see vec_widget example!
- Removal of widgets.
## Bevy Renderer Features
- Image and NinePatch renderer
- Fast MSDF Font renderer
- Quad renderer with rounded corners.
- Custom UI node to ensure UI renders on top of 3D and 2D entities.
- Fully integrated into bevy to capture input events, use bevy assets(images, etc).
- Widget prop diffing see issue: https://github.com/StarArawn/kayak_ui/issues/1
## Example Screenshot
<img src="images/screen1.png" alt="Kayak UI" width="600" />
kayak_ui = { git="https://github.com/StarArawn/kayak_ui", rev="{INSERT_COMMIT_SHA_HERE}", features = ["bevy_renderer"] }
bevy = "0.6.0"
## Declarative
Kayak UI makes it painless to build out complex UI's using custom or pre-built widgets. Custom widgets are layed out in a XML like syntax that allows you to more easily visualize the widget tree. Here's an example of that syntax:
```rust
rsx! {
<App>
<Button styles={Some(play_button_styles)}>
<Text
size={30.0}
content={"Hello World!".to_string()}
/>
</Button>
</App>
}
```
You can easily declare your own custom widgets:
```rust
#[widget]
pub fn MyCustomWidget(props: MyCustomWidgetProps) {
rsx! {
<>
{children}
</>
}
}
```
## Widget State
Widget's can create their own state and will re-render when that state changes.
let on_event = OnEvent::new(move |_, event| match event.event_type {
let count_text = format!("Current Count: {}", count);
rsx! {
<>
<Window position={(50.0, 50.0)} size={(300.0, 300.0)} title={"Counter Example".to_string()}>
<Button on_event={Some(on_event)}>
<Text size={24.0} content={"Count!".to_string()} />
</Button>
</Window>
</>
}
}
```
Widget's can also access global state and when the global state is bound to the widget it will auto re-render:
```rust
#[widget]
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
let global_count = {
if let Ok(world) = context.get_global_state::<World>() {
if let Some(global_count) = world.get_resource::<Binding<GlobalCount>>() {
global_count.clone()
} else {
return;
}
} else {
return;
}
};
// Binds the global state to the widget.
// When `global_count.set()` is called the Counter widget will auto re-render.
context.bind(&global_count);
let global_count = global_count.get().0;
rsx! {
<>
<Window position={(50.0, 50.0)} size={(300.0, 300.0)} title={"Counter Example".to_string()}>
<Text size={32.0} content={format!("Current Count: {}", global_count).to_string()}>{}</Text>
</Window>
</>
}
}
// Example bevy system:
fn count_up(global_count: Res<Binding<GlobalCount>>) {
global_count.set(GlobalCount(global_count.get().0 + 1));
}
```
## Creating new fonts
The `bevy_kayak_ui` renderer uses MSDF fonts in order to render crisp and accurate fonts at different scales without needing to re-rasterize the font. In order to generate custom fonts you need to use the following tool:
https://github.com/Chlumsky/msdf-atlas-gen
To generate a font run the following command:
```
.\msdf-atlas-gen.exe -font .\font_name.ttf -type msdf -minsize 32 -format png -imageout font_name.png -json font_name.json
```
Where font_name is the name of your font. You can play around with the different parameters that are provided but keep in mind that some of the font stuff is currently hardcoded and might result in graphical glitches if you change the settings too much. You should also try to use a decent size for the `minsize` parameter. The smaller the size the more artifacts will appear in the text.