Skip to content

Commit

Permalink
chore(doc): Add documentation for WebView::inner_size (#1028)
Browse files Browse the repository at this point in the history
* chore(doc): Add documentation for `WebView::inner_size`

* fix(doc): Fix indent in code example of `WebViewBuilder::with_asynchronous_custom_protocol` document

* Update src/webview/mod.rs

* Update mod.rs

* Update src/webview/mod.rs

* Update src/webview/mod.rs

---------

Co-authored-by: Amr Bashir <amr.bashir2015@gmail.com>
  • Loading branch information
rhysd and amrbashir authored Sep 29, 2023
1 parent f9be83f commit d87ea78
Showing 1 changed file with 34 additions and 10 deletions.
44 changes: 34 additions & 10 deletions src/webview/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,17 +513,17 @@ impl<'a> WebViewBuilder<'a> {
/// let window = WindowBuilder::new()
/// .build(&event_loop)
/// .unwrap();
/// WebViewBuilder::new(window)
/// .unwrap()
/// .with_asynchronous_custom_protocol("wry".into(), |request, responder| {
/// // here you can use a tokio task, thread pool or anything
/// // to do heavy computation to resolve your request
/// // e.g. downloading files, opening the camera...
/// std::thread::spawn(move || {
/// std::thread::sleep(std::time::Duration::from_secs(2));
/// responder.respond(http::Response::builder().body(Vec::new()).unwrap());
/// });
/// WebViewBuilder::new(window)
/// .unwrap()
/// .with_asynchronous_custom_protocol("wry".into(), |request, responder| {
/// // here you can use a tokio task, thread pool or anything
/// // to do heavy computation to resolve your request
/// // e.g. downloading files, opening the camera...
/// std::thread::spawn(move || {
/// std::thread::sleep(std::time::Duration::from_secs(2));
/// responder.respond(http::Response::builder().body(Vec::new()).unwrap());
/// });
/// });
/// ```
#[cfg(feature = "protocol")]
pub fn with_asynchronous_custom_protocol<F>(mut self, name: String, handler: F) -> Self
Expand Down Expand Up @@ -1034,6 +1034,30 @@ impl WebView {
self.webview.is_devtools_open()
}

/// Gets the physical size of the webview’s client area. This is
/// a drop-in replacement for [`Window::inner_size`] because on some platforms
/// (currently, only macOS), it will return an incorrect size.
///
/// ```no_run
/// use wry::{
/// application::{
/// event_loop::EventLoop,
/// window::WindowBuilder
/// },
/// webview::WebViewBuilder,
/// };
/// let event_loop = EventLoop::new();
/// let window = WindowBuilder::new().build(&event_loop).unwrap();
/// let webview = WebViewBuilder::new(window)
/// .unwrap()
/// .build()
/// .unwrap();
///
/// // This returns incorrect window size on macOS.
/// println!("{:?}", webview.window().inner_size());
/// // Instead, this always returns the correct window size.
/// println!("{:?}", webview.inner_size());
/// ```
pub fn inner_size(&self) -> PhysicalSize<u32> {
#[cfg(target_os = "macos")]
{
Expand Down

0 comments on commit d87ea78

Please sign in to comment.