-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
647038a
commit 7d46e19
Showing
6 changed files
with
134 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,7 @@ jobs: | |
fail-fast: false | ||
matrix: | ||
rust-toolchain: | ||
- nightly | ||
- stable | ||
|
||
steps: | ||
- name: Get source code | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[toolchain] | ||
channel = "stable" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
max_width = 100 | ||
indent_style = "Block" | ||
use_try_shorthand = true | ||
reorder_impl_items = true | ||
use_small_heuristics = "Max" | ||
imports_granularity = "Crate" | ||
use_field_init_shorthand = true | ||
match_block_trailing_comma = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,73 @@ | ||
use std::path::PathBuf; | ||
use std::str::FromStr; | ||
use std::sync::Arc; | ||
|
||
use gpui::*; | ||
|
||
#[derive(IntoElement)] | ||
struct ImageContainer { | ||
text: SharedString, | ||
src: ImageSource, | ||
} | ||
|
||
impl ImageContainer { | ||
pub fn new(text: impl Into<SharedString>, src: impl Into<ImageSource>) -> Self { | ||
Self { | ||
text: text.into(), | ||
src: src.into(), | ||
} | ||
} | ||
} | ||
|
||
impl RenderOnce for ImageContainer { | ||
fn render(self, _: &mut WindowContext) -> impl IntoElement { | ||
div().child( | ||
div() | ||
.flex_row() | ||
.size_full() | ||
.gap_4() | ||
.child(self.text) | ||
.child(img(self.src).w(px(512.0)).h(px(512.0))), | ||
) | ||
} | ||
} | ||
|
||
struct ImageShowcase { | ||
local_resource: Arc<PathBuf>, | ||
remote_resource: SharedUri, | ||
} | ||
|
||
impl Render for ImageShowcase { | ||
fn render(&mut self, _cx: &mut ViewContext<Self>) -> impl IntoElement { | ||
div() | ||
.flex() | ||
.flex_row() | ||
.size_full() | ||
.justify_center() | ||
.items_center() | ||
.gap_8() | ||
.bg(rgb(0xFFFFFF)) | ||
.child(ImageContainer::new( | ||
"Image loaded from a local file", | ||
self.local_resource.clone(), | ||
)) | ||
.child(ImageContainer::new( | ||
"Image loaded from a remote resource", | ||
self.remote_resource.clone(), | ||
)) | ||
} | ||
} | ||
|
||
fn main() { | ||
println!("Hello, world!"); | ||
pretty_env_logger::env_logger::init(); | ||
|
||
App::new().run(|cx: &mut AppContext| { | ||
cx.open_window(WindowOptions::default(), |cx| { | ||
cx.new_view(|_cx| ImageShowcase { | ||
// Relative path to your root project path | ||
local_resource: Arc::new(PathBuf::from_str("examples/image/app-icon.png").unwrap()), | ||
remote_resource: "https://picsum.photos/512/512".into(), | ||
}) | ||
}); | ||
}); | ||
} |