implement traits as tags

This commit is contained in:
yggverse 2025-02-01 19:47:27 +02:00
parent ae45108d7f
commit a4f3fe449a
9 changed files with 95 additions and 64 deletions

View file

@ -1,12 +1,15 @@
mod h1; mod header;
mod h2;
mod h3;
mod list; mod list;
mod plain; mod plain;
mod quote; mod quote;
mod title; mod title;
use gtk::{TextTag, TextTagTable}; use gtk::{TextTag, TextTagTable};
use header::Header;
use list::List;
use plain::Plain;
use quote::Quote;
use title::Title;
pub struct Tag { pub struct Tag {
pub text_tag_table: TextTagTable, pub text_tag_table: TextTagTable,
@ -30,13 +33,13 @@ impl Tag {
// Construct // Construct
pub fn new() -> Self { pub fn new() -> Self {
// Init components // Init components
let h1 = h1::new(); let h1 = TextTag::h1();
let h2 = h2::new(); let h2 = TextTag::h2();
let h3 = h3::new(); let h3 = TextTag::h3();
let list = list::new(); let list = TextTag::list();
let quote = quote::new(); let quote = TextTag::quote();
let title = title::new(); let title = TextTag::title();
let plain = plain::new(); let plain = TextTag::plain();
// Init tag table // Init tag table
let text_tag_table = TextTagTable::new(); let text_tag_table = TextTagTable::new();

View file

@ -1,11 +0,0 @@
use gtk::{TextTag, WrapMode};
pub fn new() -> TextTag {
TextTag::builder()
.foreground("#2190a4") // @TODO optional
.scale(1.6)
.sentence(true)
.weight(500)
.wrap_mode(WrapMode::Word)
.build()
}

View file

@ -1,11 +0,0 @@
use gtk::{TextTag, WrapMode};
pub fn new() -> TextTag {
TextTag::builder()
.foreground("#d56199") // @TODO optional
.scale(1.4)
.sentence(true)
.weight(400)
.wrap_mode(WrapMode::Word)
.build()
}

View file

@ -1,11 +0,0 @@
use gtk::{TextTag, WrapMode};
pub fn new() -> TextTag {
TextTag::builder()
.foreground("#c88800") // @TODO optional
.scale(1.2)
.sentence(true)
.weight(400)
.wrap_mode(WrapMode::Word)
.build()
}

View file

@ -0,0 +1,37 @@
use gtk::{TextTag, WrapMode};
pub trait Header {
fn h1() -> Self;
fn h2() -> Self;
fn h3() -> Self;
}
impl Header for TextTag {
fn h1() -> Self {
TextTag::builder()
.foreground("#2190a4") // @TODO optional
.scale(1.6)
.sentence(true)
.weight(500)
.wrap_mode(WrapMode::Word)
.build()
}
fn h2() -> Self {
TextTag::builder()
.foreground("#d56199") // @TODO optional
.scale(1.4)
.sentence(true)
.weight(400)
.wrap_mode(WrapMode::Word)
.build()
}
fn h3() -> Self {
TextTag::builder()
.foreground("#c88800") // @TODO optional
.scale(1.2)
.sentence(true)
.weight(400)
.wrap_mode(WrapMode::Word)
.build()
}
}

View file

@ -1,10 +1,16 @@
use gtk::{TextTag, WrapMode}; use gtk::{TextTag, WrapMode};
pub fn new() -> TextTag { pub trait List {
TextTag::builder() fn list() -> Self;
.left_margin(28) }
.pixels_above_lines(4)
.pixels_below_lines(4) impl List for TextTag {
.wrap_mode(WrapMode::Word) fn list() -> Self {
.build() TextTag::builder()
.left_margin(28)
.pixels_above_lines(4)
.pixels_below_lines(4)
.wrap_mode(WrapMode::Word)
.build()
}
} }

View file

@ -1,5 +1,11 @@
use gtk::{TextTag, WrapMode}; use gtk::{TextTag, WrapMode};
pub fn new() -> TextTag { pub trait Plain {
TextTag::builder().wrap_mode(WrapMode::Word).build() fn plain() -> Self;
}
impl Plain for TextTag {
fn plain() -> Self {
TextTag::builder().wrap_mode(WrapMode::Word).build()
}
} }

View file

@ -1,8 +1,14 @@
use gtk::{TextTag, WrapMode}; use gtk::{TextTag, WrapMode};
pub fn new() -> TextTag { pub trait Quote {
TextTag::builder() fn quote() -> Self;
.left_margin(28) }
.wrap_mode(WrapMode::Word)
.build() impl Quote for TextTag {
fn quote() -> Self {
TextTag::builder()
.left_margin(28)
.wrap_mode(WrapMode::Word)
.build()
}
} }

View file

@ -1,10 +1,16 @@
use gtk::{TextTag, WrapMode}; use gtk::{TextTag, WrapMode};
pub fn new() -> TextTag { pub trait Title {
TextTag::builder() fn title() -> Self;
.pixels_above_lines(4) }
.pixels_below_lines(8)
.weight(500) impl Title for TextTag {
.wrap_mode(WrapMode::None) fn title() -> Self {
.build() TextTag::builder()
.pixels_above_lines(4)
.pixels_below_lines(8)
.weight(500)
.wrap_mode(WrapMode::None)
.build()
}
} }