2026-01-24 19:53:46 -06:00
|
|
|
use iced::{
|
2026-01-30 07:17:00 -06:00
|
|
|
Background, Element, Length, Theme,
|
|
|
|
|
border::{self},
|
2026-02-19 16:09:37 -06:00
|
|
|
highlighter,
|
|
|
|
|
widget::{container, markdown, row, scrollable, 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())
|
2026-01-25 17:26:16 -06:00
|
|
|
.highlight(
|
|
|
|
|
file.extension().unwrap_or("txt"),
|
|
|
|
|
highlighter::Theme::Base16Ocean,
|
|
|
|
|
)
|
|
|
|
|
.padding(10)
|
2026-01-24 21:24:32 -06:00
|
|
|
.size(font_size)
|
2026-01-25 17:26:16 -06:00
|
|
|
.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-30 07:17:00 -06:00
|
|
|
scrollable(container(editor).height(Length::Fill))
|
|
|
|
|
.auto_scroll(true)
|
|
|
|
|
.direction(scrollable::Direction::Both {
|
|
|
|
|
vertical: scrollable::Scrollbar::default(),
|
|
|
|
|
horizontal: scrollable::Scrollbar::default(),
|
|
|
|
|
})
|
|
|
|
|
.style(|theme: &Theme, status: scrollable::Status| {
|
|
|
|
|
let mut style = scrollable::default(theme, status);
|
|
|
|
|
style.horizontal_rail.background = Some(Background::Color(theme.palette().background));
|
|
|
|
|
style.horizontal_rail.scroller.background = Background::Color(theme.palette().primary);
|
|
|
|
|
style.vertical_rail.background = Some(Background::Color(theme.palette().background));
|
|
|
|
|
style.vertical_rail.scroller.background = Background::Color(theme.palette().primary);
|
|
|
|
|
style
|
|
|
|
|
})
|
|
|
|
|
.anchor_bottom()
|
|
|
|
|
.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);
|
|
|
|
|
|
2026-01-30 07:17:00 -06:00
|
|
|
scrollable(row![markdown_preview].padding(10))
|
|
|
|
|
.auto_scroll(true)
|
|
|
|
|
.direction(scrollable::Direction::Both {
|
|
|
|
|
vertical: scrollable::Scrollbar::new().spacing(1),
|
|
|
|
|
horizontal: scrollable::Scrollbar::new().spacing(1),
|
|
|
|
|
})
|
|
|
|
|
.style(|theme: &Theme, status: scrollable::Status| {
|
|
|
|
|
let mut style = scrollable::default(theme, status);
|
|
|
|
|
style.horizontal_rail.background = Some(Background::Color(theme.palette().background));
|
|
|
|
|
style.horizontal_rail.scroller.background = Background::Color(theme.palette().primary);
|
|
|
|
|
style.vertical_rail.background = Some(Background::Color(theme.palette().background));
|
|
|
|
|
style.vertical_rail.scroller.background = Background::Color(theme.palette().primary);
|
|
|
|
|
style
|
|
|
|
|
})
|
2026-01-24 21:24:32 -06:00
|
|
|
.height(Length::Fill)
|
2026-01-30 07:17:00 -06:00
|
|
|
.width(Length::Fill)
|
2026-01-24 21:24:32 -06:00
|
|
|
.into()
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-01-24 19:53:46 -06:00
|
|
|
}
|