gpui: Add SVG rendering to img
element and generic asset cache (#9931)
This is a follow up to #9436 . It has a cleaner API and generalized the image_cache to be a generic asset cache, that all GPUI elements can make use off. The changes have been discussed with @mikayla-maki on Discord. --------- Co-authored-by: Mikayla <mikayla@zed.dev>
This commit is contained in:
parent
ed5bfcdddc
commit
f9becbd3d1
11 changed files with 392 additions and 237 deletions
|
@ -1,6 +1,6 @@
|
|||
use gpui::{
|
||||
canvas, div, fill, img, opaque_grey, point, size, AnyElement, AppContext, Bounds, Context,
|
||||
Element, EventEmitter, FocusHandle, FocusableView, InteractiveElement, IntoElement, Model,
|
||||
EventEmitter, FocusHandle, FocusableView, Img, InteractiveElement, IntoElement, Model,
|
||||
ParentElement, Render, Styled, Task, View, ViewContext, VisualContext, WeakView, WindowContext,
|
||||
};
|
||||
use persistence::IMAGE_VIEWER;
|
||||
|
@ -36,8 +36,7 @@ impl project::Item for ImageItem {
|
|||
.and_then(OsStr::to_str)
|
||||
.unwrap_or_default();
|
||||
|
||||
let format = gpui::ImageFormat::from_extension(ext);
|
||||
if format.is_some() {
|
||||
if Img::extensions().contains(&ext) {
|
||||
Some(cx.spawn(|mut cx| async move {
|
||||
let abs_path = project
|
||||
.read_with(&cx, |project, cx| project.absolute_path(&path, cx))?
|
||||
|
@ -156,8 +155,6 @@ impl FocusableView for ImageView {
|
|||
|
||||
impl Render for ImageView {
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
|
||||
let im = img(self.path.clone()).into_any();
|
||||
|
||||
div()
|
||||
.track_focus(&self.focus_handle)
|
||||
.size_full()
|
||||
|
@ -210,10 +207,12 @@ impl Render for ImageView {
|
|||
.left_0(),
|
||||
)
|
||||
.child(
|
||||
v_flex()
|
||||
.h_full()
|
||||
.justify_around()
|
||||
.child(h_flex().w_full().justify_around().child(im)),
|
||||
v_flex().h_full().justify_around().child(
|
||||
h_flex()
|
||||
.w_full()
|
||||
.justify_around()
|
||||
.child(img(self.path.clone())),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue