diff --git a/Cargo.lock b/Cargo.lock index d9fefe4..4116844 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -556,9 +556,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.1.28" +version = "1.1.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e80e3b6a3ab07840e1cae9b0666a63970dc28e8ed5ffbcdacbfc760c281bfc1" +checksum = "58e804ac3194a48bb129643eb1d62fcc20d18c6b8c181704489353d13120bcd1" dependencies = [ "jobserver", "libc", @@ -1888,7 +1888,7 @@ dependencies = [ [[package]] name = "iced_event_wrapper" version = "0.1.0" -source = "git+https://github.com/LegitCamper/iced_event_wrapper#94095398d91e7b5e8016f72bb6d60dd57228ffbe" +source = "git+https://github.com/LegitCamper/iced_event_wrapper#22151db0c8c9d7aeee655278613b19a6dcec9714" dependencies = [ "iced", ] @@ -2252,9 +2252,9 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.71" +version = "0.3.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0cb94a0ffd3f3ee755c20f7d8752f45cac88605a4dcf808abcff72873296ec7b" +checksum = "6a88f1bda2bd75b0452a14784937d796722fdebfe50df998aeb3f0b7603019a9" dependencies = [ "wasm-bindgen", ] @@ -4831,9 +4831,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.94" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef073ced962d62984fb38a36e5fdc1a2b23c9e0e1fa0689bb97afa4202ef6887" +checksum = "128d1e363af62632b8eb57219c8fd7877144af57558fb2ef0368d0087bddeb2e" dependencies = [ "cfg-if", "once_cell", @@ -4842,9 +4842,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.94" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4bfab14ef75323f4eb75fa52ee0a3fb59611977fd3240da19b2cf36ff85030e" +checksum = "cb6dd4d3ca0ddffd1dd1c9c04f94b868c37ff5fac97c30b97cff2d74fce3a358" dependencies = [ "bumpalo", "log", @@ -4857,9 +4857,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.44" +version = "0.4.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65471f79c1022ffa5291d33520cbbb53b7687b01c2f8e83b57d102eed7ed479d" +checksum = "cc7ec4f8827a71586374db3e87abdb5a2bb3a15afed140221307c3ec06b1f63b" dependencies = [ "cfg-if", "js-sys", @@ -4869,9 +4869,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.94" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7bec9830f60924d9ceb3ef99d55c155be8afa76954edffbb5936ff4509474e7" +checksum = "e79384be7f8f5a9dd5d7167216f022090cf1f9ec128e6e6a482a2cb5c5422c56" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -4879,9 +4879,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.94" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c74f6e152a76a2ad448e223b0fc0b6b5747649c3d769cc6bf45737bf97d0ed6" +checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68" dependencies = [ "proc-macro2", "quote", @@ -4892,9 +4892,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.94" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a42f6c679374623f295a8623adfe63d9284091245c3504bde47c17a3ce2777d9" +checksum = "65fc09f10666a9f147042251e0dda9c18f166ff7de300607007e96bdebc1068d" [[package]] name = "wasm-timer" @@ -5022,9 +5022,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.71" +version = "0.3.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44188d185b5bdcae1052d08bcbcf9091a5524038d4572cc4f4f2bb9d5554ddd9" +checksum = "f6488b90108c040df0fe62fa815cbdee25124641df01814dd7282749234c6112" dependencies = [ "js-sys", "wasm-bindgen", diff --git a/src/widgets/browser_view.rs b/src/widgets/browser_view.rs index ac11234..a853bd5 100644 --- a/src/widgets/browser_view.rs +++ b/src/widgets/browser_view.rs @@ -1,121 +1,16 @@ -use iced::advanced::{ - self, - graphics::core::event, - layout, mouse, - renderer::{self}, - widget::Tree, - Clipboard, Layout, Shell, Widget, -}; -use iced::event::Status; -use iced::widget::image::{Handle, Image}; -use iced::{theme::Theme, Element, Event, Length, Rectangle, Size}; +use iced::{Element, Size}; +use iced_event_wrapper::wrapper; use super::Message; use crate::ImageInfo; -pub fn browser_view(bounds: Size, image: &ImageInfo, can_type: bool) -> BrowserView { - BrowserView::new(bounds, image, can_type) -} - -pub struct BrowserView { - bounds: Size, - image: Image, - can_interact: bool, // wheather or not to allow typing - useful when overlay enabled -} - -impl BrowserView { - pub fn new(bounds: Size, image: &ImageInfo, can_type: bool) -> Self { - Self { - bounds, - image: image.as_image(), - can_interact: can_type, - } - } -} - -impl Widget for BrowserView -where - Renderer: iced::advanced::image::Renderer, -{ - fn size(&self) -> Size { - Size { - width: Length::Fill, - height: Length::Fill, - } - } - - fn layout( - &self, - _tree: &mut Tree, - _renderer: &Renderer, - limits: &layout::Limits, - ) -> layout::Node { - layout::Node::new(limits.max()) - } - - fn draw( - &self, - tree: &Tree, - renderer: &mut Renderer, - theme: &Theme, - style: &renderer::Style, - layout: Layout<'_>, - cursor: mouse::Cursor, - viewport: &Rectangle, - ) { - as Widget>::draw( - &self.image, - tree, - renderer, - theme, - style, - layout, - cursor, - viewport, - ) - } - - fn on_event( - &mut self, - _state: &mut Tree, - event: Event, - layout: Layout<'_>, - cursor: mouse::Cursor, - _renderer: &Renderer, - _clipboard: &mut dyn Clipboard, - shell: &mut Shell<'_, Message>, - _viewport: &Rectangle, - ) -> event::Status { - if self.can_interact { - // Send updates back if bounds change - // convert to u32 because Image takes u32 - let size = Size::new(layout.bounds().width as u32, layout.bounds().height as u32); - if self.bounds != size { - shell.publish(Message::UpdateViewSize(size)); - } - - match event { - Event::Keyboard(event) => { - shell.publish(Message::SendKeyboardEvent(Some(event))); - } - Event::Mouse(event) => { - if let Some(point) = cursor.position_in(layout.bounds()) { - shell.publish(Message::SendMouseEvent(point, Some(event))); - } - } - _ => (), - } - } - Status::Ignored - } -} - -impl<'a, Message: 'a, Renderer> From for Element<'a, Message, Theme, Renderer> -where - Renderer: advanced::Renderer + advanced::image::Renderer, - BrowserView: Widget, -{ - fn from(widget: BrowserView) -> Self { - Self::new(widget) - } +pub fn browser_view(image: &ImageInfo) -> Element { + wrapper(image.as_image()) + .always_ignore_events() + .on_keyboard_event(|event| Message::SendKeyboardEvent(Some(event))) + .on_mouse_event(|event, point| Message::SendMouseEvent(point, Some(event))) + .on_bounds_change(|bounds: Size| { + Message::UpdateViewSize(Size::new(bounds.width as u32, bounds.height as u32)) + }) + .into() } diff --git a/src/widgets/mod.rs b/src/widgets/mod.rs index 07fe52f..40ef06f 100644 --- a/src/widgets/mod.rs +++ b/src/widgets/mod.rs @@ -510,11 +510,7 @@ impl IcyBrowser { column = column.push(bookmark_bar(bookmarks)) } - let browser_view = browser_view( - self.view_size, - self.engine.get_tabs().get_current().get_view(), - !self.show_overlay, - ); + let browser_view = browser_view(self.engine.get_tabs().get_current().get_view()); if self.show_overlay { column = column.push(command_palatte(browser_view, &self.command_window_state)) } else {