Crate web_ui

Source
Expand description

§Web UI

A simple Rust library for creating local web interfaces with real-time communication.

This library provides a framework for building local web applications with event-driven architecture, supporting both WebSocket and HTTP-based communication between the frontend and backend.

§Features

  • Event-driven architecture with customizable handlers
  • WebSocket support for real-time communication
  • HTTP fallback for event handling
  • Static file serving
  • Simple configuration API

§Quick Start

use web_ui::{WebUI, WebUIConfig};

let config = WebUIConfig::default()
    .with_port(3030)
    .with_title("My Web App".to_string());

let webui = WebUI::new(config);

// Bind a click event handler
webui.bind_click("my-button", || {
    println!("Button clicked!");
}).await;

// webui.run().await // This would start the server

Ensure that the webui.js file is included in your static files directory

§Event System

The library uses an event-driven architecture where UI events from the frontend are dispatched to registered handlers on the backend. Events are identified by a combination of element ID and event type (e.g., “button1:click”).

Structs§

UIEvent
Represents a UI event sent from the frontend to the backend.
UIResponse
Represents a response sent from the backend to the frontend after processing an event.
WebUI
The main WebUI server instance.
WebUIConfig
Configuration for the WebUI server.

Type Aliases§

EventHandler
Type alias for event handler functions.
EventRegistry
Type alias for the event registry that maps event keys to handlers.