parent
df54c7b2fb
commit
ab772c04f1
2 changed files with 9 additions and 14 deletions
|
|
@ -1,5 +1,5 @@
|
|||
use gpui::{px, ParentElement as _, Render, Styled, View, VisualContext as _, WindowContext};
|
||||
use ui::{h_flex, svg_img, v_flex, SvgImg};
|
||||
use ui::{h_flex, v_flex, SvgImg};
|
||||
|
||||
const GOOGLE_LOGO: &str = include_str!("./fixtures/google.svg");
|
||||
const PIE_JSON: &str = include_str!("./fixtures/pie.json");
|
||||
|
|
@ -27,9 +27,9 @@ impl ImageStory {
|
|||
|
||||
Self {
|
||||
focus_handle: cx.focus_handle(),
|
||||
google_logo: svg_img().source(GOOGLE_LOGO.as_bytes(), px(300.), px(300.)),
|
||||
pie_chart: svg_img().source(chart.svg().unwrap().as_bytes(), px(600.), px(400.)),
|
||||
inbox_img: svg_img().source("icons/inbox.svg", px(300.), px(300.)),
|
||||
google_logo: SvgImg::new().source(GOOGLE_LOGO.as_bytes(), px(300.), px(300.)),
|
||||
pie_chart: SvgImg::new().source(chart.svg().unwrap().as_bytes(), px(600.), px(400.)),
|
||||
inbox_img: SvgImg::new().source("icons/inbox.svg", px(24.), px(24.)),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -59,7 +59,7 @@ impl Render for ImageStory {
|
|||
.child(self.google_logo.clone().size_12().flex_grow())
|
||||
.child(self.google_logo.clone().w(px(300.)).h(px(300.))),
|
||||
)
|
||||
.child(self.inbox_img.clone().w(px(80.)).h(px(80.)))
|
||||
.child(self.inbox_img.clone().w(px(24.)).h(px(24.)))
|
||||
.child(self.pie_chart.clone().size_full())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ use image::ImageBuffer;
|
|||
|
||||
use crate::Assets;
|
||||
|
||||
const SCALE: f32 = 2.;
|
||||
const FONT_PATH: &str = "fonts/NotoSans-Regular.ttf";
|
||||
static OPTIONS: LazyLock<usvg::Options> = LazyLock::new(|| {
|
||||
let mut options = usvg::Options::default();
|
||||
|
|
@ -90,7 +91,6 @@ impl Asset for Image {
|
|||
source: Self::Source,
|
||||
cx: &mut AppContext,
|
||||
) -> impl std::future::Future<Output = Self::Output> + Send + 'static {
|
||||
let scale = 2.;
|
||||
let asset_source = cx.asset_source().clone();
|
||||
|
||||
async move {
|
||||
|
|
@ -99,8 +99,8 @@ impl Asset for Image {
|
|||
return Err(usvg::Error::InvalidSize.into());
|
||||
}
|
||||
let size = Size {
|
||||
width: (size.width * 2).ceil(),
|
||||
height: (size.height * scale).ceil(),
|
||||
width: (size.width * SCALE).ceil(),
|
||||
height: (size.height * SCALE).ceil(),
|
||||
};
|
||||
|
||||
let bytes = match source.source {
|
||||
|
|
@ -124,7 +124,7 @@ impl Asset for Image {
|
|||
resvg::tiny_skia::Pixmap::new(size.width.0 as u32, size.height.0 as u32)
|
||||
.ok_or(usvg::Error::InvalidSize)?;
|
||||
|
||||
let transform = resvg::tiny_skia::Transform::from_scale(scale, scale);
|
||||
let transform = resvg::tiny_skia::Transform::from_scale(SCALE, SCALE);
|
||||
|
||||
resvg::render(&tree, transform, &mut pixmap.as_mut());
|
||||
|
||||
|
|
@ -144,11 +144,6 @@ impl Asset for Image {
|
|||
}
|
||||
}
|
||||
|
||||
/// An SVG image element.
|
||||
pub fn svg_img() -> SvgImg {
|
||||
SvgImg::new()
|
||||
}
|
||||
|
||||
pub struct SvgImg {
|
||||
interactivity: Interactivity,
|
||||
source: Option<SvgSource>,
|
||||
|
|
|
|||
Loading…
Reference in a new issue