mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-03-31 08:35:28 +00:00
draft horizontal separator for code (alternative to PR#18)
This commit is contained in:
parent
e92eb318b3
commit
026a8fbab6
5 changed files with 35 additions and 15 deletions
|
|
@ -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!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
@ -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(),
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue