ZIm/crates/workspace/src
Mikayla Maki 516f7b3642
Add Loading and Fallback States to Image Elements (via StyledImage) (#20371)
@iamnbutler edit:

This pull request enhances the image element by introducing the ability
to display loading and fallback states.

Changes:

- Implemented the loading and fallback states for image elements using
`.with_loading` and `.with_fallback` respectively.
- Introduced the `StyledImage` trait and `ImageStyle` to enable a fluent
API for changing image styles across image types (`Img`,
`Stateful<Img>`, etc).

Example Usage:

```rust
fn loading_element() -> impl IntoElement {
    div().size_full().flex_none().p_0p5().rounded_sm().child(
        div().size_full().with_animation(
            "loading-bg",
            Animation::new(Duration::from_secs(3))
                .repeat()
                .with_easing(pulsating_between(0.04, 0.24)),
            move |this, delta| this.bg(black().opacity(delta)),
        ),
    )
}

fn fallback_element() -> impl IntoElement {
    let fallback_color: Hsla = black().opacity(0.5);

    div().size_full().flex_none().p_0p5().child(
        div()
            .size_full()
            .flex()
            .items_center()
            .justify_center()
            .rounded_sm()
            .text_sm()
            .text_color(fallback_color)
            .border_1()
            .border_color(fallback_color)
            .child("?"),
    )
}

impl Render for ImageLoadingExample {
    fn render(&mut self, _cx: &mut ViewContext<Self>) -> impl IntoElement {
        img("some/image/path")
            .id("image-1")
            .with_fallback(|| Self::fallback_element().into_any_element())
            .with_loading(|| Self::loading_element().into_any_element())
    }
}
```

Note:

An `Img` must have an `id` to be able to add a loading state.

Release Notes:

- N/A

---------

Co-authored-by: nate <nate@zed.dev>
Co-authored-by: michael <michael@zed.dev>
Co-authored-by: Nate Butler <iamnbutler@gmail.com>
Co-authored-by: Antonio Scandurra <me@as-cii.com>
2024-11-15 19:12:01 -08:00
..
persistence Remove dev servers (#19638) 2024-10-24 12:14:03 -06:00
dock.rs project panel: Fix rendering of groups of dragged project panel entries (#20686) 2024-11-14 19:29:18 +01:00
item.rs Require save confirmation and prevent autosave for deleted files (#20742) 2024-11-15 15:01:16 -07:00
modal_layer.rs chore: Fix several style lints (#17488) 2024-09-06 11:58:39 +02:00
notifications.rs Add settings to remote servers, use XDG paths on remote, and enable node LSPs (#19176) 2024-10-15 23:32:44 -07:00
pane.rs Rename "Overwrite" to "Save" for prompt about recreating a deleted file (#20750) 2024-11-15 15:12:40 -07:00
pane_group.rs Extension refactor (#20305) 2024-11-06 10:06:25 -07:00
persistence.rs Add language toolchains (#19576) 2024-10-28 15:34:03 +01:00
searchable.rs Display buffer/project search entries in the outline panel (#16589) 2024-08-25 21:40:02 +03:00
shared_screen.rs Use livekit's Rust SDK instead of their swift SDK (#13343) 2024-11-15 23:18:50 +02:00
status_bar.rs Refactor Spacing into DynamicSpacing using proc macro (#20504) 2024-11-11 11:08:55 -05:00
tasks.rs Do not allow [re]running ssh tasks when not connected to the server (#19306) 2024-10-16 22:57:39 +03:00
theme_preview.rs Add ui::ContentGroup (#20666) 2024-11-14 08:25:48 -05:00
toolbar.rs Refactor Spacing into DynamicSpacing using proc macro (#20504) 2024-11-11 11:08:55 -05:00
workspace.rs Add Loading and Fallback States to Image Elements (via StyledImage) (#20371) 2024-11-15 19:12:01 -08:00
workspace_settings.rs workspace: Add settings to dim inactive panes and highlight active pane (#18968) 2024-11-05 17:26:07 +02:00