Crates.io | div |
lib.rs | div |
version | 0.4.0 |
source | src |
created_at | 2020-10-14 00:56:09.871077 |
updated_at | 2023-07-09 18:44:49.803601 |
description | Ad hoc HTML for Rust Web Apps. |
homepage | |
repository | https://github.com/jakmeier/div-rs |
max_upload_size | |
id | 299434 |
size | 70,623 |
Ad hoc HTML for Rust.
This crate aims to provide a Rust API to easily create HTML div elements and manage their positions by pixel coordinates. This can be useful in combination with a frame-by-frame rendered canvas. The content of the div should be handled with different libraries.
The code base of the crate is rather small and is built on top of web-sys). The features can be summarized as:
DivHandle
which implements Copy
The examples in this crate are hosted online: div-rs Examples
Have a look at the code in example directory. The best way is to clone the repository and run it locally, so you can play around with the code.
You need npm, webpack, and wasm-pack for the examples to run on your machine.
git clone https://github.com/jakmeier/div-rs.git
cd div-rs/examples/www;
npm run build;
npm run start;
My motivation to create Div was to leverage HTML + CSS when using Rust to create games for a browser. Prior to this, the only way I knew how to do a GUI easily (in Rust running on the browser) was to render everything through general-purpose GUI crates with a WebGL backend. This seemed a bit wasteful to me, as the browser already has excellent built-in support for GUIs.
Instead of rendering fonts in WebGL and creating complex UI libraries in Rust, I wanted to use what the browser supports natively. This has two main advantages, in my opinion.