1use iced::widget::image;
27
28pub mod engines;
30pub use engines::{Engine, PageType, PixelFormat, ViewId};
31
32mod webview;
33pub use basic::{Action, WebView};
34pub use webview::{advanced, basic};
35
36#[cfg(feature = "blitz")]
37pub use engines::blitz::Blitz;
38
39#[cfg(feature = "litehtml")]
40pub use engines::litehtml::Litehtml;
41
42pub(crate) mod util;
43
44#[cfg(any(feature = "litehtml", feature = "blitz"))]
45pub(crate) mod fetch;
46
47#[derive(Clone, Debug)]
49pub struct ImageInfo {
50 width: u32,
51 height: u32,
52 handle: image::Handle,
53}
54
55impl Default for ImageInfo {
56 fn default() -> Self {
57 let pixels = vec![255; (Self::WIDTH as usize * Self::HEIGHT as usize) * 4];
58 Self {
59 width: Self::WIDTH,
60 height: Self::HEIGHT,
61 handle: image::Handle::from_rgba(Self::WIDTH, Self::HEIGHT, pixels),
62 }
63 }
64}
65
66impl ImageInfo {
67 const WIDTH: u32 = 800;
69 const HEIGHT: u32 = 800;
70
71 fn new(mut pixels: Vec<u8>, format: PixelFormat, width: u32, height: u32) -> Self {
72 assert_eq!(pixels.len() % 4, 0);
74
75 if let PixelFormat::Bgra = format {
76 pixels.chunks_mut(4).for_each(|chunk| chunk.swap(0, 2));
77 }
78
79 Self {
80 width,
81 height,
82 handle: image::Handle::from_rgba(width, height, pixels),
83 }
84 }
85
86 pub fn as_handle(&self) -> image::Handle {
88 self.handle.clone()
89 }
90
91 pub fn image_width(&self) -> u32 {
93 self.width
94 }
95
96 pub fn image_height(&self) -> u32 {
98 self.height
99 }
100
101 fn blank(width: u32, height: u32) -> Self {
102 let pixels = vec![255; (width as usize * height as usize) * 4];
103 Self {
104 width,
105 height,
106 handle: image::Handle::from_rgba(width, height, pixels),
107 }
108 }
109}