1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//! `CloudImage` — the web Cloudinary illustration by public id.
//!
//! Ids must be in the design system's illustration list (the images fetch);
//! they resolve from the local cache through [`crate::Assets`]. Apps that
//! need arbitrary Cloudinary ids at runtime bring their own gpui http client
//! and use `img(uri)` directly.
//!
//! Web props this port leaves to the fetch pipeline: `transformation` is fixed
//! per id at fetch time, `lazyload` and `placeholder` are network-progress
//! concerns the local cache removes, and `alt` has no sink in gpui yet.
use gpui::prelude::FluentBuilder as _;
use gpui::{img, px, App, IntoElement, RenderOnce, SharedString, Styled as _, Window};
#[derive(IntoElement)]
pub struct CloudImage {
public_id: SharedString,
width: Option<f32>,
height: Option<f32>,
}
impl CloudImage {
pub fn new(public_id: impl Into<SharedString>) -> Self {
Self {
public_id: public_id.into(),
width: None,
height: None,
}
}
#[must_use]
pub const fn width(mut self, width: f32) -> Self {
self.width = Some(width);
self
}
#[must_use]
pub const fn height(mut self, height: f32) -> Self {
self.height = Some(height);
self
}
}
impl RenderOnce for CloudImage {
fn render(self, _window: &mut Window, _cx: &mut App) -> impl IntoElement {
img(format!("images/{}.png", self.public_id))
.when_some(self.width, |el, width| el.w(px(width)))
.when_some(self.height, |el, height| el.h(px(height)))
}
}