ZIm/crates/assistant/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
..
context Fix regression in producing sections when converting SlashCommandOutput to event stream (#20404) 2024-11-08 09:29:14 +01:00
slash_command context_servers: Upgrade protocol to version 2024-11-05 (#20615) 2024-11-14 13:03:30 -05:00
tools context_servers: Upgrade protocol to version 2024-11-05 (#20615) 2024-11-14 13:03:30 -05:00
assistant.rs assistant: Fix panic when using /project (#20733) 2024-11-15 12:25:29 -05:00
assistant_panel.rs Add Loading and Fallback States to Image Elements (via StyledImage) (#20371) 2024-11-15 19:12:01 -08:00
assistant_settings.rs assistant: Remove low_speed_timeout (#20681) 2024-11-15 07:37:31 +01:00
context.rs assistant: Show more details for assist errors (#20740) 2024-11-15 14:23:46 -05:00
context_store.rs Improve context server lifecycle management (#20622) 2024-11-13 13:55:06 -08:00
inline_assistant.rs Avoid creating occlusions for editor blocks, since these block mouse wheel events (#20649) 2024-11-13 21:02:54 -08:00
model_selector.rs assistant: Show only configured models in the model picker (#20392) 2024-11-08 10:08:59 -03:00
patch.rs Fix more failure cases of assistant edits (#19653) 2024-10-25 14:30:34 -07:00
prompt_library.rs Refactor Spacing into DynamicSpacing using proc macro (#20504) 2024-11-11 11:08:55 -05:00
prompts.rs logs: Reduce log noise by using more debug logs (#20498) 2024-11-11 15:11:20 +01:00
slash_command.rs Fix completions for non-built-in slash commands (#20632) 2024-11-13 15:11:50 -08:00
slash_command_picker.rs Scope slash commands, context servers, and tools to individual Assistant Panel instances (#20372) 2024-11-07 18:23:25 -05:00
slash_command_settings.rs Add settings to remote servers, use XDG paths on remote, and enable node LSPs (#19176) 2024-10-15 23:32:44 -07:00
slash_command_working_set.rs assistant: Fix completions for slash commands provided by context servers (#20423) 2024-11-08 11:35:39 -05:00
streaming_diff.rs Reduce memory footprint for inline transformations (#20296) 2024-11-06 15:07:16 +01:00
terminal_inline_assistant.rs assistant: Add health telemetry (#19928) 2024-10-31 16:21:26 -07:00
tool_working_set.rs Scope slash commands, context servers, and tools to individual Assistant Panel instances (#20372) 2024-11-07 18:23:25 -05:00
tools.rs context_servers: Support tools (#19548) 2024-10-28 10:37:58 -04:00