From 026a8fbab6003c10b750ff5691b2f8d143ea1e86 Mon Sep 17 00:00:00 2001 From: yggverse Date: Mon, 23 Mar 2026 02:08:48 +0200 Subject: [PATCH] draft horizontal separator for code (alternative to PR#18) --- .../tab/item/page/content/text/gemini.rs | 25 +++++++++++-------- .../item/page/content/text/gemini/ansi/tag.rs | 2 +- .../page/content/text/gemini/separator.rs | 19 ++++++++++++++ .../page/content/text/gemini/syntax/tag.rs | 2 +- .../page/content/text/gemini/tag/title.rs | 2 -- 5 files changed, 35 insertions(+), 15 deletions(-) create mode 100644 src/app/browser/window/tab/item/page/content/text/gemini/separator.rs diff --git a/src/app/browser/window/tab/item/page/content/text/gemini.rs b/src/app/browser/window/tab/item/page/content/text/gemini.rs index 6a09513c..ceceeb17 100644 --- a/src/app/browser/window/tab/item/page/content/text/gemini.rs +++ b/src/app/browser/window/tab/item/page/content/text/gemini.rs @@ -2,6 +2,7 @@ mod ansi; pub mod error; mod gutter; mod icon; +mod separator; mod syntax; mod tag; @@ -146,16 +147,17 @@ impl Gemini { None => None, }; + text_view.add_child_at_anchor( + &separator::horizontal(&text_view), + &buffer.create_child_anchor(&mut buffer.end_iter()), + ); + // Begin code block construction // Try auto-detect code syntax for given `value` and `alt` @TODO optional match syntax.highlight(&c.value, alt) { Ok(highlight) => { for (syntax_tag, entity) in highlight { - // Register new tag - if !tag.text_tag_table.add(&syntax_tag) { - todo!() - } - // Append tag to buffer + assert!(tag.text_tag_table.add(&syntax_tag)); buffer.insert_with_tags( &mut buffer.end_iter(), &entity, @@ -166,11 +168,7 @@ impl Gemini { Err(_) => { // Try ANSI/SGR format (terminal emulation) @TODO optional for (syntax_tag, entity) in ansi::format(&c.value) { - // Register new tag - if !tag.text_tag_table.add(&syntax_tag) { - todo!() - } - // Append tag to buffer + assert!(tag.text_tag_table.add(&syntax_tag)); buffer.insert_with_tags( &mut buffer.end_iter(), &entity, @@ -180,6 +178,11 @@ impl Gemini { } // @TODO handle } + text_view.add_child_at_anchor( + &separator::horizontal(&text_view), + &buffer.create_child_anchor(&mut buffer.end_iter()), + ); + // Reset code = None; } @@ -187,7 +190,7 @@ impl Gemini { // Skip other actions for this line continue; } - Err(_) => todo!(), + Err(_) => panic!(), } } } diff --git a/src/app/browser/window/tab/item/page/content/text/gemini/ansi/tag.rs b/src/app/browser/window/tab/item/page/content/text/gemini/ansi/tag.rs index 7154b1f3..73583704 100644 --- a/src/app/browser/window/tab/item/page/content/text/gemini/ansi/tag.rs +++ b/src/app/browser/window/tab/item/page/content/text/gemini/ansi/tag.rs @@ -20,7 +20,7 @@ impl Tag { Self { text_tag: TextTag::builder() .family("monospace") // @TODO - .left_margin(28) + //.left_margin(28) .scale(0.81) // * the rounded `0.8` value crops text for some reason @TODO .wrap_mode(WrapMode::None) .build(), diff --git a/src/app/browser/window/tab/item/page/content/text/gemini/separator.rs b/src/app/browser/window/tab/item/page/content/text/gemini/separator.rs new file mode 100644 index 00000000..80070be0 --- /dev/null +++ b/src/app/browser/window/tab/item/page/content/text/gemini/separator.rs @@ -0,0 +1,19 @@ +use gtk::{Separator, prelude::WidgetExt}; + +pub fn horizontal(text_view: >k::TextView) -> Separator { + const MARGIN: i32 = 8; + let separator = Separator::builder() + .margin_bottom(MARGIN) + .margin_top(MARGIN) + .orientation(gtk::Orientation::Horizontal) + .build(); + gtk::glib::idle_add_local({ + let text_view = text_view.clone(); + let separator = separator.clone(); + move || { + separator.set_width_request(text_view.width() - 18); + gtk::glib::ControlFlow::Break + } + }); + separator +} diff --git a/src/app/browser/window/tab/item/page/content/text/gemini/syntax/tag.rs b/src/app/browser/window/tab/item/page/content/text/gemini/syntax/tag.rs index 4b2011b8..bf7c8959 100644 --- a/src/app/browser/window/tab/item/page/content/text/gemini/syntax/tag.rs +++ b/src/app/browser/window/tab/item/page/content/text/gemini/syntax/tag.rs @@ -20,7 +20,7 @@ impl Tag { Self { text_tag: TextTag::builder() .family("monospace") // @TODO - .left_margin(28) + //.left_margin(28) .scale(0.81) // * the rounded `0.8` value crops text for some reason @TODO .wrap_mode(WrapMode::None) .build(), diff --git a/src/app/browser/window/tab/item/page/content/text/gemini/tag/title.rs b/src/app/browser/window/tab/item/page/content/text/gemini/tag/title.rs index ed0072fe..a2197484 100644 --- a/src/app/browser/window/tab/item/page/content/text/gemini/tag/title.rs +++ b/src/app/browser/window/tab/item/page/content/text/gemini/tag/title.rs @@ -7,8 +7,6 @@ pub trait Title { impl Title for TextTag { fn title() -> Self { TextTag::builder() - .pixels_above_lines(4) - .pixels_below_lines(8) .weight(500) .wrap_mode(WrapMode::None) .build()