mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
resize elements from center point (#1225)
* add hint & support multi-line hints * resize from center point using the new resize maths * resize with origin element when lifting alt key * add readonly to elementOriginPosition * add setResizeWithCenterKeyLifted * isResizeFromCenter logic * offsetX and offsetY * simplify equations * creating element from center point * lint * lint * lint * remove revert on key up logic Co-authored-by: dwelle <luzar.david@gmail.com> Co-authored-by: daishi <daishi@axlight.com>
This commit is contained in:
parent
8c49770e3b
commit
ed6fb60337
6 changed files with 69 additions and 22 deletions
|
@ -71,7 +71,12 @@ import {
|
|||
sceneCoordsToViewportCoords,
|
||||
setCursorForShape,
|
||||
} from "../utils";
|
||||
import { KEYS, isArrowKey } from "../keys";
|
||||
import {
|
||||
KEYS,
|
||||
isArrowKey,
|
||||
getResizeCenterPointKey,
|
||||
getResizeWithSidesSameLengthKey,
|
||||
} from "../keys";
|
||||
|
||||
import { findShapeByKey, shapesShortcutKeys } from "../shapes";
|
||||
import { createHistory, SceneHistory } from "../history";
|
||||
|
@ -1801,6 +1806,7 @@ class App extends React.Component<any, AppState> {
|
|||
let draggingOccurred = false;
|
||||
let hitElement: ExcalidrawElement | null = null;
|
||||
let hitElementWasAddedToSelection = false;
|
||||
|
||||
if (this.state.elementType === "selection") {
|
||||
const elements = globalSceneState.getElements();
|
||||
const selectedElements = getSelectedElements(elements, this.state);
|
||||
|
@ -2021,7 +2027,7 @@ class App extends React.Component<any, AppState> {
|
|||
}
|
||||
|
||||
let resizeArrowFn: ResizeArrowFnType | null = null;
|
||||
const setResizeArrrowFn = (fn: ResizeArrowFnType) => {
|
||||
const setResizeArrowFn = (fn: ResizeArrowFnType) => {
|
||||
resizeArrowFn = fn;
|
||||
};
|
||||
|
||||
|
@ -2082,7 +2088,7 @@ class App extends React.Component<any, AppState> {
|
|||
this.state,
|
||||
this.setAppState,
|
||||
resizeArrowFn,
|
||||
setResizeArrrowFn,
|
||||
setResizeArrowFn,
|
||||
event,
|
||||
x,
|
||||
y,
|
||||
|
@ -2189,7 +2195,7 @@ class App extends React.Component<any, AppState> {
|
|||
});
|
||||
}
|
||||
} else {
|
||||
if (event.shiftKey) {
|
||||
if (getResizeWithSidesSameLengthKey(event)) {
|
||||
({ width, height } = getPerfectElementSize(
|
||||
this.state.elementType,
|
||||
width,
|
||||
|
@ -2201,9 +2207,19 @@ class App extends React.Component<any, AppState> {
|
|||
}
|
||||
}
|
||||
|
||||
let newX = x < originX ? originX - width : originX;
|
||||
let newY = y < originY ? originY - height : originY;
|
||||
|
||||
if (getResizeCenterPointKey(event)) {
|
||||
width += width;
|
||||
height += height;
|
||||
newX = originX - width / 2;
|
||||
newY = originY - height / 2;
|
||||
}
|
||||
|
||||
mutateElement(draggingElement, {
|
||||
x: x < originX ? originX - width : originX,
|
||||
y: y < originY ? originY - height : originY,
|
||||
x: newX,
|
||||
y: newY,
|
||||
width: width,
|
||||
height: height,
|
||||
});
|
||||
|
|
|
@ -8,11 +8,12 @@
|
|||
position: absolute;
|
||||
top: 54px;
|
||||
transform: translateX(calc(-50% - 16px)); /* 16px is half of lock icon */
|
||||
white-space: pre;
|
||||
text-align: center;
|
||||
@media #{$media-query} {
|
||||
position: static;
|
||||
transform: none;
|
||||
margin-top: 0.5rem;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
> span {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue