feat: make canvas refresh more efficient
This commit is contained in:
parent
b430c80000
commit
8447fdef5d
5 changed files with 507 additions and 408 deletions
|
|
@ -63,7 +63,7 @@ pub struct ViewerSettings {
|
|||
pub zoom_level: f64,
|
||||
|
||||
/// When true, props use reference scaling based on 1920x1080.
|
||||
/// Only applicable when `panning_enabled` is false.
|
||||
/// Applies in both fit mode and pan mode.
|
||||
pub enlarge_props: bool,
|
||||
|
||||
/// Saved horizontal scroll position for pan mode.
|
||||
|
|
@ -78,7 +78,7 @@ impl Default for ViewerSettings {
|
|||
Self {
|
||||
panning_enabled: false,
|
||||
zoom_level: 1.0,
|
||||
enlarge_props: false,
|
||||
enlarge_props: true,
|
||||
scroll_x: 0.0,
|
||||
scroll_y: 0.0,
|
||||
}
|
||||
|
|
@ -132,18 +132,23 @@ impl ViewerSettings {
|
|||
|
||||
/// Calculate the effective prop size based on current settings.
|
||||
///
|
||||
/// In pan mode, returns base size * zoom level.
|
||||
/// In pan mode without enlarge, returns base size * zoom level.
|
||||
/// In pan mode with enlarge, returns base size * reference_scale * zoom level.
|
||||
/// In fit mode with enlarge_props, returns size adjusted for reference resolution.
|
||||
/// Otherwise returns base size (caller should multiply by canvas scale).
|
||||
pub fn calculate_prop_size(&self, scene_width: f64, scene_height: f64) -> f64 {
|
||||
// Reference scale factor for "enlarge props" mode
|
||||
let ref_scale = (scene_width / REFERENCE_WIDTH).max(scene_height / REFERENCE_HEIGHT);
|
||||
|
||||
if self.panning_enabled {
|
||||
// Pan mode: base size * zoom
|
||||
BASE_PROP_SIZE * self.zoom_level
|
||||
if self.enlarge_props {
|
||||
BASE_PROP_SIZE * ref_scale * self.zoom_level
|
||||
} else {
|
||||
BASE_PROP_SIZE * self.zoom_level
|
||||
}
|
||||
} else if self.enlarge_props {
|
||||
// Reference scaling: ensure minimum size based on 1920x1080
|
||||
let scale_w = scene_width / REFERENCE_WIDTH;
|
||||
let scale_h = scene_height / REFERENCE_HEIGHT;
|
||||
BASE_PROP_SIZE * scale_w.max(scale_h)
|
||||
BASE_PROP_SIZE * ref_scale
|
||||
} else {
|
||||
// Default: base size (will be scaled by canvas scale factor)
|
||||
BASE_PROP_SIZE
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue