draft horizontal separator for code (alternative to PR#18)

This commit is contained in:
yggverse 2026-03-23 02:08:48 +02:00
parent e92eb318b3
commit 026a8fbab6
5 changed files with 35 additions and 15 deletions

View file

@ -2,6 +2,7 @@ mod ansi;
pub mod error; pub mod error;
mod gutter; mod gutter;
mod icon; mod icon;
mod separator;
mod syntax; mod syntax;
mod tag; mod tag;
@ -146,16 +147,17 @@ impl Gemini {
None => None, None => None,
}; };
text_view.add_child_at_anchor(
&separator::horizontal(&text_view),
&buffer.create_child_anchor(&mut buffer.end_iter()),
);
// Begin code block construction // Begin code block construction
// Try auto-detect code syntax for given `value` and `alt` @TODO optional // Try auto-detect code syntax for given `value` and `alt` @TODO optional
match syntax.highlight(&c.value, alt) { match syntax.highlight(&c.value, alt) {
Ok(highlight) => { Ok(highlight) => {
for (syntax_tag, entity) in highlight { for (syntax_tag, entity) in highlight {
// Register new tag assert!(tag.text_tag_table.add(&syntax_tag));
if !tag.text_tag_table.add(&syntax_tag) {
todo!()
}
// Append tag to buffer
buffer.insert_with_tags( buffer.insert_with_tags(
&mut buffer.end_iter(), &mut buffer.end_iter(),
&entity, &entity,
@ -166,11 +168,7 @@ impl Gemini {
Err(_) => { Err(_) => {
// Try ANSI/SGR format (terminal emulation) @TODO optional // Try ANSI/SGR format (terminal emulation) @TODO optional
for (syntax_tag, entity) in ansi::format(&c.value) { for (syntax_tag, entity) in ansi::format(&c.value) {
// Register new tag assert!(tag.text_tag_table.add(&syntax_tag));
if !tag.text_tag_table.add(&syntax_tag) {
todo!()
}
// Append tag to buffer
buffer.insert_with_tags( buffer.insert_with_tags(
&mut buffer.end_iter(), &mut buffer.end_iter(),
&entity, &entity,
@ -180,6 +178,11 @@ impl Gemini {
} // @TODO handle } // @TODO handle
} }
text_view.add_child_at_anchor(
&separator::horizontal(&text_view),
&buffer.create_child_anchor(&mut buffer.end_iter()),
);
// Reset // Reset
code = None; code = None;
} }
@ -187,7 +190,7 @@ impl Gemini {
// Skip other actions for this line // Skip other actions for this line
continue; continue;
} }
Err(_) => todo!(), Err(_) => panic!(),
} }
} }
} }

View file

@ -20,7 +20,7 @@ impl Tag {
Self { Self {
text_tag: TextTag::builder() text_tag: TextTag::builder()
.family("monospace") // @TODO .family("monospace") // @TODO
.left_margin(28) //.left_margin(28)
.scale(0.81) // * the rounded `0.8` value crops text for some reason @TODO .scale(0.81) // * the rounded `0.8` value crops text for some reason @TODO
.wrap_mode(WrapMode::None) .wrap_mode(WrapMode::None)
.build(), .build(),

View file

@ -0,0 +1,19 @@
use gtk::{Separator, prelude::WidgetExt};
pub fn horizontal(text_view: &gtk::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
}

View file

@ -20,7 +20,7 @@ impl Tag {
Self { Self {
text_tag: TextTag::builder() text_tag: TextTag::builder()
.family("monospace") // @TODO .family("monospace") // @TODO
.left_margin(28) //.left_margin(28)
.scale(0.81) // * the rounded `0.8` value crops text for some reason @TODO .scale(0.81) // * the rounded `0.8` value crops text for some reason @TODO
.wrap_mode(WrapMode::None) .wrap_mode(WrapMode::None)
.build(), .build(),

View file

@ -7,8 +7,6 @@ pub trait Title {
impl Title for TextTag { impl Title for TextTag {
fn title() -> Self { fn title() -> Self {
TextTag::builder() TextTag::builder()
.pixels_above_lines(4)
.pixels_below_lines(8)
.weight(500) .weight(500)
.wrap_mode(WrapMode::None) .wrap_mode(WrapMode::None)
.build() .build()