Merge branch 'gpui2' into marshall/gpui2-playground

This commit is contained in:
Marshall Bowers
2023-10-04 17:32:21 -04:00
19 changed files with 588 additions and 1326 deletions
+16 -12
View File
@@ -1,5 +1,6 @@
use crate::{
Element, Layout, LayoutId, Result, SharedString, Style, StyleHelpers, Styled, ViewContext,
BorrowWindow, Element, Layout, LayoutId, Result, SharedString, Style, StyleHelpers, Styled,
ViewContext,
};
use futures::FutureExt;
use refineable::RefinementCascade;
@@ -34,7 +35,7 @@ impl<S> Img<S> {
}
}
impl<S: 'static> Element for Img<S> {
impl<S: Send + Sync + 'static> Element for Img<S> {
type State = S;
type FrameState = ();
@@ -64,22 +65,25 @@ impl<S: 'static> Element for Img<S> {
style.paint(order, bounds, cx);
if let Some(uri) = &self.uri {
let image_future = cx.image_cache.get(uri.clone());
if let Some(uri) = self.uri.clone() {
let image_future = cx.image_cache.get(uri);
if let Some(data) = image_future
.clone()
.now_or_never()
.and_then(ResultExt::log_err)
{
cx.paint_image(bounds, order, data, self.grayscale)?;
let corner_radii = style.corner_radii.to_pixels(bounds, cx.rem_size());
cx.paint_image(bounds, corner_radii, order, data, self.grayscale)?;
} else {
log::warn!("image not loaded yet");
// cx.spawn(|this, mut cx| async move {
// if image_future.await.log_err().is_some() {
// this.update(&mut cx, |_, cx| cx.notify()).ok();
// }
// })
// .detach();
cx.spawn(|view, mut cx| async move {
if image_future.await.log_err().is_some() {
view.update(&mut cx, |_, cx| {
cx.notify();
})
.ok();
}
})
.detach()
}
}
Ok(())