rustdesk/libs/rust-sciter/examples/interop.htm
2021-05-23 10:55:19 +08:00

91 lines
2.5 KiB
HTML

<html window-icon="https://sciter.com/wp-content/themes/sciter/!images/favicon.ico">
<head>
<title>Rust-sciter sample</title>
<style>
html {
background: radial-gradient(75% 75%, circle farthest-side, white, orange, rgb(0,0,204));
color:#fff;
}
html:rtl {
mapping: left-to-right(background);
}
</style>
<script type="text/tiscript">
view.caption = $(head > title).value;
$(#machine).text = Sciter.machineName();
$(#backend).text = view.backendName;
$(#version).text = String.printf("%d.%d.%d.%d",
(Sciter.VERSION >> 16) & 0xffff, Sciter.VERSION & 0xffff,
(Sciter.REVISION >> 16) & 0xffff, Sciter.REVISION & 0xffff);
var counter = 0;
$(button#append).on("click", function() {
$(body).$append(<h1#test>{ ++counter }</h1>);
});
$(button#open).on("click", function() {
var fn = view.selectFile(#open,
"HTML Files (*.htm,*.html)|*.HTM;*.HTML|All Files (*.*)|*.*" , "html" );
stdout.println("selected file: " + fn);
if (fn) {
$(body).$append(<h1#test>{fn}</h1>);
}
});
$(button#ti2py).on("click", function() {
var answer = view.NativeCall(view.caption);
$(body).$append(<h1#test>script -&gt; native: {answer}</h1>);
})
$(button#py2ti).on("click", function() {
var answer = view.ScriptCallTest("call arg");
})
$(button#sum).on("click", function() {
stdout.printf("2 + 3 = %d\n", view.calc_sum(2, 3));
})
function hello(who) {
$(body).$append(<h1#test>native -&gt; script: {who}</h1>);
return "its working!";
}
function raise_error(arg1, arg2, arg3) {
throw new Error(String.$(Unexpected type of input: {typeof arg1}, {typeof arg2}, {typeof arg3}.));
}
self.timer(2000, function() {
if(!view.api)
view.api = view.GetNativeApi();
// {add: function(a,b) { return a + b; }};
stdout.printf("2 + 3 = %d\n", view.api.add(2, 3));
stdout.printf("2 * 3 = %d\n", view.api.mul(2, 3));
stdout.printf("2 - 3 = %d\n", view.api.sub(2, 3));
});
</script>
</head>
<body>
<h1>Rust Sciter Application</h1>
<p>Running on <strong #machine /> machine via <strong #backend/> (<strong #version/>).</p>
<button #append>Append</button>
<button #open>Open</button>
<button #ti2py>Call native</button>
<button #py2ti>Call script</button>
<button #sum>Calc sum</button>
</body>
</html>