gpui: Make image
example work regardless of how it is run (#24645)
This PR updates the GPUI `image` example such that it works when run in the following ways: - `cargo run -p gpui --example image` from the repository root - `cargo run --example image` from within `crates/gpui` Release Notes: - N/A
This commit is contained in:
parent
6a40a400bd
commit
04d65cb3cd
3 changed files with 14 additions and 9 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -5546,6 +5546,7 @@ dependencies = [
|
||||||
"rand 0.8.5",
|
"rand 0.8.5",
|
||||||
"raw-window-handle",
|
"raw-window-handle",
|
||||||
"refineable",
|
"refineable",
|
||||||
|
"reqwest_client",
|
||||||
"resvg",
|
"resvg",
|
||||||
"schemars",
|
"schemars",
|
||||||
"seahash",
|
"seahash",
|
||||||
|
|
|
@ -202,11 +202,12 @@ windows-core = "0.58"
|
||||||
backtrace = "0.3"
|
backtrace = "0.3"
|
||||||
collections = { workspace = true, features = ["test-support"] }
|
collections = { workspace = true, features = ["test-support"] }
|
||||||
env_logger.workspace = true
|
env_logger.workspace = true
|
||||||
rand.workspace = true
|
|
||||||
util = { workspace = true, features = ["test-support"] }
|
|
||||||
http_client = { workspace = true, features = ["test-support"] }
|
http_client = { workspace = true, features = ["test-support"] }
|
||||||
unicode-segmentation.workspace = true
|
|
||||||
lyon = { version = "1.0", features = ["extra"] }
|
lyon = { version = "1.0", features = ["extra"] }
|
||||||
|
rand.workspace = true
|
||||||
|
unicode-segmentation.workspace = true
|
||||||
|
reqwest_client = { workspace = true, features = ["test-support"] }
|
||||||
|
util = { workspace = true, features = ["test-support"] }
|
||||||
|
|
||||||
[target.'cfg(target_os = "windows")'.build-dependencies]
|
[target.'cfg(target_os = "windows")'.build-dependencies]
|
||||||
embed-resource = "3.0"
|
embed-resource = "3.0"
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::str::FromStr;
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
@ -9,6 +8,7 @@ use gpui::{
|
||||||
Bounds, Context, ImageSource, KeyBinding, Menu, MenuItem, Point, SharedString, SharedUri,
|
Bounds, Context, ImageSource, KeyBinding, Menu, MenuItem, Point, SharedString, SharedUri,
|
||||||
TitlebarOptions, Window, WindowBounds, WindowOptions,
|
TitlebarOptions, Window, WindowBounds, WindowOptions,
|
||||||
};
|
};
|
||||||
|
use reqwest_client::ReqwestClient;
|
||||||
|
|
||||||
struct Assets {
|
struct Assets {
|
||||||
base: PathBuf,
|
base: PathBuf,
|
||||||
|
@ -127,11 +127,16 @@ actions!(image, [Quit]);
|
||||||
fn main() {
|
fn main() {
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
|
|
||||||
|
let manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
||||||
|
|
||||||
Application::new()
|
Application::new()
|
||||||
.with_assets(Assets {
|
.with_assets(Assets {
|
||||||
base: PathBuf::from("crates/gpui/examples"),
|
base: manifest_dir.join("examples"),
|
||||||
})
|
})
|
||||||
.run(|cx: &mut App| {
|
.run(move |cx: &mut App| {
|
||||||
|
let http_client = ReqwestClient::user_agent("gpui example").unwrap();
|
||||||
|
cx.set_http_client(Arc::new(http_client));
|
||||||
|
|
||||||
cx.activate(true);
|
cx.activate(true);
|
||||||
cx.on_action(|_: &Quit, cx| cx.quit());
|
cx.on_action(|_: &Quit, cx| cx.quit());
|
||||||
cx.bind_keys([KeyBinding::new("cmd-q", Quit, None)]);
|
cx.bind_keys([KeyBinding::new("cmd-q", Quit, None)]);
|
||||||
|
@ -158,9 +163,7 @@ fn main() {
|
||||||
cx.open_window(window_options, |_, cx| {
|
cx.open_window(window_options, |_, cx| {
|
||||||
cx.new(|_| ImageShowcase {
|
cx.new(|_| ImageShowcase {
|
||||||
// Relative path to your root project path
|
// Relative path to your root project path
|
||||||
local_resource: PathBuf::from_str("crates/gpui/examples/image/app-icon.png")
|
local_resource: manifest_dir.join("examples/image/app-icon.png").into(),
|
||||||
.unwrap()
|
|
||||||
.into(),
|
|
||||||
|
|
||||||
remote_resource: "https://picsum.photos/512/512".into(),
|
remote_resource: "https://picsum.photos/512/512".into(),
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue