Skip to content

Commit

Permalink
implement indicator icons, update quotes decoration
Browse files Browse the repository at this point in the history
  • Loading branch information
yggverse committed Jan 28, 2025
1 parent 7b624f7 commit ab6375a
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
20 changes: 20 additions & 0 deletions src/app/browser/window/tab/item/page/content/text/gemini/reader.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
mod ansi;
pub mod error;
mod icon;
mod syntax;
mod tag;
mod widget;

pub use error::Error;
use icon::Icon;
use syntax::Syntax;
use tag::Tag;
use widget::Widget;
Expand Down Expand Up @@ -58,13 +60,19 @@ impl Reader {
// Init multiline code builder features
let mut multiline = None;

// Init quote icon feature
let mut is_line_after_quote = false;

// Init colors
// @TODO use accent colors in adw 1.6 / ubuntu 24.10+
let link_color = (RGBA::new(0.2, 0.5, 0.9, 1.0), RGBA::new(0.2, 0.5, 0.9, 0.9));

// Init syntect highlight features
let syntax = Syntax::new();

// Init icons
let icon = Icon::new();

// Init tags
let tag = Tag::new();

Expand Down Expand Up @@ -282,12 +290,24 @@ impl Reader {

// Is quote
if let Some(quote) = Quote::from(line) {
// Show quote indicator if last line is not quote (to prevent duplicates)
if !is_line_after_quote {
// Show only if the icons resolved for default `Display`
if let Some(ref icon) = icon {
buffer.insert_paintable(&mut buffer.end_iter(), &icon.quote);
buffer.insert(&mut buffer.end_iter(), NEW_LINE);
}
}
is_line_after_quote = true;

// Append value to buffer
buffer.insert_with_tags(&mut buffer.end_iter(), &quote.value, &[&tag.quote]);
buffer.insert(&mut buffer.end_iter(), NEW_LINE);

// Skip other actions for this line
continue;
} else {
is_line_after_quote = false;
}

// Nothing match custom tags above,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use gtk::{gdk::Display, IconLookupFlags, IconPaintable, IconTheme, TextDirection};

const SIZE: i32 = 16;

/// Indication icons asset (for tag blocks decoration)
pub struct Icon {
pub quote: IconPaintable,
// @TODO other tags..
}

impl Icon {
pub fn new() -> Option<Self> {
Display::default().map(|display| {
let theme = IconTheme::for_display(&display);
Self {
quote: icon(&theme, "mail-forward-symbolic"),
}
})
}
}

fn icon(theme: &IconTheme, name: &str) -> IconPaintable {
theme.lookup_icon(
name,
&[], // @TODO
SIZE,
SIZE,
TextDirection::None,
IconLookupFlags::FORCE_SYMBOLIC,
)
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use gtk::{pango::Style, TextTag, WrapMode};
use gtk::{TextTag, WrapMode};

pub fn new() -> TextTag {
TextTag::builder()
.style(Style::Italic)
.left_margin(28)
.wrap_mode(WrapMode::Word)
.build()
}

0 comments on commit ab6375a

Please sign in to comment.