https://github.com/unrust/uni-app
Unrust native/wasm compatibility layer for window, input and filesystem
https://github.com/unrust/uni-app
filesystem input rust wasm windowing
Last synced: about 1 month ago
JSON representation
Unrust native/wasm compatibility layer for window, input and filesystem
- Host: GitHub
- URL: https://github.com/unrust/uni-app
- Owner: unrust
- License: apache-2.0
- Created: 2018-06-26T07:45:21.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-03-30T15:41:53.000Z (over 2 years ago)
- Last Synced: 2025-08-27T05:52:01.784Z (about 2 months ago)
- Topics: filesystem, input, rust, wasm, windowing
- Language: Rust
- Homepage:
- Size: 82 KB
- Stars: 7
- Watchers: 3
- Forks: 8
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# unrust / uni-app
[](https://docs.rs/uni-app)
[](https://crates.io/crates/uni-app)This library is a part of [Unrust](https://github.com/unrust/unrust), a pure rust native/wasm game engine.
This library provides a native/wasm compatibility layer for following components :
* Window creation
* Input (mouse + keyboard)
* File system (local + http[s], ready-only)## Usage
```toml
[dependencies]
uni-app = "0.4.*"
``````rust
extern crate uni_app;fn main() {
// create the game window (native) or canvas (web)
let app = uni_app::App::new(uni_app::AppConfig {
size: (800, 600),
title: "my game".to_owned(),
vsync: true,
show_cursor: true,
headless: false,
resizable: true,
fullscreen: false,
intercept_close_request: false,
icon: None,
});
// start game loop
app.run(move |app: &mut uni_app::App| {
for evt in app.events.borrow().iter() {
// print on stdout (native) or js console (web)
uni_app::App::print(format!("{:?}", evt));
// exit when pressing escape
match &evt {
uni_app::AppEvent::KeyUp(ev) if ev.code == ScanCode::Escape => {
uni_app::App::exit();
}
_ => (),
}
}
});
}
```## Build
### As web app (wasm32-unknown-unknown)
Install wasm32 target :
```
rustup target install wasm32-unknown-unknown
```
Install [wasm-pack](https://rustwasm.github.io/wasm-pack/installer/)
and [npm](https://www.npmjs.com/get-npm)Compile the demo with
```
wasm-pack build examples
```
This creates a wasm package in examples/pkgRun the demo with
```
cd www
npm install
npm run start
```Open your browser at http://localhost:8080/
### As desktop app (native-opengl)
Run it from the www/ directory to be able to load the test.txt file :
```
cd www && cargo run --example basic --release
```## License
Licensed under either of
* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
* MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)at your option.
### Contribution
You can contribute to this library through pull requests. If you do so, please update the CHANGELOG.md and CREDITS.md files. If you provide a new feature, consider adding an example as a tutorial/showcase.
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any
additional terms or conditions.