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