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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
use std::collections::HashSet;

use rsciter::*;

fn main() {
    if let Err(e) = try_main() {
        eprintln!("Error: {e}");
    } else {
        println!("Ok!");
    }
}

fn try_main() -> Result<i32> {
    // pass custom args to the Sciter Engine
    app::init_from_iter(["arg1", "arg2"].into_iter())?;

    let ux_ok = set_option(RuntimeOption::UxTheming(false))?;
    let gfx_ok = set_option(RuntimeOption::GfxLayer(GfxLayer::GFX_LAYER_AUTO))?;
    let rt_ok = set_option(RuntimeOption::ScriptFeatures(ScriptFeatures::ALLOW_ALL))?;

    dbg!(ux_ok, gfx_ok, rt_ok);

    let window = Window::builder()
        .with_window_delegate(WinDelegate::new())
        .build_main()?;

    window.load_html(include_bytes!("app.html"), None)?;

    // app.html does this like Window.this.state = Window.WINDOW_SHOWN;
    // window.show(Visibility::Normal)?;

    let exit_code = app::run()?;

    window.with_window_delegate::<WinDelegate>(|d| {
        println!("It was {} different messages", d.messages.len());
    });

    app::shutdown()?;

    Ok(exit_code)
}

struct WinDelegate {
    messages: HashSet<u32>,
}

impl WinDelegate {
    fn new() -> Self {
        Self {
            messages: HashSet::new(),
        }
    }
}

impl WindowDelegate for WinDelegate {
    fn on_message(
        &mut self,
        window: WindowHandle,
        msg: bindings::UINT,
        wparam: bindings::WPARAM,
        lparam: bindings::LPARAM,
    ) -> (bool, bindings::LRESULT) {
        let _ = window;
        let _ = msg;
        let _ = wparam;
        let _ = lparam;

        self.messages.insert(msg);

        (false, Default::default())
    }
}

impl Drop for WinDelegate {
    fn drop(&mut self) {
        println!("Dropped");
    }
}