Skip to content

Commit 8213a6e

Browse files
committed
update examples
1 parent eec33ac commit 8213a6e

8 files changed

Lines changed: 34 additions & 36 deletions

File tree

examples/basic2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fn main() {
1717
win.show();
1818

1919
let wv = Webview::create(false, &mut wv_win);
20-
wv.navigate("https://google.com");
20+
wv.navigate("https://google.com").unwrap();
2121

2222
app.run().unwrap();
2323
}

examples/bind.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ fn main() {
3131
win.show();
3232

3333
let wv = Webview::create(true, &mut wv_win);
34-
wv.set_html(HTML);
34+
wv.set_html(HTML).unwrap();
3535
wv.bind("add", |seq, content| {
3636
println!("{}, {}", seq, content);
3737
let parsed: JsonValue = content.parse().unwrap();
@@ -40,15 +40,15 @@ fn main() {
4040
let ret = val1 + val2;
4141
// currenyly still not valid on MS Edge as well as the official for window.onload = function() {..},
4242
// binding (on first load window evaluation), but working fine on webkit.
43-
wv.return_(seq, 0, &ret.to_string());
44-
});
43+
wv.return_(seq, 0, &ret.to_string()).unwrap();
44+
}).unwrap();
4545

4646
wv.bind("say_hello", |seq, content| {
4747
println!("{}, {}", seq, content);
4848
let parsed: JsonValue = content.parse().unwrap();
4949
let val: &String = parsed[0].get().unwrap();
50-
wv.return_(seq, 0, &format!("\"Hello {}\"", val));
51-
});
50+
wv.return_(seq, 0, &format!("\"Hello {}\"", val)).unwrap();
51+
}).unwrap();
5252

5353
app.run().unwrap();
5454
}

examples/dispatch.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ fn main() {
3131
result.innerText = s;
3232
};
3333
"#,
34-
);
35-
wv.set_html(HTML);
34+
).unwrap();
35+
wv.set_html(HTML).unwrap();
3636

3737
let (s, r) = app::channel::<i32>();
3838
wv.dispatch(move |_wv| {
@@ -44,11 +44,11 @@ fn main() {
4444
count += 1;
4545
}
4646
});
47-
});
47+
}).unwrap();
4848

4949
while app.wait() {
5050
if let Some(count) = r.recv() {
51-
wv.eval(&format!("counter({})", count));
51+
wv.eval(&format!("counter({})", count)).unwrap();
5252
}
5353
}
5454
}

examples/eval.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ fn main() {
4343
wv.eval(&format!(
4444
"document.getElementById('result').innerText = {}",
4545
ret
46-
));
47-
});
46+
)).unwrap();
47+
}).unwrap();
4848

49-
wv.set_html(HTML);
49+
wv.set_html(HTML).unwrap();
5050

5151
app.run().unwrap();
5252
}

examples/init.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ fn main() {
2626
result.innerText = "works";
2727
};
2828
"#,
29-
);
29+
).unwrap();
3030

31-
wv.set_html(HTML);
31+
wv.set_html(HTML).unwrap();
3232

33-
btn.set_callback(move |_| wv.eval("window.change()"));
33+
btn.set_callback(move |_| { wv.eval("window.change()").unwrap(); });
3434

3535
app.run().unwrap();
3636
}

examples/markdown.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fn main() {
1919
win.show();
2020

2121
let wv = Webview::create(false, &mut wv_win);
22-
wv.set_html("");
22+
wv.set_html("").unwrap();
2323

2424
buf.add_modify_callback({
2525
move |_, _, _, _, _| {
@@ -29,7 +29,7 @@ fn main() {
2929
let parser = Parser::new_ext(&txt, options);
3030
let mut html_output: String = String::with_capacity(txt.len() * 3 / 2);
3131
html::push_html(&mut html_output, parser);
32-
wv.set_html(&html_output);
32+
wv.set_html(&html_output).unwrap();
3333
}
3434
});
3535

examples/unicode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fn main() {
1616
win.show();
1717

1818
let wv = Webview::create(false, &mut wv_win);
19-
wv.set_html(HTML);
19+
wv.set_html(HTML).unwrap();
2020

2121
app.run().unwrap();
2222
}

src/lib.rs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use fltk::{
77
window,
88
};
99
use fltk_webview_sys as wv;
10-
use std::{os::raw, sync::Arc};
10+
use std::sync::Arc;
1111
pub use wv::SizeHint;
1212
pub use wv::Webview;
1313

@@ -33,21 +33,12 @@ impl FromFltkWindow for Webview {
3333
extern "system" {
3434
pub fn SetFocus(child: *mut ()) -> *mut ();
3535
pub fn CoInitializeEx(pvReserved: *mut (), dwCoInit: u32) -> i32;
36-
pub fn SendMessageW(
37-
hwnd: *mut (),
38-
msg: u32,
39-
wparam: usize,
40-
lparam: isize,
41-
) -> isize;
42-
}
43-
const COINIT_APARTMENTTHREADED: u32 = 0x2;
44-
const WM_SIZE: u32 = 0x0005;
45-
CoInitializeEx(std::ptr::null_mut(), COINIT_APARTMENTTHREADED);
46-
inner = wv::webview_create(debug as i32, std::ptr::null_mut());
47-
wv::webview_set_size(inner, win.w(), win.h(), 3);
48-
let wv_hwnd = wv::webview_get_window(inner);
49-
// Manually set the webview window as a child and position it
50-
extern "system" {
36+
// pub fn SendMessageW(
37+
// hwnd: *mut (),
38+
// msg: u32,
39+
// wparam: usize,
40+
// lparam: isize,
41+
// ) -> isize;
5142
pub fn SetParent(child: *mut (), parent: *mut ()) -> *mut ();
5243
pub fn SetWindowPos(
5344
hwnd: *mut (),
@@ -58,9 +49,16 @@ impl FromFltkWindow for Webview {
5849
cy: i32,
5950
flags: u32,
6051
) -> i32;
61-
pub fn GetWindowLongW(hwnd: *mut (), index: i32) -> i32;
52+
// pub fn GetWindowLongW(hwnd: *mut (), index: i32) -> i32;
6253
pub fn SetWindowLongW(hwnd: *mut (), index: i32, new_long: i32) -> i32;
6354
}
55+
const COINIT_APARTMENTTHREADED: u32 = 0x2;
56+
// const WM_SIZE: u32 = 0x0005;
57+
CoInitializeEx(std::ptr::null_mut(), COINIT_APARTMENTTHREADED);
58+
inner = wv::webview_create(debug as i32, std::ptr::null_mut());
59+
wv::webview_set_size(inner, win.w(), win.h(), 3);
60+
let wv_hwnd = wv::webview_get_window(inner);
61+
// Manually set the webview window as a child and position it
6462
const GWL_STYLE: i32 = -16;
6563
const WS_CHILD: i32 = 0x40000000;
6664
const WS_VISIBLE: i32 = 0x10000000;

0 commit comments

Comments
 (0)