Crate zng_view

source ·
Expand description

This crate is part of the zng project.

View-Process implementation using glutin.

This backend supports headed and headless apps.

§Usage

First add this to your Cargo.toml:

[dependencies]
zng = "0.2.3"
zng-view = "0.2.2"

Then call init before any other code in main to setup a view-process that uses the same app executable:

use zng::prelude::*;

fn main() {
    zng_view::init();

    APP.defaults().run_window(|ctx| {
        unimplemented!()
    })
}

When the app is executed init setup its startup and returns, run_window gets called and internally starts the view-process, using the init setup. The current executable is started again, this time configured to be a view-process, init detects this and highjacks the process never returning.

§Software Backend

The webrender/swgl software renderer can be used as fallback when no native OpenGL 3.2 driver is available, to build it the feature "software" must be enabled (it is by default) and on Windows MSVC the clang-cl dependency must be installed and associated with the CC and CXX environment variables, if requirements are not met a warning is emitted and the build fails.

To install dependencies on Windows:

setx PATH %PATH%;C:\Program Files\LLVM\bin
  • Associate CC and CXX with clang-cl:
setx CC clang-cl
setx CXX clang-cl

Note that you may need to reopen the terminal for the environment variables to be available (setx always requires this).

§Pre-built

There is a pre-built release of this crate, zng-view-prebuilt, it works as a drop-in replacement

In the Cargo.toml file:

zng-view-prebuilt = "0.1"

Then in the main.rs file:

use zng_view_prebuilt as zng_view;

fn main() {
    zng_view::init();
     
    // APP.defaults().run ..
}

The pre-built crate includes the "software" and "ipc" features, in fact ipc is required, even for running on the same process, you can also configure where the pre-build library is installed, see the zng-view-prebuilt documentation for details.

The pre-build crate does not support extensions.

§API Extensions

This implementation of the view API provides one extension:

  • "zng-view.webrender_debug": { flags: DebugFlags, profiler_ui: String }, sets Webrender debug flags.
    • The zng-wgt-webrender-debug implements a property that uses this extension.

You can also inject your own extensions, see the extensions module for more details.

Modules§

  • Extensions API
  • OpenGL bindings used by Webrender.
  • Webrender build used in the view-process. A GPU based renderer for the web.

Functions§

  • Runs the view-process server if called in the environment of a view-process.
  • Like init but with custom API extensions.
  • Runs the view-process server in the current process and calls run_app to also run the app in the current process. Note that run_app will be called in a different thread.
  • Like run_same_process but with custom API extensions.