Browse Source

toggle cursor icon if tag contain URI

master
yggverse 2 months ago
parent
commit
0d9fc801c9
  1. 24
      src/app/browser/window/tab/item/page/content/text/gemini/reader.rs

24
src/app/browser/window/tab/item/page/content/text/gemini/reader.rs

@ -9,8 +9,7 @@ use gtk::{
gdk::{BUTTON_MIDDLE, BUTTON_PRIMARY}, gdk::{BUTTON_MIDDLE, BUTTON_PRIMARY},
gio::SimpleAction, gio::SimpleAction,
glib::{GString, TimeZone, Uri}, glib::{GString, TimeZone, Uri},
pango::Underline, prelude::{ActionExt, TextBufferExt, TextBufferExtManual, TextViewExt, ToVariant, WidgetExt},
prelude::{ActionExt, TextBufferExt, TextBufferExtManual, TextTagExt, TextViewExt, ToVariant},
EventControllerMotion, GestureClick, TextBuffer, TextTag, TextView, TextWindowType, WrapMode, EventControllerMotion, GestureClick, TextBuffer, TextTag, TextView, TextWindowType, WrapMode,
}; };
@ -139,12 +138,15 @@ impl Reader {
let gobject = widget.gobject().clone(); let gobject = widget.gobject().clone();
let _links_ = links.clone(); // is copy let _links_ = links.clone(); // is copy
move |_, _, x, y| { move |_, _, x, y| {
// Detect tag match current coords hovered
let (window_x, window_y) = let (window_x, window_y) =
gobject.window_to_buffer_coords(TextWindowType::Widget, x as i32, y as i32); gobject.window_to_buffer_coords(TextWindowType::Widget, x as i32, y as i32);
if let Some(iter) = gobject.iter_at_location(window_x, window_y) { if let Some(iter) = gobject.iter_at_location(window_x, window_y) {
for tag in iter.tags() { for tag in iter.tags() {
// Detect links on tag contain URI
if let Some(uri) = _links_.get(&tag) { if let Some(uri) = _links_.get(&tag) {
// Select handler by scheme
match uri.scheme().as_str() { match uri.scheme().as_str() {
"gemini" => { "gemini" => {
// Open new page // Open new page
@ -162,27 +164,21 @@ impl Reader {
let gobject = widget.gobject().clone(); let gobject = widget.gobject().clone();
let _links_ = links.clone(); // is copy let _links_ = links.clone(); // is copy
move |_, x, y| { move |_, x, y| {
// Remove underline decoration from all tags
gobject.buffer().tag_table().foreach(|tag| {
tag.set_underline(Underline::None);
});
// Detect tag match current coords hovered // Detect tag match current coords hovered
let (window_x, window_y) = let (window_x, window_y) =
gobject.window_to_buffer_coords(TextWindowType::Widget, x as i32, y as i32); gobject.window_to_buffer_coords(TextWindowType::Widget, x as i32, y as i32);
if let Some(iter) = gobject.iter_at_location(window_x, window_y) { if let Some(iter) = gobject.iter_at_location(window_x, window_y) {
for tag in iter.tags() { for tag in iter.tags() {
// Show underline if tag contain URI (is link) // Toggle cursor icon if tag contain URI (is link)
if let Some(_) = _links_.get(&tag) { match _links_.get(&tag) {
tag.set_underline(Underline::Single); Some(_) => gobject.set_cursor_from_name(Some("pointer")), // @TODO Show tooltip
None => gobject.set_cursor_from_name(Some("text")),
// @TODO Show tooltip
} }
} }
} }
} // @TODO expensive for CPU }
}); }); // @TODO may be expensive for CPU
// @TODO // @TODO
// middle_button_controller(|_, _, _, _| {}); // middle_button_controller(|_, _, _, _| {});

Loading…
Cancel
Save