Crates.io | open_ui |
lib.rs | open_ui |
version | 1.4.0 |
source | src |
created_at | 2022-07-17 22:01:32.999087 |
updated_at | 2022-08-11 13:38:54.92143 |
description | 🕹 Build cross-platform GUI apps with Rust |
homepage | https://github.com/craigfay/open_ui |
repository | https://github.com/craigfay/open_ui |
max_upload_size | |
id | 627389 |
size | 63,612 |
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.
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
Add OpenUI as a dependency in any Cargo project:
# Cargo.toml
[dependencies]
open_ui = "*"
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);
}
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.