2021-04-03 07:19:20 +00:00
|
|
|
use gpui::{
|
2021-08-03 19:48:58 +00:00
|
|
|
color::Color,
|
2023-04-26 00:23:55 +00:00
|
|
|
elements::Text,
|
|
|
|
fonts::{HighlightStyle, TextStyle},
|
2023-04-27 20:58:06 +00:00
|
|
|
platform::{CursorStyle, MouseButton},
|
|
|
|
AnyElement, CursorRegion, Element, MouseRegion,
|
2021-04-03 07:19:20 +00:00
|
|
|
};
|
|
|
|
use log::LevelFilter;
|
|
|
|
use simplelog::SimpleLogger;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
SimpleLogger::init(LevelFilter::Info, Default::default()).expect("could not initialize logger");
|
|
|
|
|
2021-05-28 22:25:15 +00:00
|
|
|
gpui::App::new(()).unwrap().run(|cx| {
|
|
|
|
cx.platform().activate(true);
|
2021-08-05 17:48:35 +00:00
|
|
|
cx.add_window(Default::default(), |_| TextView);
|
2021-04-10 03:33:17 +00:00
|
|
|
});
|
2021-04-03 07:19:20 +00:00
|
|
|
}
|
|
|
|
|
2021-04-06 12:30:05 +00:00
|
|
|
struct TextView;
|
2021-04-03 07:19:20 +00:00
|
|
|
|
2021-04-06 12:30:05 +00:00
|
|
|
impl gpui::Entity for TextView {
|
2021-04-03 07:19:20 +00:00
|
|
|
type Event = ();
|
|
|
|
}
|
|
|
|
|
2021-04-06 12:30:05 +00:00
|
|
|
impl gpui::View for TextView {
|
2021-04-03 07:19:20 +00:00
|
|
|
fn ui_name() -> &'static str {
|
2021-04-06 12:30:05 +00:00
|
|
|
"View"
|
2021-04-03 07:19:20 +00:00
|
|
|
}
|
|
|
|
|
2023-04-26 00:23:55 +00:00
|
|
|
fn render(&mut self, cx: &mut gpui::ViewContext<Self>) -> AnyElement<TextView> {
|
2021-04-06 12:30:05 +00:00
|
|
|
let font_size = 12.;
|
2023-03-17 08:51:07 +00:00
|
|
|
let family = cx
|
|
|
|
.font_cache
|
2023-04-26 00:23:55 +00:00
|
|
|
.load_family(&["Monaco"], &Default::default())
|
2023-03-17 08:51:07 +00:00
|
|
|
.unwrap();
|
2023-04-26 00:23:55 +00:00
|
|
|
let font_id = cx
|
|
|
|
.font_cache
|
|
|
|
.select_font(family, &Default::default())
|
|
|
|
.unwrap();
|
|
|
|
let view_id = cx.view_id();
|
2021-04-03 07:19:20 +00:00
|
|
|
|
2023-04-26 00:23:55 +00:00
|
|
|
let underline = HighlightStyle {
|
|
|
|
underline: Some(gpui::fonts::Underline {
|
|
|
|
thickness: 1.0.into(),
|
|
|
|
..Default::default()
|
|
|
|
}),
|
2021-04-06 12:30:05 +00:00
|
|
|
..Default::default()
|
2023-04-26 00:23:55 +00:00
|
|
|
};
|
2022-07-21 15:35:40 +00:00
|
|
|
|
2023-04-26 00:23:55 +00:00
|
|
|
Text::new(
|
|
|
|
"The text:\nHello, beautiful world, hello!",
|
|
|
|
TextStyle {
|
|
|
|
font_id,
|
|
|
|
font_size,
|
|
|
|
color: Color::red(),
|
|
|
|
font_family_name: "".into(),
|
|
|
|
font_family_id: family,
|
|
|
|
underline: Default::default(),
|
|
|
|
font_properties: Default::default(),
|
2023-07-26 18:54:23 +00:00
|
|
|
soft_wrap: false,
|
2023-04-26 00:23:55 +00:00
|
|
|
},
|
|
|
|
)
|
|
|
|
.with_highlights(vec![(17..26, underline), (34..40, underline)])
|
2023-04-27 20:58:06 +00:00
|
|
|
.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}");
|
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
2023-04-26 00:23:55 +00:00
|
|
|
})
|
|
|
|
.into_any()
|
2021-04-07 05:50:13 +00:00
|
|
|
}
|
2021-04-03 07:19:20 +00:00
|
|
|
}
|