normalize tab items component

This commit is contained in:
yggverse 2024-10-08 00:56:52 +03:00
parent 47e2bc4617
commit 65502c247d
29 changed files with 427 additions and 117 deletions

View file

@ -1,68 +0,0 @@
// @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
}
}