[][src]Struct alcro::UI

pub struct UI { /* fields omitted */ }

The browser window

Implementations

impl UI[src]

pub fn done(&self) -> bool[src]

Returns true if the browser is closed

pub fn wait_finish(&self)[src]

Wait for the browser to be closed

pub fn close(&self)[src]

Close the browser window

pub fn load(&self, content: Content) -> JSResult[src]

Load content in the browser. It returns Err if it fails.

pub fn bind<F>(&self, name: &str, f: F) -> JSResult where
    F: Fn(&[JSObject]) -> JSResult + Sync + Send + 'static, 
[src]

Bind a rust function so that JS code can use it. It returns Err if it fails.

Arguments

  • name - Name of the function
  • f - The function. It should take a list of JSObject as argument and return a JSResult

Examples

#![windows_subsystem = "windows"]
use alcro::UIBuilder;
use serde_json::to_value;

let ui = UIBuilder::new().custom_args(&["--headless"]).run();
ui.bind("add", |args| {
    let mut sum = 0;
    for arg in args {
        if arg.is_i64() {
            sum += arg.as_i64().unwrap();
        } else {
            return Err(to_value("Not a number").unwrap());
        }
    }
    Ok(to_value(sum).unwrap())
}).unwrap();
assert_eq!(ui.eval("(async () => await add(1,2,3))();").unwrap(), 6);
assert!(ui.eval("(async () => await add(1,2,'hi'))();").is_err());

pub fn eval(&self, js: &str) -> JSResult[src]

Evaluates js code and returns the result.

Examples

#![windows_subsystem = "windows"]
use alcro::UIBuilder;
let ui = UIBuilder::new().custom_args(&["--headless"]).run();
assert_eq!(ui.eval("1+1").unwrap(), 2);
assert_eq!(ui.eval("'Hello'+' World'").unwrap(), "Hello World");
assert!(ui.eval("xfgch").is_err());

pub fn set_bounds(&self, b: Bounds) -> JSResult[src]

It changes the size, position or state of the browser window specified by the Bounds struct. It returns Err if it fails.

To change the window state alone use WindowState::to_bounds()

pub fn bounds(&self) -> Result<Bounds, JSObject>[src]

It gets the size, position and state of the browser window. It returns Err if it fails.

Trait Implementations

impl Drop for UI[src]

Closes the browser window

Auto Trait Implementations

impl RefUnwindSafe for UI

impl Send for UI

impl Sync for UI

impl Unpin for UI

impl UnwindSafe for UI

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.