svg_img: Reduce ImageSource creation (#728)
This commit is contained in:
parent
393e7e8f85
commit
9d2a70be48
1 changed files with 14 additions and 7 deletions
|
|
@ -68,10 +68,10 @@ impl Clone for SvgImg {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum Image {}
|
pub enum Image {}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
struct ImageSource {
|
pub struct ImageSource {
|
||||||
source: SvgSource,
|
source: SvgSource,
|
||||||
size: Size<Pixels>,
|
size: Size<Pixels>,
|
||||||
}
|
}
|
||||||
|
|
@ -152,7 +152,7 @@ impl Asset for Image {
|
||||||
|
|
||||||
pub struct SvgImg {
|
pub struct SvgImg {
|
||||||
interactivity: Interactivity,
|
interactivity: Interactivity,
|
||||||
source: Option<SvgSource>,
|
source: Option<ImageSource>,
|
||||||
size: Size<Pixels>,
|
size: Size<Pixels>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -178,10 +178,18 @@ impl SvgImg {
|
||||||
width: impl Into<Pixels>,
|
width: impl Into<Pixels>,
|
||||||
height: impl Into<Pixels>,
|
height: impl Into<Pixels>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
self.source = Some(source.into());
|
let size = size(width.into(), height.into());
|
||||||
self.size = size(width.into(), height.into());
|
self.size = size;
|
||||||
|
self.source = Some(ImageSource {
|
||||||
|
source: source.into(),
|
||||||
|
size,
|
||||||
|
});
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_source(&self) -> Option<&ImageSource> {
|
||||||
|
self.source.as_ref()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IntoElement for SvgImg {
|
impl IntoElement for SvgImg {
|
||||||
|
|
@ -213,9 +221,8 @@ impl Element for SvgImg {
|
||||||
});
|
});
|
||||||
|
|
||||||
let source = self.source.clone();
|
let source = self.source.clone();
|
||||||
let size = self.size;
|
|
||||||
let data = if let Some(source) = source {
|
let data = if let Some(source) = source {
|
||||||
match window.use_asset::<Image>(&ImageSource { source, size }, cx) {
|
match window.use_asset::<Image>(&source, cx) {
|
||||||
Some(Ok(data)) => Some(data),
|
Some(Ok(data)) => Some(data),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue