Get playground app launching

Not sure if it should be in the workspace, but it's easier for now.

Co-Authored-By: Derek Briggs <derek.briggs@me.com>
This commit is contained in:
Nathan Sobo 2023-07-14 15:34:31 -06:00
parent 4b2054215a
commit 87bafb04e2
5 changed files with 3022 additions and 0 deletions

9
Cargo.lock generated
View file

@ -5037,6 +5037,15 @@ version = "0.3.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964"
[[package]]
name = "playground"
version = "0.1.0"
dependencies = [
"gpui",
"log",
"simplelog",
]
[[package]]
name = "plist"
version = "1.5.0"

View file

@ -28,6 +28,7 @@ members = [
"crates/git",
"crates/go_to_line",
"crates/gpui",
"crates/gpui/playground",
"crates/gpui_macros",
"crates/install_cli",
"crates/journal",

2919
crates/gpui/playground/Cargo.lock generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,13 @@
[[bin]]
name = "playground"
path = "src/playground.rs"
[package]
name = "playground"
version = "0.1.0"
edition = "2021"
[dependencies]
gpui = { path = ".." }
log.workspace = true
simplelog = "0.9"

View file

@ -0,0 +1,80 @@
use gpui::{
color::Color,
elements::Text,
fonts::{HighlightStyle, TextStyle},
platform::{CursorStyle, MouseButton},
AnyElement, CursorRegion, Element, MouseRegion,
};
use log::LevelFilter;
use simplelog::SimpleLogger;
fn main() {
SimpleLogger::init(LevelFilter::Info, Default::default()).expect("could not initialize logger");
gpui::App::new(()).unwrap().run(|cx| {
cx.platform().activate(true);
cx.add_window(Default::default(), |_| TextView);
});
}
struct TextView;
impl gpui::Entity for TextView {
type Event = ();
}
impl gpui::View for TextView {
fn ui_name() -> &'static str {
"View"
}
fn render(&mut self, cx: &mut gpui::ViewContext<Self>) -> AnyElement<TextView> {
let font_size = 12.;
let family = cx
.font_cache
.load_family(&["Monaco"], &Default::default())
.unwrap();
let font_id = cx
.font_cache
.select_font(family, &Default::default())
.unwrap();
let view_id = cx.view_id();
let underline = HighlightStyle {
underline: Some(gpui::fonts::Underline {
thickness: 1.0.into(),
..Default::default()
}),
..Default::default()
};
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(),
},
)
.with_highlights(vec![(17..26, underline), (34..40, underline)])
.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()
}
}