Skip to main content

hello_world/
hello_world.rs

1use inkview::bindings::APPLICATION_ATTRIBUTE_APPLICATION_READER;
2use inkview::{bindings, Event};
3use std::ffi::{c_int, CString};
4
5fn main() {
6    let iv = Box::leak(Box::new(inkview::load())) as &_;
7    const FONT_SIZE: c_int = 42;
8
9    inkview::iv_main(&iv, move |event| {
10        match event {
11            Event::Init => unsafe {
12                iv.SetCurrentApplicationAttribute(APPLICATION_ATTRIBUTE_APPLICATION_READER, 1);
13
14                let font_name = CString::new("LiberationSans").unwrap();
15                let text = CString::new("Hello world!").unwrap();
16
17                let font = iv.OpenFont(font_name.as_ptr(), FONT_SIZE, 0);
18                iv.ClearScreen();
19
20                iv.SetFont(font, bindings::BLACK as c_int);
21                iv.DrawLine(
22                    25,
23                    iv.ScreenHeight() - 25,
24                    iv.ScreenWidth() - 25,
25                    iv.ScreenHeight() - 25,
26                    0x00666666,
27                );
28                iv.FillArea(
29                    50,
30                    250,
31                    iv.ScreenWidth() - 50 * 2,
32                    iv.ScreenHeight() - 250 * 2,
33                    0x00E0E0E0,
34                );
35                iv.FillArea(
36                    100,
37                    300,
38                    iv.ScreenWidth() - 100 * 2,
39                    iv.ScreenHeight() - 300 * 2,
40                    0x00A0A0A0,
41                );
42                iv.DrawTextRect(
43                    0,
44                    iv.ScreenHeight() / 2 - FONT_SIZE / 2,
45                    iv.ScreenWidth(),
46                    FONT_SIZE,
47                    text.as_ptr(),
48                    bindings::ALIGN_CENTER as c_int,
49                );
50
51                // Copies the buffer to the real screen
52                iv.FullUpdate();
53
54                iv.CloseFont(font);
55            },
56            Event::KeyDown { .. } => unsafe {
57                iv.CloseApp();
58            },
59            _ => {}
60        }
61        Some(())
62    });
63}