Skip to content

Commit 8f32c85

Browse files
update root transform strategy - use nonscaled offset value
1 parent 917bd20 commit 8f32c85

1 file changed

Lines changed: 11 additions & 16 deletions

File tree

editor-packages/editor-canvas/canvas/canvas.tsx

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@ import {
1414
OnPointerMoveHandler,
1515
OnPointerDownHandler,
1616
} from "../canvas-event-target";
17-
import {
18-
transform_by_zoom_delta,
19-
get_hovering_target,
20-
centerOf,
21-
} from "../math";
17+
import { get_hovering_target, centerOf } from "../math";
2218
import { utils } from "@design-sdk/core";
2319
import { LazyFrame } from "@code-editor/canvas/lazy-frame";
2420
import { HudCustomRenderers, HudSurface } from "./hud-surface";
@@ -29,7 +25,7 @@ const designq = utils.query;
2925
const INITIAL_SCALE = 1;
3026
const INITIAL_XY: XY = [0, 0];
3127
const LAYER_HOVER_HIT_MARGIN = 3.5;
32-
const MIN_ZOOM = 0.05;
28+
const MIN_ZOOM = 0.02;
3329

3430
type CanvasTransform = {
3531
scale: number;
@@ -84,7 +80,8 @@ export function Canvas({
8480

8581
const [zoom, setZoom] = useState(_initial_scale);
8682
const [isZooming, setIsZooming] = useState(false);
87-
const [xy, setXY] = useState<[number, number]>(_inicial_xy);
83+
const [offset, setOffset] = useState<[number, number]>(_inicial_xy);
84+
const nonscaled_offset: XY = [offset[0] / zoom, offset[1] / zoom]; // offset;
8885
const [isPanning, setIsPanning] = useState(false);
8986

9087
const node = (id) => designq.find_node_by_id_under_inpage_nodes(id, nodes);
@@ -109,7 +106,7 @@ export function Canvas({
109106
point: state.xy,
110107
tree: nodes,
111108
zoom: zoom,
112-
offset: xy,
109+
offset: nonscaled_offset,
113110
margin: LAYER_HOVER_HIT_MARGIN,
114111
});
115112

@@ -150,8 +147,9 @@ export function Canvas({
150147
wheeling,
151148
} = s;
152149

153-
setXY([xy[0] - x / zoom, xy[1] - y / zoom]);
150+
setOffset([offset[0] - x, offset[1] - y]);
154151
};
152+
155153
const onZooming: OnZoomingHandler = (state) => {
156154
const zoomdelta = state.delta[0];
157155
const zoompoint: XY = [
@@ -163,18 +161,15 @@ export function Canvas({
163161

164162
const newzoom = Math.max(zoom + zoomdelta, MIN_ZOOM);
165163
setZoom(newzoom);
166-
167-
const delta = transform_by_zoom_delta(zoomdelta, zoompoint);
168-
setXY([xy[0] + delta[0], xy[1] + delta[1]]);
164+
// TODO: transform offset
165+
// setOffset([offset[0], offset[1]]);
169166
};
170167

171168
const is_canvas_transforming = isPanning || isZooming;
172169
const selected_nodes = selectedNodes
173170
?.map((id) => designq.find_node_by_id_under_inpage_nodes(id, nodes))
174171
.filter(Boolean);
175172

176-
// console.log("selected_nodes", selected_nodes);
177-
178173
return (
179174
<>
180175
<CanvasEventTarget
@@ -198,7 +193,7 @@ export function Canvas({
198193
onPointerDown={onPointerDown}
199194
>
200195
<HudSurface
201-
offset={xy}
196+
offset={nonscaled_offset}
202197
zoom={zoom}
203198
hide={is_canvas_transforming}
204199
readonly={readonly}
@@ -224,7 +219,7 @@ export function Canvas({
224219
renderFrameTitle={props.renderFrameTitle}
225220
/>
226221
</CanvasEventTarget>
227-
<CanvasTransformRoot scale={zoom} xy={xy}>
222+
<CanvasTransformRoot scale={zoom} xy={nonscaled_offset}>
228223
<DisableBackdropFilter>
229224
{nodes?.map((node) => {
230225
return (

0 commit comments

Comments
 (0)