Crates.io | bevy_flurx_wry |
lib.rs | bevy_flurx_wry |
version | 0.1.0-alpha1 |
source | src |
created_at | 2024-06-02 14:37:31.13588 |
updated_at | 2024-06-02 14:37:31.13588 |
description | Provides a mechanism to create a webview based on wry |
homepage | |
repository | https://github.com/not-elm/bevy_flurx_wry |
max_upload_size | |
id | 1259245 |
size | 879,375 |
[!CAUTION] This crate is in the early stages of development and is subject to disruptive changes.
The purpose of this crate is integrate bevy and wry using bevy_flurx.
In addition to that, I would like to take advantage of bevy's extensibility and discover bevy's potential to transcend the framework of existing game engines.
The operation has been confirmed on Windows
and MacOS
.
Ubuntu
is currently not supported.
There are two ways to create a webview:
use bevy::prelude::*;
use bevy::window::PrimaryWindow;
use bevy_flurx_wry::prelude::*;
fn spawn_webview(
mut commands: Commands,
window: Query<Entity, With<PrimaryWindow>>,
) {
// Converts the `Window` attached the entity into a webview window.
commands.entity(window.single()).insert(
WryWebViewBundle {
uri: WebviewUri::new("https://bevyengine.org/"),
..default()
}
);
}
use bevy::prelude::*;
use bevy::window::PrimaryWindow;
use bevy_flurx_wry::prelude::*;
fn spawn_webview(
mut commands: Commands,
window: Query<Entity, With<PrimaryWindow>>,
) {
commands.spawn((
WryWebViewBundle {
..default()
},
AsChildBundle {
// Here, create a webview as child inside a given window.
parent: ParentWindow(window.single()),
bounds: Bounds {
position: Vec2::new(100., 100.),
size: Vec2::new(500., 500.),
min_size: Vec2::new(100., 100.),
},
..default()
},
));
}
You can listen events from the webview and, conversely, emit events to the webview.
javascript
// you can use any type.
const event = {
message: "message"
};
window.__FLURX__.emit("event_id", event);
rust
use bevy::prelude::*;
use bevy_flurx_wry::prelude::*;
use serde::Deserialize;
#[derive(Deserialize, Debug)]
struct MessageFromWebview {
message: String,
}
fn read_webview_message(
mut er: EventReader<IpcEvent<MessageFromWebview>>
) {
for e in er.read() {
println!("webview message: {}", e.payload.message);
}
}
javascript
window.__FLURX__.listen("event_id", ({message}) => {
console.log(message);
});
rust
use bevy::prelude::*;
use bevy_flurx_wry::prelude::*;
use serde_json::json;
fn emit_event(
mut views: Query<&mut EventEmitter>
) {
for mut emitter in views.iter_mut() {
emitter.emit("event_id", &serde_json::json!({
"message" : "hello world!"
}));
}
}
IpcEvent
can't receive the output value from the other side.
In this case, IpcCommand
can be used.
IpcComamnd
can be divided into two command patterns: action-command, task-command
Please check examples/ipc_command.rs for details.
Please see here.
bevy_flurx_wry | bevy_flurx | bevy |
---|---|---|
0.1.0-alpha1 | 0.5.2 | 0.13.2 |
This crate is licensed under the MIT License or the Apache License 2.0.