Crate wry[][src]

Wry is a Cross-platform WebView rendering library.

There are two main ways to build WebView windows: Application and build by yourself.

Building WebView windows through Application

Application is the recommended way to build the WebView windows. It provides easy to use and unified APIs across all platforms. To get started, you simply create an Application first:

let application = Application::new()?;

Once you have your application instance, you can create the WebView window by calling Application::create_window. You can provide WebViewAttributes and Callback as arguments to configure the WebView window. If you don't have any preference, you could just set them with Default::default() and None.

    let attributes = WebViewAttributes {
        title: String::from("Wryyyyyyyyyyyyyyy"),
        // Initialization scripts can be used to define javascript functions and variables.
        initialization_script: vec![String::from("breads = NaN"), String::from("menacing = 'ゴ'")],
        ..Default::default()
    };
    // Callback defines a rust function to be called on javascript side later. Below is a function
    // which will print the list of parameters after 8th calls.
    let callback = Callback {
        name: String::from("world"),
        function: Box::new(|dispatcher, sequence, requests| {
            // Dispatcher is a channel sender for you to dispatch script to the javascript world
            // and evaluate it. This is useful when you want to perform any action in javascript.
            dispatcher
                .dispatch_script("console.log(menacing);")
                .unwrap();
            // Sequence is a number counting how many times this function being called.
            if sequence < 8 {
                println!("{} seconds has passed.", sequence);
            } else {
                // Requests is a vector of parameters passed from the caller.
                println!("{:?}", requests);
            }
            0
        }),
    };
    app.create_window(attributes, Some(vec![callback]))?;

Run the application with run in the end. This will consume the instance and run the application on current thread.

application.run();

Building WebView windows by yourself

If you want to control whole windows creation and events handling, you can use WebViewBuilder / WebView and platform module to build it all by yourself. platform module re-exports winit for you to build the window across all platforms except Linux. We still need Gtk's library to build the WebView, so it's gtk-rs on Linux.

Modules

platform

Structs

Application
Callback
Dispatcher
WebView
WebViewAttributes

Attributes to use when creating a webview window.

WebViewBuilder

Enums

Error

Type Definitions

Result