use super::*;
#[cfg(feature = "ticket")]
use crate::ticket::SubTicketRawNote;
#[cfg(all(feature = "image_processing", feature = "gui"))]
use crate::ImageSpec;
#[cfg(feature = "html")]
use mkutil::html_scraping::{self, PlaceImageHint};
#[derive(Debug, Clone, Default)]
pub struct Note {
pub text: String,
pub(crate) embed_layout: ImageEmbedLayout,
}
impl Note {
#[cfg(feature = "gui")]
pub(super) fn inplace_embed() -> Self {
Self {
embed_layout: ImageEmbedLayout::Carousel(InPlaceSeqDisplay::Embedded(
Default::default(),
)),
..Default::default()
}
}
#[cfg(feature = "html")]
pub fn with_html(self, html: &str, img_hint: &PlaceImageHint) -> Self {
let (text, img_paths) = html_scraping::grab_text_elements(html, img_hint);
Self {
text,
embed_layout: self.embed_layout.with_img_paths(img_paths),
}
}
pub(super) fn texture_ids_mut(&mut self) {
#[cfg(debug_assertions)]
if let Some(img_paths) = self.embed_layout.img_paths_as_mut() {
hconf::uri::__defect_tracking_mock_url(img_paths);
};
#[cfg(all(feature = "image_processing", feature = "gui"))]
self.embed_layout.img_specs_mut()
}
#[cfg(all(feature = "image_processing", feature = "gui"))]
pub fn img_specs(&self) -> Option<&Vec<Option<ImageSpec>>> {
self.embed_layout.img_specs()
}
#[cfg(feature = "gui")]
pub fn img_embed_ui(&mut self, ui: &mut egui::Ui, thumb_width: f32) {
match &mut self.embed_layout {
ImageEmbedLayout::RowOrColumn(seq) => {
seq.ui(ui, thumb_width);
}
ImageEmbedLayout::Carousel(_seq) => {
#[cfg(feature = "image_processing")]
_seq.inner_mut()
.show_img_embed_and_pos_slider(ui, thumb_width);
}
}
}
}
#[derive(Debug, Clone, Default)]
pub struct MultilingualNote {
en: Option<Note>,
vi: Option<Note>,
zh: Option<Note>,
fr: Option<Note>,
}
impl MultilingualNote {
pub fn empty() -> Self {
Self {
en: None,
vi: None,
zh: None,
fr: None,
}
}
#[cfg(feature = "ticket")]
pub fn to_image_array(note: &SubTicketRawNote, img_hint: &PlaceImageHint) -> Self {
MultilingualNote {
en: note
.en
.as_ref()
.map(|n| Note::default().with_html(n, img_hint)),
vi: note
.vi
.as_ref()
.map(|n| Note::default().with_html(n, img_hint)),
zh: note
.zh
.as_ref()
.map(|n| Note::default().with_html(n, img_hint)),
fr: note
.fr
.as_ref()
.map(|n| Note::default().with_html(n, img_hint)),
}
}
#[cfg(all(feature = "ticket", feature = "gui"))]
pub fn to_inplace_embed(note: &SubTicketRawNote, img_hint: &PlaceImageHint) -> Self {
MultilingualNote {
en: note
.en
.as_ref()
.map(|n| Note::inplace_embed().with_html(n, img_hint)),
vi: note
.vi
.as_ref()
.map(|n| Note::inplace_embed().with_html(n, img_hint)),
zh: note
.zh
.as_ref()
.map(|n| Note::inplace_embed().with_html(n, img_hint)),
fr: note
.fr
.as_ref()
.map(|n| Note::inplace_embed().with_html(n, img_hint)),
}
}
pub fn localized_note_as_mut(&mut self, locale: &Locale) -> Option<&mut Note> {
match &locale {
Locale::EN => self.en.as_mut(),
Locale::VI => self.vi.as_mut(),
Locale::ZH => self.zh.as_mut(),
Locale::FR => self.fr.as_mut(),
}
}
pub fn localized_note_as_ref(&self, locale: &Locale) -> Option<&Note> {
match &locale {
Locale::EN => self.en.as_ref(),
Locale::VI => self.vi.as_ref(),
Locale::ZH => self.zh.as_ref(),
Locale::FR => self.fr.as_ref(),
}
}
pub fn texture_ids_mut(&mut self) {
if let Some(en) = self.en.as_mut() {
en.texture_ids_mut();
};
if let Some(vi) = self.vi.as_mut() {
vi.texture_ids_mut();
};
if let Some(zh) = self.zh.as_mut() {
zh.texture_ids_mut();
};
if let Some(fr) = self.fr.as_mut() {
fr.texture_ids_mut();
};
}
}