Skip to content

Instantly share code, notes, and snippets.

@t-mw
Created October 5, 2019 08:41
Show Gist options
  • Save t-mw/57058efa67d0109676876d6897636c79 to your computer and use it in GitHub Desktop.
Save t-mw/57058efa67d0109676876d6897636c79 to your computer and use it in GitHub Desktop.
rust-ul-test.rs
fn main() {
let config = ul::Config::new();
let mut ul_app = ul::UltralightApp::new(Some(config));
ul_app.window(1024u32, 1024u32, false, false, true, true, false);
let mut ul = ul::Ultralight::new(None, Some(ul_app.get_renderer()));
ul.set_view(ul_app.get_view().unwrap());
ul.log_to_stdout();
ul.load_html(
r#"
<html>
<head>
<style>
body { background-color: black; }
a.button1 {
display:inline-block;
padding:0.35em 1.2em;
border:0.1em solid #FFFFFF;
margin:0 0.3em 0.3em 0;
border-radius:0.12em;
box-sizing: border-box;
text-decoration:none;
font-family:'Roboto',sans-serif;
font-weight:300;
font-size: 18px;
color:#FFFFFF;
text-align:center;
transition: all 0.2s;
}
a.button1:hover {
  color:#000000;
  background-color:#FFFFFF;
}
</style>
</head>
<body>
Hello
<a onclick="test_callback()" onmouseover="console.log('mouseover')" class="button1" id="test">Click me</a>
</body>
</html>"#,
);
ul_app.resize_overlay(1024u32, 1024u32);
ul.set_finish_loading_callback(|_view| println!("loaded!"));
ul.set_dom_ready_callback(|_view| println!("dom ready!"));
ul_app.set_window_resize_callback(|width: u32, height: u32| {
ul_app.resize_overlay(width, height);
});
let (context, global) = ul::helpers::getJSContextFromView(ul_app.get_view().unwrap());
let fun = ul
.create_function("test_callback", &mut |_, _, _, _, _, _| {
println!("clicked");
std::ptr::null() as ul_sys::JSValueRef
})
.unwrap();
ul.set_js_object_property("test_callback", fun);
ul_app.run();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment