Update WebView to pass wry::WebView instance (#69)

It's much prefer to use `WebViewBuilder` instead of
[WebView::new](https://docs.rs/wry/latest/wry/struct.WebView.html#method.new)
This commit is contained in:
尹吉峰 2024-07-24 19:32:05 +08:00 committed by GitHub
parent 4c81977639
commit 7489a4ffdd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 15 additions and 12 deletions

View file

@ -22,7 +22,12 @@ impl WebViewStory {
pub fn view(cx: &mut WindowContext) -> View<Self> { pub fn view(cx: &mut WindowContext) -> View<Self> {
let focus_handle = cx.focus_handle(); let focus_handle = cx.focus_handle();
let webview = cx.new_view(|cx| WebView::new(cx)); let webview = cx.new_view(|cx| {
let webview = ui::wry::WebViewBuilder::new_as_child(&cx.raw_window_handle())
.build()
.unwrap();
WebView::new(cx, webview)
});
let address_input = cx.new_view(|cx| { let address_input = cx.new_view(|cx| {
let mut input = TextInput::new(cx); let mut input = TextInput::new(cx);

View file

@ -5,7 +5,7 @@ use gpui::{ModelContext, Timer};
/// To manage the Input cursor blinking. /// To manage the Input cursor blinking.
/// ///
/// It will start blinking with a interval of 500ms. /// It will start blinking with a interval of 500ms.
/// Every loop will notify the view to update the `visable`, and Input will observe this update to touch repaint. /// Every loop will notify the view to update the `visible`, and Input will observe this update to touch repaint.
/// ///
/// The input painter will check if this in visible state, then it will draw the cursor. /// The input painter will check if this in visible state, then it will draw the cursor.
pub struct BlinkCursor { pub struct BlinkCursor {

View file

@ -33,6 +33,9 @@ pub mod theme;
pub mod tooltip; pub mod tooltip;
pub mod webview; pub mod webview;
// re-export
pub use wry;
pub use clickable::Clickable; pub use clickable::Clickable;
pub use disableable::Disableable; pub use disableable::Disableable;
pub use event::InterativeElementExt; pub use event::InterativeElementExt;

View file

@ -17,21 +17,16 @@ pub fn init(_cx: &AppContext) {}
pub struct WebView { pub struct WebView {
focus_handle: FocusHandle, focus_handle: FocusHandle,
webview: Rc<wry::WebView>, webview: Rc<wry::WebView>,
visable: bool, visible: bool,
} }
impl WebView { impl WebView {
pub fn new(cx: &mut WindowContext) -> Self { pub fn new(cx: &mut WindowContext, webview: wry::WebView) -> Self {
let focus_handle = cx.focus_handle();
let window_handle = cx.raw_window_handle();
let webview = wry::WebView::new_as_child(&window_handle)
.expect("failed to create webview to child window");
let _ = webview.set_bounds(Rect::default()); let _ = webview.set_bounds(Rect::default());
Self { Self {
focus_handle, focus_handle: cx.focus_handle(),
visable: true, visible: true,
webview: Rc::new(webview), webview: Rc::new(webview),
} }
} }
@ -45,7 +40,7 @@ impl WebView {
} }
pub fn visible(&self) -> bool { pub fn visible(&self) -> bool {
self.visable self.visible
} }
/// Go back in the webview history. /// Go back in the webview history.