Files
zoeae/src/components/editor.rs
T

48 lines
1.3 KiB
Rust
Raw Normal View History

2026-01-24 19:53:46 -06:00
use iced::{
Element, Length, Theme, border, highlighter,
2026-01-24 21:24:32 -06:00
widget::{container, markdown, row, text_editor},
2026-01-24 19:53:46 -06:00
};
use crate::{constants, file::File, message::Message, state::Mode};
pub fn view<'a>(file: &'a File, mode: Mode, font_size: u32) -> Element<'a, Message> {
2026-01-24 21:24:32 -06:00
match mode {
Mode::Edit => {
let editor = text_editor(file.content())
.highlight(
file.extension().unwrap_or("txt"),
highlighter::Theme::Base16Ocean,
)
.padding(10)
2026-01-24 21:24:32 -06:00
.size(font_size)
.height(Length::Fill)
.style(|theme: &Theme, status: text_editor::Status| {
let base = text_editor::default(theme, status);
text_editor::Style {
border: border::Border {
width: 0.0,
..Default::default()
},
..base
}
})
2026-01-24 21:24:32 -06:00
.on_action(Message::Edit);
2026-01-24 19:53:46 -06:00
2026-01-24 21:24:32 -06:00
container(row![editor]).height(Length::Fill).into()
2026-01-24 19:53:46 -06:00
}
2026-01-24 21:24:32 -06:00
Mode::Preview => {
let mut style: markdown::Style = Theme::Dark.into();
style.font = constants::CUSTOM_FONT;
let settings = markdown::Settings::with_text_size(font_size, style);
let markdown_preview = markdown::view(file.markdown(), settings).map(Message::LinkClicked);
container(row![markdown_preview])
.height(Length::Fill)
.into()
}
}
2026-01-24 19:53:46 -06:00
}