From 5d53e7d6ebed82236de4e8659857e8e90bf7432e Mon Sep 17 00:00:00 2001 From: sawyer bristol Date: Fri, 16 Aug 2024 22:00:06 -0400 Subject: [PATCH] use Size form iced --- src/engines/mod.rs | 5 ++--- src/engines/ultralight.rs | 7 +++---- src/lib.rs | 21 --------------------- src/widgets/browser_view.rs | 18 ++++++++---------- src/widgets/browser_widgets.rs | 26 ++++++++++++++------------ 5 files changed, 27 insertions(+), 50 deletions(-) diff --git a/src/engines/mod.rs b/src/engines/mod.rs index db13edf..1a25a22 100644 --- a/src/engines/mod.rs +++ b/src/engines/mod.rs @@ -1,11 +1,10 @@ use iced::keyboard; use iced::mouse::{self, Interaction}; +use iced::Size; // use iced::widget::image::{Handle, Image}; use iced::Point; use url::Url; -use crate::ViewBounds; - #[cfg(feature = "webkit")] pub mod ultralight; @@ -29,7 +28,7 @@ pub trait BrowserEngine { fn need_render(&self) -> bool; fn render(&mut self); fn size(&self) -> (u32, u32); - fn resize(&mut self, size: ViewBounds); + fn resize(&mut self, size: Size); fn pixel_buffer(&mut self) -> (PixelFormat, Vec); fn get_cursor(&self) -> Interaction; diff --git a/src/engines/ultralight.rs b/src/engines/ultralight.rs index 3053a4a..861696c 100644 --- a/src/engines/ultralight.rs +++ b/src/engines/ultralight.rs @@ -1,6 +1,6 @@ use iced::keyboard::{self}; use iced::mouse::{self, ScrollDelta}; -use iced::Point; +use iced::{Point, Size}; use smol_str::SmolStr; use std::sync::{Arc, RwLock}; use ul_next::{ @@ -16,7 +16,6 @@ use ul_next::{ use url::Url; use super::{BrowserEngine, PixelFormat}; -use crate::ViewBounds; struct UlLogger; impl Logger for UlLogger { @@ -131,8 +130,8 @@ impl BrowserEngine for Ultralight { (self.width, self.height) } - fn resize(&mut self, size: ViewBounds) { - let (width, height) = (size.width, size.height); + fn resize(&mut self, size: Size) { + let (width, height) = (size.width as u32, size.height as u32); (self.width, self.height) = (width, height); self.tabs.iter().for_each(|tab| { tab.view.resize(width, height); diff --git a/src/lib.rs b/src/lib.rs index baab370..45496ef 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,27 +15,6 @@ pub use engines::ultralight::Ultralight; mod widgets; pub use widgets::{browser_widgets, nav_bar, tab_bar, BrowserView, BrowserWidget}; -#[derive(Debug, Clone, Copy)] -pub struct ViewBounds { - width: u32, - height: u32, -} - -impl Default for ViewBounds { - fn default() -> Self { - Self { - width: 800, - height: 800, - } - } -} - -impl ViewBounds { - pub fn new(width: u32, height: u32) -> Self { - Self { width, height } - } -} - // Image details for passing the view around #[derive(Debug, Clone)] pub struct ImageInfo { diff --git a/src/widgets/browser_view.rs b/src/widgets/browser_view.rs index 39b5692..c838609 100644 --- a/src/widgets/browser_view.rs +++ b/src/widgets/browser_view.rs @@ -10,12 +10,12 @@ use iced::event::Status; use iced::widget::image::{Handle, Image}; use iced::{theme::Theme, Element, Event, Length, Point, Rectangle, Size}; -use crate::{ImageInfo, ViewBounds}; +use crate::ImageInfo; pub struct BrowserView { - bounds: ViewBounds, + bounds: Size, image: Image, - send_bounds: Box Message>, + send_bounds: Box Message>, keyboard_event: Box Message>, mouse_event: Box Message>, } @@ -23,12 +23,12 @@ pub struct BrowserView { impl BrowserView { pub fn new( image: &ImageInfo, - send_bounds: Box Message>, + send_bounds: Box Message>, keyboard_event: Box Message>, mouse_event: Box Message>, ) -> Self { Self { - bounds: ViewBounds::default(), + bounds: Size::new(800., 800.), image: image.as_image(), send_bounds, keyboard_event, @@ -91,11 +91,9 @@ where viewport: &Rectangle, ) -> event::Status { // Send updates back if bounds change - if viewport.width as u32 != self.bounds.width - || viewport.height as u32 != self.bounds.height - { - self.bounds.width = viewport.width as u32; - self.bounds.height = viewport.height as u32; + if viewport.width != self.bounds.width || viewport.height != self.bounds.height { + self.bounds.width = viewport.width; + self.bounds.height = viewport.height; shell.publish((self.send_bounds)(self.bounds)); } diff --git a/src/widgets/browser_widgets.rs b/src/widgets/browser_widgets.rs index fc5c7e7..0fc7f19 100644 --- a/src/widgets/browser_widgets.rs +++ b/src/widgets/browser_widgets.rs @@ -1,10 +1,10 @@ -use iced::{keyboard, mouse, widget::column, Element, Point}; +use iced::{keyboard, mouse, widget::column, Element, Point, Size}; use url::Url; use super::{nav_bar, tab_bar, BrowserView}; use crate::{ engines::{BrowserEngine, PixelFormat}, - to_url, ImageInfo, ViewBounds, + to_url, ImageInfo, }; #[cfg(feature = "ultralight")] @@ -23,19 +23,19 @@ pub enum Message { UrlChanged(String), SendKeyboardEvent(keyboard::Event), SendMouseEvent(Point, mouse::Event), - UpdateBounds(ViewBounds), + UpdateBounds(Size), DoWork, } pub struct BrowserWidget { engine: Option, home: Url, + url: String, tab_bar: bool, nav_bar: bool, - url: String, browser_view: bool, image: ImageInfo, - view_bounds: ViewBounds, + view_bounds: Size, } impl Default for BrowserWidget { @@ -44,12 +44,12 @@ impl Default for BrowserWidget { Self { engine: None, home, + url: String::new(), tab_bar: false, nav_bar: false, - url: String::new(), browser_view: false, image: ImageInfo::default(), - view_bounds: ViewBounds::default(), + view_bounds: Size::new(800., 800.), } } } @@ -166,13 +166,15 @@ impl BrowserWidget { if self.engine().need_render() { let (format, image_data) = self.engine_mut().pixel_buffer(); self.image = match format { - PixelFormat::RGBA => { - ImageInfo::new(image_data, self.view_bounds.width, self.view_bounds.height) - } + PixelFormat::RGBA => ImageInfo::new( + image_data, + self.view_bounds.width as u32, + self.view_bounds.height as u32, + ), PixelFormat::BGRA => ImageInfo::new_from_bgr( image_data, - self.view_bounds.width, - self.view_bounds.height, + self.view_bounds.width as u32, + self.view_bounds.height as u32, ), } }