Generalize Text element to let you add arbitrary scene primitives for runs of text

This commit is contained in:
Max Brunsfeld 2023-04-27 13:58:06 -07:00
parent 66d4cb8c14
commit 8eb9c6563a
2 changed files with 67 additions and 75 deletions

View file

@ -2,8 +2,8 @@ use gpui::{
color::Color,
elements::Text,
fonts::{HighlightStyle, TextStyle},
platform::MouseButton,
AnyElement, Element, MouseRegion,
platform::{CursorStyle, MouseButton},
AnyElement, CursorRegion, Element, MouseRegion,
};
use log::LevelFilter;
use simplelog::SimpleLogger;
@ -61,13 +61,19 @@ impl gpui::View for TextView {
},
)
.with_highlights(vec![(17..26, underline), (34..40, underline)])
.with_mouse_regions(vec![(17..26), (34..40)], move |ix, bounds| {
MouseRegion::new::<Self>(view_id, ix, bounds).on_click::<Self, _>(
MouseButton::Left,
move |_, _, _| {
eprintln!("clicked link {ix}");
},
)
.with_custom_runs(vec![(17..26), (34..40)], move |ix, bounds, scene, _| {
scene.push_cursor_region(CursorRegion {
bounds,
style: CursorStyle::PointingHand,
});
scene.push_mouse_region(
MouseRegion::new::<Self>(view_id, ix, bounds).on_click::<Self, _>(
MouseButton::Left,
move |_, _, _| {
eprintln!("clicked link {ix}");
},
),
);
})
.into_any()
}