5 stable releases
1.4.0 | Aug 11, 2022 |
---|---|
1.3.1 | Jul 18, 2022 |
1.3.0 | Jul 17, 2022 |
1.2.0 | Jul 17, 2022 |
1.1.1 | Jul 17, 2022 |
#303 in Rendering
34KB
804 lines
Welcome! 👋
OpenUI is a developer friendly Rust library for creating cross-platform GUI apps. This is a great choice for anyone who doesn't want to work directly with OpenGL, or wrappers like Glutin and Glium, and for anyone who doesn't need an entire desktop web framework like Electron or Tauri.
Try It Yourself! 🕹
It's extremely easy to try out the OpenUI example project, a 1980's-style Snake Game. Use the arrow keys and spacebar to play.
git clone git@github.com:craigfay/open_ui.git && cd open_ui
cargo run
Developer Installation 💽
Add OpenUI as a dependency in any Cargo project:
# Cargo.toml
[dependencies]
open_ui = "*"
Build Your Own App with OpenUI 🧱
To create a Rust program that renders a UI, simply define a struct that implements the UIController
interface:
use open_ui::UIController;
// Define a struct to hold your application data
struct SnakeGame {};
// Implement the `UIController` interface to define application behavior
impl UIController for SnakeGame {
fn blueprint(&self) -> UIBlueprint {
// This function wil be called once before the application opens,
// and determines the initial settings of the rendering window.
}
fn next_frame(&mut self) -> Option<&RgbaImage> {
// This function will be called called every frame,
// and returns the contents of the next render-able frame,
// or `None` if the application should terminate.
}
fn process_events(&mut self, events: &Vec<UIEvent>) {
// This function will be called every frame, receiving
// input events, and usually responding by modifying state.
}
}
Then, pass an instance of that struct into UI::launch()
:
use open_ui::UI;
fn main() {
let application = SnakeGame::new();
UI::launch(application);
}
Caveats
OpenUI does all its work on the CPU, and does not attempt (at this time) to leverage GPU acceleration. This means that its probably not suitable for workloads involving realistic 3D rendering. That said, OpenUI is more than capable of handling almost any 2D graphics workload on modern machines.
Resources 📖
Dependencies
~7–15MB
~211K SLoC