| Crates.io | web_ui |
| lib.rs | web_ui |
| version | 0.1.1 |
| created_at | 2025-07-25 23:38:26.097246+00 |
| updated_at | 2025-07-26 00:08:29.80004+00 |
| description | A simple Rust library for creating local web interfaces with real-time communication |
| homepage | https://github.com/williamwith4ms/web_ui |
| repository | https://github.com/williamwith4ms/web_ui |
| max_upload_size | |
| id | 1768557 |
| size | 128,849 |
A simple Rust library for creating local web interfaces with real-time communication.
Add this to your Cargo.toml:
[dependencies]
web_ui = "0.1"
tokio = { version = "1.0", features = ["full"] }
Ensure that the webui.js file is included in your static files directory
use web_ui::{WebUI, WebUIConfig};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = WebUIConfig::default();
let web_ui = WebUI::new(config);
// Bind a simple click handler
web_ui.bind_click("hello-btn", || {
println!("Hello, World!");
}).await;
println!("Starting web UI on http://localhost:3030");
web_ui.run().await
}
Create an index.html file in your static directory:
<!DOCTYPE html>
<html>
<head>
<title>My Web UI</title>
<script src="webui.js"></script>
</head>
<body>
<button id="hello-btn">Click Me!</button>
<script>
document.addEventListener('DOMContentLoaded', function() {
setTimeout(() => {
// register event handlers for buttons here
if (window.webui) {
window.webui.bindEvent('hello-btn', 'click', () => {
console.log('Hello button clicked!');
});
}
}, 100);
});
</script>
</body>
</html>
let config = WebUIConfig::default()
.with_port(8080) // Custom port
.with_title("My App".to_string()) // Window title
.with_static_dir("./assets".to_string()); // Static files directory
web_ui.bind_click("button-id", || {
println!("Button clicked!");
}).await;
web_ui.bind_event("input-btn", "click", |event| {
println!("Event data: {:?}", event.data);
Ok(UIResponse {
success: true,
message: Some("Operation completed".to_string()),
data: Some(serde_json::json!({ "result": "success" })),
request_id: event.request_id,
})
}).await;
This repository includes several examples:
hello - Basic button click exampleevent_binding - Event handling with state managementwelcome - Welcome page exampletemplate - Template for creating new projectsRun examples with:
cargo run --example hello
cargo run --example event_binding
...
static/
├── index.html # Your main HTML file
├── style.css # Optional CSS styles
├── app.js # Your custom JavaScript
└── webui.js # WebUI client library (needed to bind events)