add text/plain content type support

This commit is contained in:
yggverse 2025-02-04 15:15:12 +02:00
parent 63d2821c07
commit f2da250376
6 changed files with 75 additions and 64 deletions

View file

@ -0,0 +1,22 @@
use gtk::{TextBuffer, TextView};
pub trait Plain {
fn plain(data: &str) -> Self;
}
impl Plain for TextView {
fn plain(data: &str) -> Self {
const MARGIN: i32 = 8;
TextView::builder()
.bottom_margin(MARGIN)
.cursor_visible(false)
.buffer(&TextBuffer::builder().text(data).build())
.editable(false)
.left_margin(MARGIN)
.monospace(true)
.right_margin(MARGIN)
.top_margin(MARGIN)
.vexpand(true)
.build()
}
}

View file

@ -1,33 +0,0 @@
use gtk::{Align, Label};
pub struct Reader {
widget: Label,
}
impl Default for Reader {
fn default() -> Self {
Self::new()
}
}
impl Reader {
// Construct
pub fn new() -> Self {
Self {
widget: Label::builder()
.halign(Align::Start)
.valign(Align::Start)
.margin_start(8)
.margin_end(8)
.wrap(true)
.selectable(true)
.use_markup(true)
.build(),
}
}
// Getters
pub fn widget(&self) -> &Label {
&self.widget
}
}