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:
parent
4b2054215a
commit
87bafb04e2
5 changed files with 3022 additions and 0 deletions
9
Cargo.lock
generated
9
Cargo.lock
generated
|
@ -5037,6 +5037,15 @@ version = "0.3.27"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964"
|
checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "playground"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"gpui",
|
||||||
|
"log",
|
||||||
|
"simplelog",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "plist"
|
name = "plist"
|
||||||
version = "1.5.0"
|
version = "1.5.0"
|
||||||
|
|
|
@ -28,6 +28,7 @@ members = [
|
||||||
"crates/git",
|
"crates/git",
|
||||||
"crates/go_to_line",
|
"crates/go_to_line",
|
||||||
"crates/gpui",
|
"crates/gpui",
|
||||||
|
"crates/gpui/playground",
|
||||||
"crates/gpui_macros",
|
"crates/gpui_macros",
|
||||||
"crates/install_cli",
|
"crates/install_cli",
|
||||||
"crates/journal",
|
"crates/journal",
|
||||||
|
|
2919
crates/gpui/playground/Cargo.lock
generated
Normal file
2919
crates/gpui/playground/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
13
crates/gpui/playground/Cargo.toml
Normal file
13
crates/gpui/playground/Cargo.toml
Normal 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"
|
80
crates/gpui/playground/src/playground.rs
Normal file
80
crates/gpui/playground/src/playground.rs
Normal 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()
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue