wgpu windows (fixed) (#3257)

* Working triangle rendering with wgpu in examples. Resize needs work in order to not reinitialize everything but only the bits needed. Naming of variables and resources are wonky and not the greatest.

* The child window wasn't being resized along with the parent. This works. the abstractions in place should be passed the bounds rect down into the desktopservice to resize as opposed to in the app impl instead of how they are rn.

---------

Co-authored-by: Vineeth Yeevani <vineethyeevani@Vineeths-MacBook-Air.local>
Co-authored-by: Vineeth Yeevani <vineeth.yeevani@gmail.com>
This commit is contained in:
authored and GitHub committed 2024-11-26 18:44:53 +01:00
1 parent e1457744f0
commit 1e8693a0e8
8 files changed
+983 -289

No files matched your search

+2 -2
View File
@@ -101,12 +101,12 @@ objc = "0.2.7"
lazy-js-bundle = { workspace = true }
[features]
default = ["tokio_runtime", "exception", "devtools"]
default = ["tokio_runtime", "exception", "transparent", "devtools"]
tokio_runtime = ["dep:tokio"]
fullscreen = ["wry/fullscreen"]
transparent = ["wry/transparent"]
devtools = ["wry/devtools", "dep:dioxus-devtools", "dioxus-signals"]
exception = ["wry/objc-exception"]
transparent = ["wry/transparent"]
gnu = []
[package.metadata.docs.rs]
+22
View File
@@ -17,6 +17,7 @@ use std::{
sync::Arc,
};
use tao::{
dpi::PhysicalSize,
event::Event,
event_loop::{ControlFlow, EventLoop, EventLoopBuilder, EventLoopProxy, EventLoopWindowTarget},
window::WindowId,
@@ -222,6 +223,27 @@ impl App {
}
}
pub fn resize_window(&self, size: PhysicalSize<u32>) {
// TODO: the app layer should avoid directly manipulating the webview webview instance internals.
// Window creation and modification is the responsibility of the webview instance so it makes sense to
// encapsulate that there.
self.webviews.values().for_each(|webview_instance| {
use wry::Rect;
webview_instance
.desktop_context
.webview
.set_bounds(Rect {
position: wry::dpi::Position::Logical(wry::dpi::LogicalPosition::new(0.0, 0.0)),
size: wry::dpi::Size::Physical(wry::dpi::PhysicalSize::new(
size.width,
size.height,
)),
})
.unwrap();
});
}
pub fn handle_start_cause_init(&mut self) {
let virtual_dom = self.unmounted_dom.take().unwrap();
let mut cfg = self.cfg.take().unwrap();
+8
View File
@@ -49,6 +49,7 @@ impl From<MenuBuilderState> for Option<DioxusMenu> {
pub struct Config {
pub(crate) event_loop: Option<EventLoop<UserWindowEvent>>,
pub(crate) window: WindowBuilder,
pub(crate) as_child_window: bool,
pub(crate) menu: MenuBuilderState,
pub(crate) protocols: Vec<WryProtocol>,
pub(crate) asynchronous_protocols: Vec<AsyncWryProtocol>,
@@ -92,6 +93,7 @@ impl Config {
Self {
window,
as_child_window: false,
event_loop: None,
menu: MenuBuilderState::Unset,
protocols: Vec::new(),
@@ -152,6 +154,12 @@ impl Config {
self
}
/// Set the window as child
pub fn with_as_child_window(mut self) -> Self {
self.as_child_window = true;
self
}
/// Sets the behaviour of the application when the last window is closed.
pub fn with_close_behaviour(mut self, behaviour: WindowCloseBehaviour) -> Self {
self.last_window_close_behavior = behaviour;
+1
View File
@@ -32,6 +32,7 @@ pub fn launch_virtual_dom_blocking(virtual_dom: VirtualDom, mut desktop_config:
} => match event {
WindowEvent::CloseRequested => app.handle_close_requested(window_id),
WindowEvent::Destroyed { .. } => app.window_destroyed(window_id),
WindowEvent::Resized(new_size) => app.resize_window(new_size),
_ => {}
},
+12 -1
View File
@@ -296,7 +296,11 @@ impl WebviewInstance {
target_os = "ios",
target_os = "android"
))]
let mut webview = WebViewBuilder::new(&window);
let mut webview = if cfg.as_child_window {
WebViewBuilder::new_as_child(&window)
} else {
WebViewBuilder::new(&window)
};
#[cfg(not(any(
target_os = "windows",
@@ -319,6 +323,13 @@ impl WebviewInstance {
}
webview = webview
.with_bounds(wry::Rect {
position: wry::dpi::Position::Logical(wry::dpi::LogicalPosition::new(0.0, 0.0)),
size: wry::dpi::Size::Physical(wry::dpi::PhysicalSize::new(
window.inner_size().width,
window.inner_size().height,
)),
})
.with_transparent(cfg.window.window.transparent)
.with_url("dioxus://index.html/")
.with_ipc_handler(ipc_handler)