-
Notifications
You must be signed in to change notification settings - Fork 196
Expand file tree
/
Copy pathinner_html.rs
More file actions
59 lines (51 loc) · 1.63 KB
/
Copy pathinner_html.rs
File metadata and controls
59 lines (51 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use std::sync::Arc;
use anyrender_vello::VelloWindowRenderer;
use blitz_dom::DocumentConfig;
use blitz_html::{HtmlDocument, HtmlProvider};
use blitz_shell::{BlitzApplication, BlitzShellProxy, WindowConfig, create_default_event_loop};
pub fn main() {
// Create renderer
// Parse the HTML into a Blitz document
let mut doc = HtmlDocument::from_html(
HTML,
DocumentConfig {
html_parser_provider: Some(Arc::new(HtmlProvider) as _),
..Default::default()
},
);
let node_id = doc.query_selector("#content_area").unwrap().unwrap();
doc.mutate().set_inner_html(node_id, INNER_HTML);
doc.resolve(0.0);
// Create the Winit application and window
let event_loop = create_default_event_loop();
let (proxy, reciever) = BlitzShellProxy::new(event_loop.create_proxy());
let mut application = BlitzApplication::new(proxy, reciever);
let renderer = VelloWindowRenderer::new();
let window = WindowConfig::new(Box::new(doc), renderer);
application.add_window(window);
// Run event loop
event_loop.run_app(application).unwrap()
}
static HTML: &str = r#"
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
#content_area {
padding: 12px;
border: 1px solid black;
}
</style>
</head>
<body>
<main id="main">
<h1>Inner HTML Demo</h1>
<p>Text set with innerHTML should appear below:</p>
<div id="content_area"></div>
</main>
</body>
</html>
"#;
static INNER_HTML: &str = r#"
INNER <b>HTML</b> <i>TEXT</i> HERE
"#;