Struct Window

Source
pub struct Window { /* private fields */ }
Expand description

A window, which may or may not be open.

Implementations§

Source§

impl Window

Source

pub fn new(opts: Options) -> Self

Make a new window with the given options.

Source

pub fn with_handler(handler: impl Handler) -> Self

Make a new window with the default options and the given handler.

Examples found in repository?
examples/hello.rs (line 16)
15fn start() {
16    let window = Window::with_handler(Handler(0));
17    window.title("Hello, world!");
18    window.load(HTML);
19}
More examples
Hide additional examples
examples/tick.rs (line 23)
22fn start() {
23    let window = Window::with_handler(Handler);
24    window.title("Hello, world!");
25    window.load(HTML);
26
27    WINDOW.with(|w| {
28        *w.borrow_mut() = Some(window);
29    });
30
31    thread::spawn(ticker);
32}
Source

pub fn eval<I: Into<String>>(&self, s: I)

Evaluate the given JavaScript asynchronously.

Examples found in repository?
examples/hello.rs (lines 28-33)
24    fn handle(&mut self, window: Window, msg: &str) {
25        println!("{}", msg);
26
27        self.0 += 1;
28        window.eval(format!(
29            "
30                document.getElementById('click-count').textContent = {};
31            ",
32            self.0,
33        ));
34    }
More examples
Hide additional examples
examples/tick.rs (lines 42-46)
34fn ticker() {
35    for i in 0.. {
36        tether::dispatch(|| {
37            WINDOW.with(|window| {
38                window
39                    .borrow()
40                    .as_ref()
41                    .unwrap()
42                    .eval(format!(
43                        "document.body.textContent = '{} ({})';",
44                        if i % 2 == 1 { "Tick" } else { "Tock" },
45                        i,
46                    ));
47            });
48        });
49
50        thread::sleep(Duration::from_secs(1));
51    }
52}
Source

pub fn load<I: Into<String>>(&self, s: I)

Load the given HTML asynchronously.

Examples found in repository?
examples/hello.rs (line 18)
15fn start() {
16    let window = Window::with_handler(Handler(0));
17    window.title("Hello, world!");
18    window.load(HTML);
19}
More examples
Hide additional examples
examples/tick.rs (line 25)
22fn start() {
23    let window = Window::with_handler(Handler);
24    window.title("Hello, world!");
25    window.load(HTML);
26
27    WINDOW.with(|w| {
28        *w.borrow_mut() = Some(window);
29    });
30
31    thread::spawn(ticker);
32}
Source

pub fn title<I: Into<String>>(&self, s: I)

Set this window’s title to the given string.

Examples found in repository?
examples/hello.rs (line 17)
15fn start() {
16    let window = Window::with_handler(Handler(0));
17    window.title("Hello, world!");
18    window.load(HTML);
19}
More examples
Hide additional examples
examples/tick.rs (line 24)
22fn start() {
23    let window = Window::with_handler(Handler);
24    window.title("Hello, world!");
25    window.load(HTML);
26
27    WINDOW.with(|w| {
28        *w.borrow_mut() = Some(window);
29    });
30
31    thread::spawn(ticker);
32}
Source

pub fn focus(&self)

Focus this window above the other windows.

Source

pub fn close(&self)

Close this window.

Trait Implementations§

Source§

impl Clone for Window

Source§

fn clone(&self) -> Window

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for Window

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Window

§

impl !RefUnwindSafe for Window

§

impl !Send for Window

§

impl !Sync for Window

§

impl Unpin for Window

§

impl !UnwindSafe for Window

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.