Crate gemgui

source ·
Expand description

UI Library

User interface

Use Rust for engine and HTML/CSS/… for UI and store them into an own folder in project.

The HTML file has to contain line:

<script type="text/javascript" src="gemgui.js"></script>

Resources

UI data files can be packed along the binary as resources. The packing is done in application’s build.rs file. See pack

Main

There are few ways to initiate main

  1. Use tokio
#[tokio::main]
async fn main() -> Result<()> { 
   let fm = gemgui::filemap_from(RESOURCES);
   let mut ui = Gui::new(fm, "hello.html", 12345)?;
   //...
   ui.run().await
}
  1. Use application
fn main() -> Result<()> { 
    let fm = gemgui::filemap_from(RESOURCES);
    gemgui::application(fm, "hello.html", 12345,
    |ui| async {my_app(ui).await})
}

async fn my_app(ui: UiRef) {
   //...     
} 
  1. window application

Window application uses Python webview, it to can be installed using Pip, see PyPi

fn main() -> Result<()> { 
    let fm = gemgui::filemap_from(RESOURCES);
    let file_menu = Menu::new().
    add_item("Exit", "do_exit");

    let about_menu = Menu::new().
    add_item("About", "do_about");  

    let menu = Menu::new().
    add_sub_menu("File", file_menu).
    add_sub_menu("About", about_menu);
    gemgui::window_application(fm, "hello.html", 12345,
    |ui| async {my_app(ui).await}, "My App", 500, 500, &[], 0, menu)
}

async fn my_app(ui: UiRef) {
   //...     
} 

Callbacks

For each callback (where applicable) there is both sync and async variants. Sync callbacks are executed in the UI thread and async callbacks are spawned in a tokio task. Sync callbacks are FnMut and async callbacks are FnOnce (despite the name, they can be called multiple times within certain limits not applied here).

shortly:

Async functions are more permissive and they can be used to call async functions, but synchronous functions are lighter.

Queries

A Query function is any function that requests information from the UI. Queries are async functions that return a Result. Since they are async functions, they has to be called in async contexts, see Callbacks. Furthermore a query can be done after (or in) on_start callback as the UI has to be ready to receive query requests. Premature query will lead to a panic error.

Examples

See Repository examples

Modules

Structs

  • Rectangle
  • Helper to move values to/from callback

Enums

Functions

Type Definitions