mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-01 00:55:28 +00:00
68 lines
1.4 KiB
Rust
68 lines
1.4 KiB
Rust
// @TODO mod image;
|
|
mod text;
|
|
|
|
use text::Text;
|
|
|
|
use gtk::{
|
|
gio::SimpleAction,
|
|
glib::{GString, Uri},
|
|
prelude::{BoxExt, WidgetExt},
|
|
Box, Orientation,
|
|
};
|
|
|
|
use std::sync::Arc;
|
|
|
|
pub enum Mime {
|
|
TextGemini,
|
|
// TextPlain,
|
|
}
|
|
|
|
pub struct ResetResult {
|
|
pub title: Option<GString>,
|
|
}
|
|
|
|
pub struct Content {
|
|
// GTK
|
|
widget: Box,
|
|
// Actions
|
|
action_page_open: Arc<SimpleAction>,
|
|
}
|
|
|
|
impl Content {
|
|
// Construct
|
|
pub fn new(action_page_open: Arc<SimpleAction>) -> Self {
|
|
Self {
|
|
widget: Box::builder().orientation(Orientation::Vertical).build(),
|
|
action_page_open,
|
|
}
|
|
}
|
|
|
|
// Actions
|
|
pub fn reset(&self, mime: Mime, base: &Uri, data: &str) -> ResetResult {
|
|
// Cleanup
|
|
while let Some(child) = self.widget.last_child() {
|
|
self.widget.remove(&child)
|
|
}
|
|
|
|
// Re-compose
|
|
match mime {
|
|
Mime::TextGemini => {
|
|
let child = Text::gemini(data, base, self.action_page_open.clone());
|
|
|
|
self.widget.append(child.widget());
|
|
|
|
ResetResult {
|
|
title: child.meta_title().clone(),
|
|
}
|
|
} /* @TODO
|
|
Mime::TextPlain => {
|
|
todo!()
|
|
} */
|
|
}
|
|
}
|
|
|
|
// Getters
|
|
pub fn widget(&self) -> &Box {
|
|
&self.widget
|
|
}
|
|
}
|