diff --git a/src/core/browser_window/c.rs b/src/core/browser_window/c.rs index efeb4b6..4f0c824 100644 --- a/src/core/browser_window/c.rs +++ b/src/core/browser_window/c.rs @@ -8,10 +8,7 @@ use super::{ super::{error::Error, window::WindowImpl}, *, }; -use crate::{ - def_browser_event, def_event, - rc::*, -}; +use crate::{def_browser_event, def_event, rc::*}; #[derive(Clone)] @@ -388,13 +385,12 @@ unsafe fn bool_converter(input: &c_int) -> bool { *input > 0 } unsafe fn f64_converter(input: &c_double) -> f64 { *input } unsafe fn str_converter(input: &cbw_CStrSlice) -> String { - let string = str::from_utf8_unchecked(slice::from_raw_parts(input.data as *const u8, input.len) as _); + let string = + str::from_utf8_unchecked(slice::from_raw_parts(input.data as *const u8, input.len) as _); string.to_string() } -unsafe fn message_args_converter( - input: &cbw_BrowserWindowMessageArgs, -) -> MessageEventArgs { +unsafe fn message_args_converter(input: &cbw_BrowserWindowMessageArgs) -> MessageEventArgs { // Convert the command and args to a String and `Vec<&str>` let cmd_string = str::from_utf8_unchecked(slice::from_raw_parts( input.cmd.data as *const u8, diff --git a/src/event.rs b/src/event.rs index c3adbca..0b8d0ad 100644 --- a/src/event.rs +++ b/src/event.rs @@ -1,37 +1,49 @@ //! This module contains all event related types. -//! -//! To register a callback to an event, the documentation may be a bit hard to -//! navigate. The [`BrowserWindow`](../browser/struct.BrowserWindow.html) handle +//! +//! To understand how events work in _BrowserWindow_, here is a short summary. +//! The [`BrowserWindow`](../browser/struct.BrowserWindow.html) handle //! contains a bunch of functions that return different event objects, and then //! the event object can be used to register the callback at. -//! -//! Each event object has the [`register`](trait.EventExt.html#tymethod.register) -//! method to register a closure to be executed on the occurence of the event. -//! +//! +//! Each event object has the +//! [`register`](trait.EventExt.html#tymethod.register) method to register a +//! closure to be executed on the occurence of the event. +//! //! ``` -//! use browser_window::browser::*; -//! use browser_window::prelude::*; -//! +//! use browser_window::{browser::*, prelude::*}; +//! //! fn example(bw: BrowserWindow) { -//! bw.on_message().register(|h: &BrowserWindowHandle, e: MessageEventArgs| { -//! // .. code here ... -//! }); +//! bw.on_message() +//! .register(|h: &BrowserWindowHandle, e: MessageEventArgs| { +//! // .. code here ... +//! }); //! } //! ``` -//! -//! There is also a [`register_async`](trait.EventExt.html#tymethod.register_async) +//! +//! There is also a +//! [`register_async`](trait.EventExt.html#tymethod.register_async) //! method, which can be useful in async code: -//! +//! //! ``` -//! use browser_window::browser::*; -//! use browser_window::prelude::*; -//! +//! use browser_window::{browser::*, prelude::*}; +//! //! fn async_example(bw: BrowserWindow) { -//! bw.on_message().register_async(|h: BrowserWindow, e: MessageEventArgs| async move { -//! // .. code here ... -//! }); +//! bw.on_message() +//! .register_async(|h: BrowserWindow, e: MessageEventArgs| async move { +//! // .. code here ... +//! }); //! } //! ``` +//! +//! Also, keep in mind that if the `register` or `register_async` methods are +//! not available, that means that event object does not implement `EventExt`, +//! which in turn means that the corresponding event is not supported for the +//! browser framework that has been selected. +//! +//! CEF supports all events, unless it is stated that it is not implemented yet. +//! The other browser frameworks only support a subset of what is supported for +//! CEF. The reason for this is that CEF is simply the most cross-platform +//! framework out there, so it gets the most care. use std::{boxed::Box, future::Future, pin::Pin}; diff --git a/src/lib.rs b/src/lib.rs index d256c84..5906d92 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -19,16 +19,17 @@ //! To use the threadsafe version of _BrowserWindow_, enable feature //! `threadsafe`. This will use [`Arc`](https://doc.rust-lang.org/std/sync/struct.Arc.html) //! instead of [`Rc`](https://doc.rust-lang.org/std/rc/struct.Rc.html) -//! internally, and will enable the [`BrowserWindowThreaded`](browser/struct.BrowserWindow.html) and +//! internally, and will enable the +//! [`BrowserWindowThreaded`](browser/struct.BrowserWindow.html) and //! [`ApplicationHandleThreaded`](browser/struct.BrowserWindowThreaded.html) //! handles. It will also require closures to be `Send`. Docs.rs will show the //! threadsafe versions of everything. If you need to know how everything is -//! compiled in the non-threadsafe version, you need to invoke `cargo doc --open` -//! in the git repo yourself. -//! +//! compiled in the non-threadsafe version, you need to invoke `cargo doc +//! --open` in the git repo yourself. +//! //! # Events -//! To learn how to use events, take a quick look at the [`event`](event/index.html) -//! module. +//! To learn how to use events, take a quick look at the +//! [`event`](event/index.html) module. mod core; #[cfg(test)]