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§

element
Element
event
Event
graphics
Graphics
respack
Resource pack for build.rs
ui
Ui
ui_ref
Ui reference
window
Dialogs and furnitures

Structs§

Rect
Rectangle
Value
Helper to move values to/from callback

Enums§

GemGuiError
Error type

Functions§

application
Convenience to create an default UI application
default_error
Default error function
filemap_from
Read a filemap from applied resources
filemap_from_dir
Create a filemap from a directory content
next_free_port
Find a next free port
version
Current version
wait_free_port
Wait a port to be free
window_application
Convenience to create a windowed UI application

Type Aliases§

Filemap
Resource file map
Result
Result alias