Skip to content

Commit 59a68fa

Browse files
committed
update
1 parent 2f0a9b8 commit 59a68fa

File tree

3 files changed

+137
-0
lines changed

3 files changed

+137
-0
lines changed

crates/rs-gui/try-wry/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ edition = "2024"
99
name = "t01"
1010
path = "examples/try01.rs"
1111

12+
# gtk_multiwebview
13+
[[bin]]
14+
name = "t01b"
15+
path = "examples/try01b.rs"
16+
1217
# multiwindow
1318
[[bin]]
1419
name = "t02"
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
// Copyright 2020-2023 Tauri Programme within The Commons Conservancy
2+
// SPDX-License-Identifier: Apache-2.0
3+
// SPDX-License-Identifier: MIT
4+
5+
use tao::{
6+
event::{Event, WindowEvent},
7+
event_loop::{ControlFlow, EventLoop},
8+
window::WindowBuilder,
9+
};
10+
use wry::{
11+
Rect, WebViewBuilder,
12+
dpi::{LogicalPosition, LogicalSize},
13+
};
14+
15+
fn main() -> wry::Result<()> {
16+
let event_loop = EventLoop::new();
17+
let window = WindowBuilder::new().build(&event_loop).unwrap();
18+
19+
#[cfg(not(any(
20+
target_os = "windows",
21+
target_os = "macos",
22+
target_os = "ios",
23+
target_os = "android"
24+
)))]
25+
let fixed = {
26+
use gtk::prelude::*;
27+
use tao::platform::unix::WindowExtUnix;
28+
let fixed = gtk::Fixed::new();
29+
let vbox = window.default_vbox().unwrap();
30+
vbox.pack_start(&fixed, true, true, 0);
31+
fixed.show_all();
32+
fixed
33+
};
34+
35+
let build_webview = |builder: WebViewBuilder<'_>| -> wry::Result<wry::WebView> {
36+
#[cfg(any(
37+
target_os = "windows",
38+
target_os = "macos",
39+
target_os = "ios",
40+
target_os = "android"
41+
))]
42+
let webview = builder.build(&window)?;
43+
44+
#[cfg(not(any(
45+
target_os = "windows",
46+
target_os = "macos",
47+
target_os = "ios",
48+
target_os = "android"
49+
)))]
50+
let webview = {
51+
use wry::WebViewBuilderExtUnix;
52+
builder.build_gtk(&fixed)?
53+
};
54+
55+
Ok(webview)
56+
};
57+
58+
let size = window.inner_size().to_logical::<u32>(window.scale_factor());
59+
60+
let builder = WebViewBuilder::new()
61+
.with_bounds(Rect {
62+
position: LogicalPosition::new(0, 0).into(),
63+
size: LogicalSize::new(size.width / 2, size.height / 2).into(),
64+
})
65+
.with_url("https://tauri.app");
66+
let webview = build_webview(builder)?;
67+
68+
let builder2 = WebViewBuilder::new()
69+
.with_bounds(Rect {
70+
position: LogicalPosition::new(size.width / 2, 0).into(),
71+
size: LogicalSize::new(size.width / 2, size.height / 2).into(),
72+
})
73+
.with_url("https://github.com/tauri-apps/wry");
74+
let webview2 = build_webview(builder2)?;
75+
76+
let builder3 = WebViewBuilder::new()
77+
.with_bounds(Rect {
78+
position: LogicalPosition::new(0, size.height / 2).into(),
79+
size: LogicalSize::new(size.width / 2, size.height / 2).into(),
80+
})
81+
.with_url("https://twitter.com/TauriApps");
82+
let webview3 = build_webview(builder3)?;
83+
84+
let builder4 = WebViewBuilder::new()
85+
.with_bounds(Rect {
86+
position: LogicalPosition::new(size.width / 2, size.height / 2).into(),
87+
size: LogicalSize::new(size.width / 2, size.height / 2).into(),
88+
})
89+
.with_url("https://google.com");
90+
let webview4 = build_webview(builder4)?;
91+
92+
event_loop.run(move |event, _, control_flow| {
93+
*control_flow = ControlFlow::Wait;
94+
95+
match event {
96+
Event::WindowEvent { event: WindowEvent::Resized(size), .. } => {
97+
let size = size.to_logical::<u32>(window.scale_factor());
98+
webview
99+
.set_bounds(Rect {
100+
position: LogicalPosition::new(0, 0).into(),
101+
size: LogicalSize::new(size.width / 2, size.height / 2).into(),
102+
})
103+
.unwrap();
104+
webview2
105+
.set_bounds(Rect {
106+
position: LogicalPosition::new(size.width / 2, 0).into(),
107+
size: LogicalSize::new(size.width / 2, size.height / 2).into(),
108+
})
109+
.unwrap();
110+
webview3
111+
.set_bounds(Rect {
112+
position: LogicalPosition::new(0, size.height / 2).into(),
113+
size: LogicalSize::new(size.width / 2, size.height / 2).into(),
114+
})
115+
.unwrap();
116+
webview4
117+
.set_bounds(Rect {
118+
position: LogicalPosition::new(size.width / 2, size.height / 2).into(),
119+
size: LogicalSize::new(size.width / 2, size.height / 2).into(),
120+
})
121+
.unwrap();
122+
},
123+
Event::WindowEvent { event: WindowEvent::CloseRequested, .. } => {
124+
*control_flow = ControlFlow::Exit
125+
},
126+
_ => {},
127+
}
128+
});
129+
}

crates/rs-gui/try-wry/readme.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ cd git-repo-root-dir/
1919
# multiwebview
2020
task gui:wry:r -- --bin t01
2121

22+
# gtk_multiwebview
23+
task gui:wry:r -- --bin t01b
24+
2225
# multiwindow
2326
task gui:wry:r -- --bin t02
2427
```

0 commit comments

Comments
 (0)