Skip to content

Commit

Permalink
refactor: use stable
Browse files Browse the repository at this point in the history
  • Loading branch information
cs50victor committed Mar 13, 2024
1 parent 647038a commit 7d46e19
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-rs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
fail-fast: false
matrix:
rust-toolchain:
- nightly
- stable

steps:
- name: Get source code
Expand Down
58 changes: 50 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ edition = "2021"

[dependencies]
gpui = { git = "https://github.com/zed-industries/zed", version = "0.1.0" }
log = "0.4.21"
pretty_env_logger = "0.5.0"

[[bin]]
name = "os1"
2 changes: 2 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[toolchain]
channel = "stable"
8 changes: 8 additions & 0 deletions rustfmt.toml
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
72 changes: 71 additions & 1 deletion src/main.rs
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(),
})
});
});
}

0 comments on commit 7d46e19

Please sign in to comment.