gif_viewer.rs

 1use gpui::{App, Application, Context, Render, Window, WindowOptions, div, img, prelude::*};
 2use std::path::PathBuf;
 3
 4struct GifViewer {
 5    gif_path: PathBuf,
 6}
 7
 8impl GifViewer {
 9    fn new(gif_path: PathBuf) -> Self {
10        Self { gif_path }
11    }
12}
13
14impl Render for GifViewer {
15    fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
16        div().size_full().child(
17            img(self.gif_path.clone())
18                .size_full()
19                .object_fit(gpui::ObjectFit::Contain)
20                .id("gif"),
21        )
22    }
23}
24
25fn main() {
26    env_logger::init();
27    Application::new().run(|cx: &mut App| {
28        let gif_path =
29            PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("examples/image/black-cat-typing.gif");
30
31        cx.open_window(
32            WindowOptions {
33                focus: true,
34                ..Default::default()
35            },
36            |_, cx| cx.new(|_| GifViewer::new(gif_path)),
37        )
38        .unwrap();
39        cx.activate(true);
40    });
41}