use modern (2018) pattern for modules

This commit is contained in:
yggverse 2024-09-27 22:36:22 +03:00
parent 1627902b8f
commit cdc3fe3388
28 changed files with 0 additions and 0 deletions

View file

@ -0,0 +1,61 @@
// @TODO mod image;
mod text;
use text::Text;
use gtk::{
glib::{GString, Uri},
prelude::{BoxExt, WidgetExt},
Box, Orientation,
};
pub enum Mime {
TextGemini,
TextPlain,
}
pub struct ResetResult {
pub title: Option<GString>,
}
pub struct Content {
widget: Box,
}
impl Content {
// Construct
pub fn new() -> Self {
Self {
widget: Box::builder().orientation(Orientation::Vertical).build(),
}
}
// 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.widget.append(child.widget());
ResetResult {
title: child.meta_title().clone(),
}
}
Mime::TextPlain => {
todo!()
}
}
}
// Getters
pub fn widget(&self) -> &Box {
&self.widget
}
}