diff --git a/Cargo.toml b/Cargo.toml index c9e5a50..2eaf700 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,13 @@ members = [ ] [dependencies] +bevy = { version = "0.9.0", features = [ + "bevy_winit", + "render", + "png", + "hdr", + "wayland", +] } crossbeam-channel = "0.5.1" headless_webview = { version = "0.1.1", path = "./crates/headless_webview", features = ["protocol"] } headless_webview_engine = { version = "0.1.1", path = "./crates/headless_webview_engine", optional = true } @@ -29,22 +36,6 @@ serde_json = "1.0" url = "2.2" mime_guess = "2.0.3" -[dependencies.bevy] -version = "0.7" -default-features = false -features = ["render"] - -[dev-dependencies.bevy] -version = "0.7" -default-features = false -features = [ - "bevy_winit", - "render", - "png", - "hdr", - "x11", -] - [dev-dependencies] rand = "0.8.4" diff --git a/examples/3d_scene.rs b/examples/3d_scene.rs index d3f6c5d..65a032b 100644 --- a/examples/3d_scene.rs +++ b/examples/3d_scene.rs @@ -17,20 +17,20 @@ fn setup( mut materials: ResMut>, ) { // plane - commands.spawn_bundle(PbrBundle { + commands.spawn(PbrBundle { mesh: meshes.add(Mesh::from(shape::Plane { size: 5.0 })), material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()), ..Default::default() }); // cube - commands.spawn_bundle(PbrBundle { + commands.spawn(PbrBundle { mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()), transform: Transform::from_xyz(0.0, 0.5, 0.0), ..Default::default() }); // light - commands.spawn_bundle(PointLightBundle { + commands.spawn(PointLightBundle { point_light: PointLight { intensity: 1500.0, shadows_enabled: true, @@ -40,15 +40,15 @@ fn setup( ..Default::default() }); // camera - commands.spawn_bundle(PerspectiveCameraBundle { + commands.spawn(Camera3dBundle { transform: Transform::from_xyz(-2.0, 2.5, 5.0) .looking_at(Vec3::new(0.0, 2.0, 0.0), Vec3::Y), ..Default::default() }); // webview - commands.spawn_bundle(WebviewBundle { + commands.spawn(WebviewBundle { webview: Webview { - uri: Some(String::from("https://bevyengine.org/")), + uri: Some(String::from("https://html5test.com/")), color: Color::rgba(0.3, 0.3, 0.3, 0.5), ..Default::default() }, diff --git a/src/events.rs b/src/events.rs index b1fa2ef..0b93a39 100644 --- a/src/events.rs +++ b/src/events.rs @@ -10,13 +10,13 @@ use serde::{Deserialize, Serialize}; use crate::{systems, PostUpdateLabel, PreUpdateLabel}; /// Mapping of RPC Input Event methods -#[derive(Default)] +#[derive(Default, Resource)] pub(crate) struct InputEventMapping { pub events: HashMap, } /// Mapping of RPC Output Event methods -#[derive(Default)] +#[derive(Default, Resource)] pub(crate) struct OutputEventMapping { pub events: HashMap, } @@ -204,7 +204,7 @@ impl WebviewApp for App { } /// Enum of builtin event methods -#[derive(Deserialize, Debug)] +#[derive(Deserialize, Debug, Resource)] #[serde(rename_all(deserialize = "lowercase"))] pub(crate) enum BuiltinWebviewEvent { Despawn, diff --git a/src/systems/ui_focus_system.rs b/src/systems/ui_focus_system.rs index ff3b375..a7da528 100644 --- a/src/systems/ui_focus_system.rs +++ b/src/systems/ui_focus_system.rs @@ -1,5 +1,5 @@ //! This module is based on bevy_ui, with added positions for Interaction -use bevy::{core::FloatOrd, input::ElementState, prelude::*, ui::FocusPolicy}; +use bevy::{utils::FloatOrd, input::ButtonState, prelude::*, ui::FocusPolicy}; use crate::{ types::{EventTransport, WebviewAction}, @@ -79,7 +79,7 @@ pub(crate) fn webview_ui_focus_system( .send(WebviewAction::Click(( entity, MouseButton::Left, - ElementState::Released, + ButtonState::Released, offset, // FIXME : currently using wrong offset ))) .unwrap(); @@ -99,9 +99,9 @@ pub(crate) fn webview_ui_focus_system( .iter_mut() .filter_map( |(entity, node, global_transform, interaction, focus_policy, clip)| { - let position = global_transform.translation; + let position = global_transform.translation(); let ui_position = position.truncate(); - let extents = node.size / 2.0; + let extents = node.size() / 2.0; let mut min = ui_position - extents; let mut max = ui_position + extents; if let Some(clip) = clip { @@ -154,7 +154,7 @@ pub(crate) fn webview_ui_focus_system( .send(WebviewAction::Click(( entity, MouseButton::Left, - ElementState::Pressed, + ButtonState::Pressed, offset, ))) .unwrap(); @@ -166,7 +166,7 @@ pub(crate) fn webview_ui_focus_system( .send(WebviewAction::Click(( entity, MouseButton::Right, - ElementState::Pressed, + ButtonState::Pressed, offset, ))) .unwrap(); diff --git a/src/systems/ui_size_system.rs b/src/systems/ui_size_system.rs index d79d35f..2060300 100644 --- a/src/systems/ui_size_system.rs +++ b/src/systems/ui_size_system.rs @@ -10,11 +10,11 @@ pub(crate) fn ui_size( resized_webviews: Query<(Entity, &Node, &Webview), Changed>, ) { for (entity, node, _webview) in resized_webviews.iter() { - log::debug!("Webview {:?} resized to {:?}", entity, node.size); + log::debug!("Webview {:?} resized to {:?}", entity, node.size()); event_transport .webview_action_tx - .send(WebviewAction::Resize((entity, node.size))) + .send(WebviewAction::Resize((entity, node.size()))) .unwrap(); } } diff --git a/src/systems/webview_create_system.rs b/src/systems/webview_create_system.rs index ee1b0bc..162593a 100644 --- a/src/systems/webview_create_system.rs +++ b/src/systems/webview_create_system.rs @@ -33,12 +33,12 @@ pub(crate) fn create_webview_system( { if let Some(node) = node { let window_size = - WindowSize::new(node.size.x.round() as u32, node.size.y.round() as u32); + WindowSize::new(node.size().x.round() as u32, node.size().y.round() as u32); log::debug!( "Webview {:?} (UI) added, window_size={:?}, texture_size_mb={:.2}", entity, - node.size, + node.size(), (window_size.width as usize * window_size.height as usize * 4) as f32 / 1024. / 1024. @@ -69,7 +69,7 @@ pub(crate) fn create_webview_system( TextureFormat::Rgba8Unorm, )), )) - .insert(UiColor(webview.color)); + .insert(BackgroundColor(webview.color)); } else if let Some(webview_size) = webview_size { log::debug!( "Webview {:?} (PBR) added, texture_size_mb={:.2}", @@ -99,7 +99,7 @@ pub(crate) fn create_webview_system( webview_size.y, )))); - commands.entity(entity).insert_bundle(PbrBundle { + commands.entity(entity).insert(PbrBundle { mesh: quad_handle.clone(), material: material_handle, transform: *transform, diff --git a/src/systems/webview_update_textures.rs b/src/systems/webview_update_textures.rs index 0274772..026038a 100644 --- a/src/systems/webview_update_textures.rs +++ b/src/systems/webview_update_textures.rs @@ -19,7 +19,7 @@ pub(crate) fn update_webview_textures( Option<&Handle>, Option<&Node>, Option<&mut UiImage>, - Option<&mut UiColor>, + Option<&mut BackgroundColor>, &mut WebviewState, ), With, diff --git a/src/types.rs b/src/types.rs index b3349e8..a827fa7 100644 --- a/src/types.rs +++ b/src/types.rs @@ -1,5 +1,5 @@ use bevy::{ - input::{keyboard::KeyboardInput, ElementState}, + input::{keyboard::KeyboardInput, ButtonState}, prelude::*, }; use crossbeam_channel::{Receiver, Sender}; @@ -16,7 +16,7 @@ pub(crate) enum WebviewAction { /// Mouse motion over webview MouseMotion((Entity, Vec2)), /// Webview was clicked - Click((Entity, MouseButton, ElementState, Vec2)), + Click((Entity, MouseButton, ButtonState, Vec2)), /// Webview was hovered Hover((Entity, Vec2)), /// Webview received keyboard input @@ -53,6 +53,7 @@ pub(crate) struct TextureReceivedEvent { } /// Takes care of event handling between webview impl and bevy system +#[derive(Resource)] pub(crate) struct EventTransport { pub webview_action_tx: Sender, pub texture_rx: Receiver, diff --git a/src/webview/runner_inner.rs b/src/webview/runner_inner.rs index ec084ba..3a7c3de 100644 --- a/src/webview/runner_inner.rs +++ b/src/webview/runner_inner.rs @@ -86,8 +86,8 @@ pub(crate) fn webview_runner_inner( bevy::prelude::MouseButton::Other(_) => continue, }, state: match element_state { - bevy::input::ElementState::Pressed => ElementState::Pressed, - bevy::input::ElementState::Released => ElementState::Released, + bevy::input::ButtonState::Pressed => ElementState::Pressed, + bevy::input::ButtonState::Released => ElementState::Released, }, // TODO: move position calc to the webview lib? @@ -108,8 +108,8 @@ pub(crate) fn webview_runner_inner( if let Some(w) = webviews.get(&entity) { w.webview.send_keyboard_input(KeyboardInput { state: match keyboard_input.state { - bevy::input::ElementState::Pressed => ElementState::Pressed, - bevy::input::ElementState::Released => ElementState::Released, + bevy::input::ButtonState::Pressed => ElementState::Pressed, + bevy::input::ButtonState::Released => ElementState::Released, }, }) }