Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 7 additions & 16 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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"

Expand Down
12 changes: 6 additions & 6 deletions examples/3d_scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ fn setup(
mut materials: ResMut<Assets<StandardMaterial>>,
) {
// 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,
Expand All @@ -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()
},
Expand Down
6 changes: 3 additions & 3 deletions src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TypeId, &'static str>,
}

/// Mapping of RPC Output Event methods
#[derive(Default)]
#[derive(Default, Resource)]
pub(crate) struct OutputEventMapping {
pub events: HashMap<TypeId, &'static str>,
}
Expand Down Expand Up @@ -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,
Expand Down
12 changes: 6 additions & 6 deletions src/systems/ui_focus_system.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand Down Expand Up @@ -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();
Expand All @@ -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 {
Expand Down Expand Up @@ -154,7 +154,7 @@ pub(crate) fn webview_ui_focus_system(
.send(WebviewAction::Click((
entity,
MouseButton::Left,
ElementState::Pressed,
ButtonState::Pressed,
offset,
)))
.unwrap();
Expand All @@ -166,7 +166,7 @@ pub(crate) fn webview_ui_focus_system(
.send(WebviewAction::Click((
entity,
MouseButton::Right,
ElementState::Pressed,
ButtonState::Pressed,
offset,
)))
.unwrap();
Expand Down
4 changes: 2 additions & 2 deletions src/systems/ui_size_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ pub(crate) fn ui_size(
resized_webviews: Query<(Entity, &Node, &Webview), Changed<Node>>,
) {
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();
}
}
8 changes: 4 additions & 4 deletions src/systems/webview_create_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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}",
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/systems/webview_update_textures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub(crate) fn update_webview_textures(
Option<&Handle<StandardMaterial>>,
Option<&Node>,
Option<&mut UiImage>,
Option<&mut UiColor>,
Option<&mut BackgroundColor>,
&mut WebviewState,
),
With<Webview>,
Expand Down
5 changes: 3 additions & 2 deletions src/types.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use bevy::{
input::{keyboard::KeyboardInput, ElementState},
input::{keyboard::KeyboardInput, ButtonState},
prelude::*,
};
use crossbeam_channel::{Receiver, Sender};
Expand All @@ -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
Expand Down Expand Up @@ -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<WebviewAction>,
pub texture_rx: Receiver<TextureReceivedEvent>,
Expand Down
8 changes: 4 additions & 4 deletions src/webview/runner_inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ pub(crate) fn webview_runner_inner<T: HeadlessWindow>(
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?
Expand All @@ -108,8 +108,8 @@ pub(crate) fn webview_runner_inner<T: HeadlessWindow>(
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,
},
})
}
Expand Down