mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-10-06 03:18:11 +08:00
Fix thumbnails not being updated for layers when they become empty (#3624)
* fix: thumbnail render for empty layers * removed self import * fix: rename * Cleanup --------- Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
@@ -514,33 +514,36 @@ impl NodeRuntime {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let bounds = match graphic.bounding_box(DAffine2::IDENTITY, true) {
|
let bounds = match graphic.bounding_box(DAffine2::IDENTITY, true) {
|
||||||
RenderBoundingBox::None => return,
|
RenderBoundingBox::None => None,
|
||||||
RenderBoundingBox::Infinite => [DVec2::ZERO, DVec2::new(300., 200.)],
|
RenderBoundingBox::Infinite => Some([DVec2::ZERO, DVec2::new(300., 200.)]),
|
||||||
RenderBoundingBox::Rectangle(bounds) => bounds,
|
RenderBoundingBox::Rectangle(bounds) => Some(bounds),
|
||||||
};
|
};
|
||||||
let footprint = Footprint {
|
let new_thumbnail_svg = if let Some(bounds) = bounds {
|
||||||
transform: DAffine2::from_translation(DVec2::new(bounds[0].x, bounds[0].y)),
|
let footprint = Footprint {
|
||||||
resolution: UVec2::new((bounds[1].x - bounds[0].x).abs() as u32, (bounds[1].y - bounds[0].y).abs() as u32),
|
transform: DAffine2::from_translation(DVec2::new(bounds[0].x, bounds[0].y)),
|
||||||
quality: RenderQuality::Full,
|
resolution: UVec2::new((bounds[1].x - bounds[0].x).abs() as u32, (bounds[1].y - bounds[0].y).abs() as u32),
|
||||||
|
quality: RenderQuality::Full,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Render the thumbnail from a `Graphic` into an SVG string
|
||||||
|
let render_params = RenderParams {
|
||||||
|
footprint,
|
||||||
|
thumbnail: true,
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
let mut render = SvgRender::new();
|
||||||
|
graphic.render_svg(&mut render, &render_params);
|
||||||
|
|
||||||
|
// And give the SVG a viewbox and outer <svg>...</svg> wrapper tag
|
||||||
|
render.format_svg(bounds[0], bounds[1]);
|
||||||
|
|
||||||
|
render.svg
|
||||||
|
} else {
|
||||||
|
Vec::new()
|
||||||
};
|
};
|
||||||
|
|
||||||
// Render the thumbnail from a `Graphic` into an SVG string
|
// Update frontend thumbnail
|
||||||
let render_params = RenderParams {
|
|
||||||
footprint,
|
|
||||||
thumbnail: true,
|
|
||||||
..Default::default()
|
|
||||||
};
|
|
||||||
let mut render = SvgRender::new();
|
|
||||||
graphic.render_svg(&mut render, &render_params);
|
|
||||||
|
|
||||||
// And give the SVG a viewbox and outer <svg>...</svg> wrapper tag
|
|
||||||
render.format_svg(bounds[0], bounds[1]);
|
|
||||||
|
|
||||||
// UPDATE FRONTEND THUMBNAIL
|
|
||||||
|
|
||||||
let new_thumbnail_svg = render.svg;
|
|
||||||
let old_thumbnail_svg = thumbnail_renders.entry(parent_network_node_id).or_default();
|
let old_thumbnail_svg = thumbnail_renders.entry(parent_network_node_id).or_default();
|
||||||
|
|
||||||
if old_thumbnail_svg != &new_thumbnail_svg {
|
if old_thumbnail_svg != &new_thumbnail_svg {
|
||||||
responses.push_back(FrontendMessage::UpdateNodeThumbnail {
|
responses.push_back(FrontendMessage::UpdateNodeThumbnail {
|
||||||
id: parent_network_node_id,
|
id: parent_network_node_id,
|
||||||
|
|||||||
Reference in New Issue
Block a user