DEVELOPMENT ENVIRONMENT

~liljamo/gandalf

ref: 17ace9336bdbb5bc86438d7c4b5ff62028c31e1f gandalf/src/main.rs -rw-r--r-- 1.7 KiB
17ace933Jonni Liljamo just keep force pushing this lol 7 months ago
                                                                                
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 libtalma::iced::{self, Command, widget::{column, text}, Application};

mod fonts;
mod input;

fn main() -> iced::Result {
    let settings = iced::settings::Settings {
        window: iced::window::Settings {
            position: iced::window::Position::Centered,
            visible: true,
            resizable: false,
            decorations: false,
            transparent: true,
            level: iced::window::Level::AlwaysOnTop,
            ..Default::default()
        },
        ..libtalma::window_settings(())
    };

    Gandalf::run(settings)
}

enum GandalfState {
    Exec,
    Calc,
    Light,
}

struct Gandalf {
    state: GandalfState,
}

#[derive(Debug)]
pub enum Message {
    Exit,
}

impl Application for Gandalf {
    type Theme = iced::Theme;
    type Flags = ();
    type Message = Message;
    type Executor = iced::executor::Default;

    fn new(_flags: Self::Flags) -> (Self, iced::Command<Self::Message>) {
        (Gandalf {
            state: GandalfState::Exec,
        }, Command::none())
    }

    fn title(&self) -> String {
        String::from("gandalf")
    }

    fn update(&mut self, message: Self::Message) -> Command<Self::Message> {
        match message {
            Message::Exit => iced::window::close(iced::window::Id::MAIN),
        }
    }

    fn subscription(&self) -> iced::Subscription<Self::Message> {
        iced::keyboard::on_key_press(|key_code, modifiers| {
            if modifiers.command() {
                return None;
            }

            input::handle(key_code)
        })
    }

    fn view(&self) -> iced::Element<'_, Self::Message> {
        column![
            text("libtalma").size(64)
        ]
        .padding(20)
        .align_items(iced::Alignment::Center)
        .into()
    }
}