orientation/
orientation.rs1use 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 = 24;
8 let mut orientation = 0;
9 let draw = |iv: &inkview::bindings::Inkview| unsafe {
10 let font_name = CString::new("LiberationSans").unwrap();
11 let text = CString::new("Press Menu to toggle the orientation!").unwrap();
12
13 let font = iv.OpenFont(font_name.as_ptr(), FONT_SIZE, 0);
14 iv.ClearScreen();
15 iv.SetFont(font, bindings::BLACK as c_int);
16 iv.FillArea(
17 50,
18 250,
19 iv.ScreenWidth() - 50 * 2,
20 iv.ScreenHeight() - 250 * 2,
21 0x00E0E0E0,
22 );
23 iv.FillArea(
24 100,
25 300,
26 iv.ScreenWidth() - 100 * 2,
27 iv.ScreenHeight() - 300 * 2,
28 0x00A0A0A0,
29 );
30 iv.DrawTextRect(
31 0,
32 iv.ScreenHeight() / 2 - FONT_SIZE / 2,
33 iv.ScreenWidth(),
34 FONT_SIZE,
35 text.as_ptr(),
36 bindings::ALIGN_CENTER as c_int,
37 );
38 iv.FullUpdate();
39 iv.CloseFont(font);
40 };
41
42 inkview::iv_main(&iv, move |event| {
43 match event {
44 Event::Init => {
45 unsafe {
46 iv.SetCurrentApplicationAttribute(APPLICATION_ATTRIBUTE_APPLICATION_READER, 1);
47 iv.SetOrientation(orientation);
48 }
49 draw(iv);
50 }
51 Event::KeyDown { key } => match key {
52 inkview::event::Key::Menu => {
53 orientation = match orientation {
54 0 => 2,
55 2 => 3,
56 3 => 1,
57 1 => 0,
58 _ => unreachable!(),
59 };
60 unsafe {
61 iv.SetOrientation(orientation);
62 }
63 draw(iv);
64 }
65 _ => unsafe {
66 iv.CloseApp();
67 },
68 },
69 _ => {}
70 }
71 Some(())
72 });
73}