Skip to content

Commit

Permalink
Updated docs & cargo fmt.
Browse files Browse the repository at this point in the history
  • Loading branch information
bamidev committed Mar 9, 2024
1 parent 544930c commit 748a566
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 36 deletions.
12 changes: 4 additions & 8 deletions src/core/browser_window/c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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,
Expand Down
56 changes: 34 additions & 22 deletions src/event.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down
13 changes: 7 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down

0 comments on commit 748a566

Please sign in to comment.