Files
zoeae/src/main.rs
T

87 lines
2.4 KiB
Rust
Raw Normal View History

2026-01-24 19:53:46 -06:00
mod components;
mod constants;
mod file;
2026-01-24 19:53:46 -06:00
mod io;
mod key_bindings;
mod state;
mod handler;
mod message;
2026-01-24 19:53:46 -06:00
use iced::Theme;
use iced::widget::column;
2026-01-09 07:51:53 -06:00
use iced::window::icon;
2026-01-24 19:53:46 -06:00
use iced::{Element, Subscription, Task, event};
2026-01-10 08:02:21 -06:00
use iced::{keyboard, window};
2026-01-11 08:04:25 -06:00
2026-01-24 19:53:46 -06:00
use crate::message::Message;
use crate::state::State;
2026-01-24 19:53:46 -06:00
pub fn main() -> iced::Result {
iced::application(boot, update, view)
.subscription(subscription)
.font(constants::CUSTOM_FONT_BYTES)
.theme(theme)
.settings(iced::Settings {
default_font: constants::CUSTOM_FONT,
..Default::default()
})
.window(window::Settings {
icon: Some(
icon::from_file_data(constants::ICON_BYTES, None).expect("Failed to load icon"),
),
..window::Settings::default()
})
.run()
}
2026-01-21 07:12:20 -06:00
fn update(state: &mut State, message: Message) -> Task<Message> {
match message {
2026-01-24 19:53:46 -06:00
Message::Edit(action) => handler::edit(state, action),
Message::SwitchTab(index) => handler::switch_tab(state, index),
Message::LinkClicked(url) => handler::link_clicked(url),
Message::FileActionSelected(action) => handler::file_action(state, action),
Message::ViewActionSelected(action) => handler::view_action(state, action),
Message::FileOpened(_) => todo!(),
Message::FileSaved(path_buf) => todo!(),
}
}
2026-01-24 19:53:46 -06:00
fn view(state: &State) -> Element<'_, Message> {
let current_file = state.active_file();
column![
components::tabs::view(state.files(), state.current_file_index()),
components::action_bar::view(state.selected_file_action(), state.selected_view_action()),
components::editor::view(current_file, state.mode(), state.font_size()),
components::status_bar::view(current_file),
]
.padding(10)
.into()
}
2026-01-24 19:53:46 -06:00
fn boot() -> State {
state::State::new()
}
fn subscription(_state: &State) -> Subscription<Message> {
event::listen_with(|e, _status, _win| -> Option<Message> {
match e {
iced::Event::Keyboard(keyboard::Event::KeyPressed { key, modifiers, .. }) => {
2026-01-24 19:53:46 -06:00
for vb in key_bindings::ALL {
if vb.should_handle(&key, &modifiers) {
2026-01-24 19:53:46 -06:00
return Some(vb.message());
}
}
None
}
_ => None,
}
})
}
2026-01-24 19:53:46 -06:00
fn theme(_state: &State) -> Theme {
Theme::Dark
}