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 h2;
mod h3;
mod header;
mod list;
mod plain;
mod quote;
mod title;
use gtk::{TextTag, TextTagTable};
use header::Header;
use list::List;
use plain::Plain;
use quote::Quote;
use title::Title;
pub struct Tag {
pub text_tag_table: TextTagTable,
@ -30,13 +33,13 @@ impl Tag {
// Construct
pub fn new() -> Self {
// Init components
let h1 = h1::new();
let h2 = h2::new();
let h3 = h3::new();
let list = list::new();
let quote = quote::new();
let title = title::new();
let plain = plain::new();
let h1 = TextTag::h1();
let h2 = TextTag::h2();
let h3 = TextTag::h3();
let list = TextTag::list();
let quote = TextTag::quote();
let title = TextTag::title();
let plain = TextTag::plain();
// Init tag table
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};
pub fn new() -> TextTag {
TextTag::builder()
.left_margin(28)
.pixels_above_lines(4)
.pixels_below_lines(4)
.wrap_mode(WrapMode::Word)
.build()
pub trait List {
fn list() -> Self;
}
impl List for TextTag {
fn list() -> Self {
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};
pub fn new() -> TextTag {
TextTag::builder().wrap_mode(WrapMode::Word).build()
pub trait Plain {
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};
pub fn new() -> TextTag {
TextTag::builder()
.left_margin(28)
.wrap_mode(WrapMode::Word)
.build()
pub trait Quote {
fn quote() -> Self;
}
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};
pub fn new() -> TextTag {
TextTag::builder()
.pixels_above_lines(4)
.pixels_below_lines(8)
.weight(500)
.wrap_mode(WrapMode::None)
.build()
pub trait Title {
fn title() -> Self;
}
impl Title for TextTag {
fn title() -> Self {
TextTag::builder()
.pixels_above_lines(4)
.pixels_below_lines(8)
.weight(500)
.wrap_mode(WrapMode::None)
.build()
}
}