diff --git a/Cargo.toml b/Cargo.toml index c9e5a50..5cb37ec 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,20 +30,29 @@ url = "2.2" mime_guess = "2.0.3" [dependencies.bevy] -version = "0.7" +version = "0.12.0" default-features = false -features = ["render"] - +features = [ + "bevy_winit", + "png", + "hdr", + "x11", + "bevy_ui", + "bevy_render", + "bevy_pbr" + ] [dev-dependencies.bevy] -version = "0.7" +version = "0.12.0" default-features = false features = [ "bevy_winit", - "render", "png", "hdr", "x11", -] + "bevy_ui", + "bevy_render", + "bevy_pbr" + ] [dev-dependencies] rand = "0.8.4" diff --git a/crates/headless_webview_engine/examples/window.rs b/crates/headless_webview_engine/examples/window.rs index e015634..d5aeda1 100644 --- a/crates/headless_webview_engine/examples/window.rs +++ b/crates/headless_webview_engine/examples/window.rs @@ -5,7 +5,7 @@ use headless_webview::{ self, types::{self, WindowSize}, webview::Color, - WebviewBuilder, EngineWebview, + EngineWebview, WebviewBuilder, }; pub fn main() { diff --git a/examples/3d_scene.rs b/examples/3d_scene.rs index d3f6c5d..273f68d 100644 --- a/examples/3d_scene.rs +++ b/examples/3d_scene.rs @@ -3,11 +3,11 @@ use bevy_webview::prelude::*; fn main() { App::new() - .insert_resource(Msaa { samples: 4 }) + .insert_resource(Msaa::Sample4) .add_plugins(DefaultPlugins) - .add_plugin(WebviewPlugin::with_engine(webview_engine::headless)) - .add_startup_system(setup) - .add_system(rotator) + .add_plugins(WebviewPlugin::with_engine(webview_engine::headless)) + .add_systems(Startup, setup) + .add_systems(Update, rotator) .run(); } @@ -17,20 +17,23 @@ fn setup( mut materials: ResMut>, ) { // plane - commands.spawn_bundle(PbrBundle { - mesh: meshes.add(Mesh::from(shape::Plane { size: 5.0 })), + commands.spawn(PbrBundle { + mesh: meshes.add(Mesh::from(shape::Plane { + size: 5.0, + subdivisions: 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,13 +43,14 @@ 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), + tonemapping: bevy::core_pipeline::tonemapping::Tonemapping::SomewhatBoringDisplayTransform, ..Default::default() }); // webview - commands.spawn_bundle(WebviewBundle { + commands.spawn(WebviewBundle { webview: Webview { uri: Some(String::from("https://bevyengine.org/")), color: Color::rgba(0.3, 0.3, 0.3, 0.5), diff --git a/examples/change_detection.rs b/examples/change_detection.rs index ca65be9..372783a 100644 --- a/examples/change_detection.rs +++ b/examples/change_detection.rs @@ -6,22 +6,21 @@ use bevy_webview::prelude::*; fn main() { App::new() .add_plugins(DefaultPlugins) - .add_plugin(WebviewPlugin::with_engine(webview_engine::headless)) - .add_startup_system(setup) - .add_system(change_webview_system) + .add_plugins(WebviewPlugin::with_engine(webview_engine::headless)) + .add_systems(Startup, setup) + .add_systems(Update, change_webview_system) .run(); } fn setup(mut commands: Commands) { - commands.spawn_bundle(UiCameraBundle::default()); - + commands.spawn(Camera2dBundle::default()); commands.insert_resource(Elapsed { iteration: 0, - timer: Timer::new(Duration::from_millis(2000), true), + timer: Timer::new(Duration::from_millis(2000), TimerMode::Repeating), }); } -#[derive(Component, Debug)] +#[derive(Resource, Component, Debug)] struct Elapsed { iteration: usize, timer: Timer, @@ -36,19 +35,22 @@ fn change_webview_system( if elapsed.timer.tick(time.delta()).just_finished() { if elapsed.iteration == 0 { // at first tick, spawn the webview - commands.spawn_bundle(WebviewUIBundle { + commands.spawn(WebviewUIBundle { webview: Webview { uri: Some("https://bevyengine.org/".into()), - ..Default::default() + ..default() }, style: Style { - size: Size::new(Val::Percent(50.0), Val::Percent(50.)), - margin: Rect::all(Val::Auto), + width: Val::Percent(100.), + height: Val::Percent(100.), justify_content: JustifyContent::Center, align_items: AlignItems::Center, - ..Default::default() + ..default() }, - ..Default::default() + visibility: Visibility::Inherited, + inherited_visibility: InheritedVisibility::default(), + view_visibility: ViewVisibility::default(), + ..default() }); elapsed.iteration += 1; diff --git a/examples/commands.rs b/examples/commands.rs index c187e63..a2160d9 100644 --- a/examples/commands.rs +++ b/examples/commands.rs @@ -6,37 +6,39 @@ use bevy_webview::prelude::*; fn main() { App::new() .add_plugins(DefaultPlugins) - .add_plugin(WebviewPlugin::with_engine(webview_engine::headless)) - .add_startup_system(setup) - .add_system(send_commands_system) + .add_plugins(WebviewPlugin::with_engine(webview_engine::headless)) + .add_systems(Startup, setup) + .add_systems(Update, send_commands_system) .run(); } fn setup(mut commands: Commands) { - commands.spawn_bundle(UiCameraBundle::default()); + commands.spawn(Camera2dBundle::default()); - commands.spawn_bundle(WebviewUIBundle { + commands.spawn(WebviewUIBundle { webview: Webview { uri: Some("https://bevyengine.org/".into()), ..Default::default() }, style: Style { - size: Size::new(Val::Percent(50.0), Val::Percent(50.)), - margin: Rect::all(Val::Auto), + width: Val::Percent(50.), + height: Val::Percent(50.), + // margin: Rect::all(Val::Auto), justify_content: JustifyContent::Center, align_items: AlignItems::Center, ..Default::default() }, + visibility: Visibility::Inherited, ..Default::default() }); commands.insert_resource(Elapsed { iteration: 0, - timer: Timer::new(Duration::from_millis(2000), true), + timer: Timer::new(Duration::from_millis(2000), TimerMode::Repeating), }); } -#[derive(Component)] +#[derive(Component, Resource)] struct Elapsed { iteration: usize, timer: Timer, diff --git a/examples/events.rs b/examples/events.rs index 9879658..d4b1b1b 100644 --- a/examples/events.rs +++ b/examples/events.rs @@ -7,14 +7,14 @@ use serde::{Deserialize, Serialize}; fn main() { App::new() .add_plugins(DefaultPlugins) - .add_plugin(WebviewPlugin::with_engine(webview_engine::headless)) + .add_plugins(WebviewPlugin::with_engine(webview_engine::headless)) .add_webview_input_event::("login") .add_webview_input_event::("close") .add_webview_output_event::("app_time") - .add_startup_system(setup) - .add_system(login_handler) - .add_system(send_time_to_all_webviews_system) - .add_system(close_handler) + .add_systems(Startup, setup) + .add_systems(Update, login_handler) + .add_systems(Update, send_time_to_all_webviews_system) + .add_systems(Update, close_handler) .run(); } @@ -22,35 +22,39 @@ fn main() { struct TimeReceiver; fn setup(mut commands: Commands) { - commands.spawn_bundle(UiCameraBundle::default()); + commands.spawn(Camera2dBundle::default()); commands - .spawn_bundle(WebviewUIBundle { + .spawn(WebviewUIBundle { webview: Webview { html: Some(include_str!("events.html").into()), color: Color::rgb_u8(58, 58, 58), ..Default::default() }, style: Style { - size: Size::new(Val::Percent(50.0), Val::Percent(50.)), - margin: Rect::all(Val::Auto), + width: Val::Percent(50.), + height: Val::Percent(50.), justify_content: JustifyContent::Center, align_items: AlignItems::Center, ..Default::default() }, + visibility: Visibility::Inherited, ..Default::default() }) .insert(TimeReceiver); - commands.insert_resource(TimeTick(Timer::new(Duration::from_millis(1_000), true))); + commands.insert_resource(TimeTick(Timer::new( + Duration::from_millis(1_000), + TimerMode::Repeating, + ))); } -#[derive(Deserialize, Debug)] +#[derive(Deserialize, Debug, Resource)] pub struct LoginRequest { username: String, } -#[derive(Serialize, Debug)] +#[derive(Serialize, Debug, Resource)] pub struct AppTime { seconds_since_startup: f64, } @@ -70,7 +74,7 @@ fn login_handler(mut login_request_events: WebviewEventReader) { } } -#[derive(Deserialize, Debug)] +#[derive(Deserialize, Debug, Resource)] pub struct CloseRequest; fn close_handler( @@ -85,7 +89,7 @@ fn close_handler( commands.entity(entity).despawn_recursive(); } } - +#[derive(Resource)] struct TimeTick(Timer); fn send_time_to_all_webviews_system( @@ -95,7 +99,7 @@ fn send_time_to_all_webviews_system( ) { if tick.0.tick(time.delta()).just_finished() { app_time.send(AppTime { - seconds_since_startup: time.seconds_since_startup(), + seconds_since_startup: time.elapsed_seconds_f64(), }); } } diff --git a/examples/local_assets.rs b/examples/local_assets.rs index a8c7b8c..29da215 100644 --- a/examples/local_assets.rs +++ b/examples/local_assets.rs @@ -4,54 +4,60 @@ use bevy_webview::prelude::*; fn main() { App::new() .add_plugins(DefaultPlugins) - .add_plugin(WebviewPlugin::new().register_engine(webview_engine::headless)) - .add_startup_system(setup) - .add_system(reload_system) + .add_plugins(WebviewPlugin::new().register_engine(webview_engine::headless)) + .add_systems(Startup, setup) + .add_systems(Update, reload_system) .run(); } fn setup(mut commands: Commands, asset_server: Res) { - commands.spawn_bundle(UiCameraBundle::default()); + commands.spawn(Camera2dBundle::default()); // webview - commands.spawn_bundle(WebviewUIBundle { + commands.spawn(WebviewUIBundle { webview: Webview { uri: Some(String::from("webview:///test_webview.html")), ..Default::default() }, style: Style { - size: Size::new(Val::Percent(80.0), Val::Percent(80.)), - margin: Rect::all(Val::Auto), + width: Val::Percent(80.0), + height: Val::Percent(80.), justify_content: JustifyContent::Center, align_items: AlignItems::Center, ..Default::default() }, + visibility: Visibility::Inherited, ..Default::default() }); // reload button commands - .spawn_bundle(ButtonBundle { + .spawn(ButtonBundle { style: Style { - size: Size::new(Val::Px(150.0), Val::Px(65.0)), - margin: Rect::all(Val::Auto), + width: Val::Px(150.0), + height: Val::Px(65.0), + border: UiRect::all(Val::Px(5.0)), justify_content: JustifyContent::Center, align_items: AlignItems::Center, - ..Default::default() + position_type: PositionType::Absolute, + right: Val::Percent(10.), + bottom: Val::Percent(10.), + ..default() }, - color: NORMAL_BUTTON.into(), - ..Default::default() + border_color: BorderColor(Color::BLACK), + background_color: NORMAL_BUTTON.into(), + ..default() }) .with_children(|parent| { - parent.spawn_bundle(TextBundle { - text: Text::with_section( + parent.spawn(TextBundle { + text: Text::from_section( "Reload", TextStyle { font: asset_server.load("fonts/FiraSans-Bold.ttf"), font_size: 40.0, color: Color::rgb(0.9, 0.9, 0.9), + ..Default::default() }, - Default::default(), ), ..Default::default() }); @@ -64,7 +70,7 @@ const PRESSED_BUTTON: Color = Color::rgb(0.35, 0.75, 0.35); fn reload_system( mut interaction_query: Query< - (&Interaction, &mut UiColor), + (&Interaction, &mut BackgroundColor), (Changed, With