raster: info-panel size + "Layer to document size" (scale/expand-crop)
Resizing the document leaves raster layers as-is (canvas keeps its old pixel size, anchored top-left). To reconcile, the info panel now shows the active raster layer's canvas size — driven by the *active* layer, not selection focus, since painting doesn't focus the layer — and, when it differs from the document, a Scale / Expand-Crop toggle + a "Layer to document size" button. - RasterKeyframe::resize_to(w, h, mode): always applies the new declared size; resamples (Lanczos3) when Scale, top-left pad/trim when Canvas, and only touches the buffer when pixels are resident (a blank canvas just takes the new size). Sets texture_dirty so the stage's dirty-scan refreshes the GPU texture. - ResizeRasterLayerAction resizes every keyframe with undo, holding a (read-only) RasterStore so paged-out keyframes are loaded one at a time rather than bulk. Resized keyframes stay resident + dirty and persist on the next full save (no incremental store write to page them back out). Scale is lossy/compounds; Expand-Crop is lossless.
This commit is contained in:
@@ -44,6 +44,8 @@ pub struct InfopanelPane {
|
||||
selected_tool_gradient_stop: Option<usize>,
|
||||
/// FPS value captured when a drag/focus-in starts (for single-undo-action on commit)
|
||||
fps_drag_start: Option<f64>,
|
||||
/// Resize mode for the active raster layer's "to document size" action (scale vs canvas).
|
||||
raster_resize_mode: lightningbeam_core::raster_layer::RasterResizeMode,
|
||||
}
|
||||
|
||||
impl InfopanelPane {
|
||||
@@ -61,6 +63,7 @@ impl InfopanelPane {
|
||||
selected_shape_gradient_stop: None,
|
||||
selected_tool_gradient_stop: None,
|
||||
fps_drag_start: None,
|
||||
raster_resize_mode: lightningbeam_core::raster_layer::RasterResizeMode::Scale,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1197,6 +1200,53 @@ impl InfopanelPane {
|
||||
});
|
||||
}
|
||||
|
||||
/// Render a raster-layer section: shows the active keyframe's canvas dimensions and, when they
|
||||
/// differ from the document, a Scale/Expand-Crop mode toggle + a "Layer to document size" button.
|
||||
/// Driven by the *active* layer (not selection focus), since painting doesn't focus the layer.
|
||||
fn render_raster_layer_section(&mut self, ui: &mut Ui, path: &NodePath, shared: &mut SharedPaneState, layer_id: Uuid) {
|
||||
use lightningbeam_core::raster_layer::RasterResizeMode;
|
||||
|
||||
// Pull the values, then drop the document borrow before mutating `shared`.
|
||||
let time = *shared.playback_time;
|
||||
let dims = {
|
||||
let document = shared.action_executor.document();
|
||||
match document.get_layer(&layer_id) {
|
||||
Some(AnyLayer::Raster(rl)) => rl
|
||||
.keyframe_at(time)
|
||||
.map(|kf| (kf.width, kf.height, document.width as u32, document.height as u32)),
|
||||
_ => None,
|
||||
}
|
||||
};
|
||||
let Some((kf_w, kf_h, doc_w, doc_h)) = dims else { return };
|
||||
|
||||
egui::CollapsingHeader::new("Raster Layer")
|
||||
.id_salt(("raster_layer", path))
|
||||
.default_open(true)
|
||||
.show(ui, |ui| {
|
||||
ui.add_space(4.0);
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Size:");
|
||||
ui.label(format!("{} × {}", kf_w, kf_h));
|
||||
});
|
||||
|
||||
if kf_w != doc_w || kf_h != doc_h {
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Mode:");
|
||||
ui.selectable_value(&mut self.raster_resize_mode, RasterResizeMode::Scale, "Scale");
|
||||
ui.selectable_value(&mut self.raster_resize_mode, RasterResizeMode::Canvas, "Expand/Crop");
|
||||
});
|
||||
if ui.button(format!("Layer to document size ({} × {})", doc_w, doc_h)).clicked() {
|
||||
let store = lightningbeam_core::raster_store::RasterStore::new(shared.container_path.clone());
|
||||
let action = lightningbeam_core::actions::ResizeRasterLayerAction::new(
|
||||
layer_id, doc_w, doc_h, self.raster_resize_mode, store,
|
||||
);
|
||||
shared.pending_actions.push(Box::new(action));
|
||||
}
|
||||
}
|
||||
ui.add_space(4.0);
|
||||
});
|
||||
}
|
||||
|
||||
/// Render clip instance info section
|
||||
fn render_clip_instance_section(&self, ui: &mut Ui, path: &NodePath, shared: &SharedPaneState, clip_ids: &[Uuid]) {
|
||||
let document = shared.action_executor.document();
|
||||
@@ -1547,6 +1597,12 @@ impl PaneRenderer for InfopanelPane {
|
||||
}
|
||||
}
|
||||
|
||||
// Active raster layer's size + "to document size" — shown whenever a raster layer is
|
||||
// active (independent of selection focus, since painting doesn't focus the layer).
|
||||
if let Some(active_id) = *shared.active_layer_id {
|
||||
self.render_raster_layer_section(ui, path, shared, active_id);
|
||||
}
|
||||
|
||||
// Onion-skinning view settings — always available, regardless of selection.
|
||||
ui.add_space(8.0);
|
||||
ui.separator();
|
||||
|
||||
Reference in New Issue
Block a user