remove extra struct wrapper for tags

This commit is contained in:
yggverse 2024-12-17 03:36:19 +02:00
parent bdab2d2ded
commit cc9b86caf3
9 changed files with 71 additions and 142 deletions

View File

@ -141,7 +141,7 @@ impl Reader {
buffer.insert_with_tags(
&mut buffer.end_iter(),
alt.as_str(),
&[&tag.title.text_tag],
&[&tag.title],
);
// Append new line after alt text
@ -206,9 +206,9 @@ impl Reader {
&mut buffer.end_iter(),
header.value.as_str(),
&[match header.level {
Level::H1 => &tag.h1.text_tag,
Level::H2 => &tag.h2.text_tag,
Level::H3 => &tag.h3.text_tag,
Level::H1 => &tag.h1,
Level::H2 => &tag.h2,
Level::H3 => &tag.h3,
}],
);
buffer.insert(&mut buffer.end_iter(), NEW_LINE);
@ -278,7 +278,7 @@ impl Reader {
buffer.insert_with_tags(
&mut buffer.end_iter(),
format!("{LIST_ITEM} {}", list.value).as_str(),
&[&tag.list.text_tag],
&[&tag.list],
);
buffer.insert(&mut buffer.end_iter(), NEW_LINE);
@ -292,7 +292,7 @@ impl Reader {
buffer.insert_with_tags(
&mut buffer.end_iter(),
quote.value.as_str(),
&[&tag.quote.text_tag],
&[&tag.quote],
);
buffer.insert(&mut buffer.end_iter(), NEW_LINE);
@ -302,7 +302,7 @@ impl Reader {
// Nothing match custom tags above,
// just append plain text covered in empty tag (to handle controller events properly)
buffer.insert_with_tags(&mut buffer.end_iter(), line, &[&tag.plain.text_tag]);
buffer.insert_with_tags(&mut buffer.end_iter(), line, &[&tag.plain]);
buffer.insert(&mut buffer.end_iter(), NEW_LINE);
}

View File

@ -6,50 +6,42 @@ mod plain;
mod quote;
mod title;
use h1::H1;
use h2::H2;
use h3::H3;
use list::List;
use plain::Plain;
use quote::Quote;
use title::Title;
use gtk::TextTagTable;
use gtk::{TextTag, TextTagTable};
pub struct Tag {
pub text_tag_table: TextTagTable,
// Tags
pub h1: H1,
pub h2: H2,
pub h3: H3,
pub list: List,
pub quote: Quote,
pub title: Title,
pub plain: Plain,
pub h1: TextTag,
pub h2: TextTag,
pub h3: TextTag,
pub list: TextTag,
pub quote: TextTag,
pub title: TextTag,
pub plain: TextTag,
}
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 = 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();
// Init tag table
let text_tag_table = TextTagTable::new();
text_tag_table.add(&h1.text_tag);
text_tag_table.add(&h2.text_tag);
text_tag_table.add(&h3.text_tag);
text_tag_table.add(&title.text_tag);
text_tag_table.add(&list.text_tag);
text_tag_table.add(&quote.text_tag);
text_tag_table.add(&plain.text_tag);
text_tag_table.add(&h1);
text_tag_table.add(&h2);
text_tag_table.add(&h3);
text_tag_table.add(&title);
text_tag_table.add(&list);
text_tag_table.add(&quote);
text_tag_table.add(&plain);
Self {
text_tag_table,

View File

@ -1,19 +1,10 @@
use gtk::{TextTag, WrapMode};
pub struct H1 {
pub text_tag: TextTag,
}
impl H1 {
// Construct
pub fn new() -> Self {
Self {
text_tag: TextTag::builder()
.scale(1.6)
.sentence(true)
.weight(500)
.wrap_mode(WrapMode::Word)
.build(),
}
}
pub fn new() -> TextTag {
TextTag::builder()
.scale(1.6)
.sentence(true)
.weight(500)
.wrap_mode(WrapMode::Word)
.build()
}

View File

@ -1,19 +1,10 @@
use gtk::{TextTag, WrapMode};
pub struct H2 {
pub text_tag: TextTag,
}
impl H2 {
// Construct
pub fn new() -> Self {
Self {
text_tag: TextTag::builder()
.scale(1.4)
.sentence(true)
.weight(400)
.wrap_mode(WrapMode::Word)
.build(),
}
}
pub fn new() -> TextTag {
TextTag::builder()
.scale(1.4)
.sentence(true)
.weight(400)
.wrap_mode(WrapMode::Word)
.build()
}

View File

@ -1,19 +1,10 @@
use gtk::{TextTag, WrapMode};
pub struct H3 {
pub text_tag: TextTag,
}
impl H3 {
// Construct
pub fn new() -> Self {
Self {
text_tag: TextTag::builder()
.scale(1.2)
.sentence(true)
.weight(400)
.wrap_mode(WrapMode::Word)
.build(),
}
}
pub fn new() -> TextTag {
TextTag::builder()
.scale(1.2)
.sentence(true)
.weight(400)
.wrap_mode(WrapMode::Word)
.build()
}

View File

@ -1,19 +1,10 @@
use gtk::{TextTag, WrapMode};
pub struct List {
pub text_tag: TextTag,
}
impl List {
// Construct
pub fn new() -> Self {
Self {
text_tag: TextTag::builder()
.left_margin(28)
.pixels_above_lines(4)
.pixels_below_lines(4)
.wrap_mode(WrapMode::Word)
.build(),
}
}
pub fn new() -> TextTag {
TextTag::builder()
.left_margin(28)
.pixels_above_lines(4)
.pixels_below_lines(4)
.wrap_mode(WrapMode::Word)
.build()
}

View File

@ -1,14 +1,5 @@
use gtk::{TextTag, WrapMode};
pub struct Plain {
pub text_tag: TextTag,
}
impl Plain {
// Construct
pub fn new() -> Self {
Self {
text_tag: TextTag::builder().wrap_mode(WrapMode::Word).build(),
}
}
pub fn new() -> TextTag {
TextTag::builder().wrap_mode(WrapMode::Word).build()
}

View File

@ -1,17 +1,8 @@
use gtk::{pango::Style, TextTag, WrapMode};
pub struct Quote {
pub text_tag: TextTag,
}
impl Quote {
// Construct
pub fn new() -> Self {
Self {
text_tag: TextTag::builder()
.style(Style::Italic)
.wrap_mode(WrapMode::Word)
.build(),
}
}
pub fn new() -> TextTag {
TextTag::builder()
.style(Style::Italic)
.wrap_mode(WrapMode::Word)
.build()
}

View File

@ -1,19 +1,10 @@
use gtk::{TextTag, WrapMode};
pub struct Title {
pub text_tag: TextTag,
}
impl Title {
// Construct
pub fn new() -> Self {
Self {
text_tag: TextTag::builder()
.pixels_above_lines(4)
.pixels_below_lines(8)
.weight(500)
.wrap_mode(WrapMode::None)
.build(),
}
}
pub fn new() -> TextTag {
TextTag::builder()
.pixels_above_lines(4)
.pixels_below_lines(8)
.weight(500)
.wrap_mode(WrapMode::None)
.build()
}