XPositionReference: Fix Selector and Append
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
522cd722c0
commit
4fbc67835c
3 changed files with 31 additions and 6 deletions
|
@ -7,6 +7,7 @@ import { getCurrentHistory } from './Editor';
|
||||||
import IProperties from '../../Interfaces/IProperties';
|
import IProperties from '../../Interfaces/IProperties';
|
||||||
import { AddMethod } from '../../Enums/AddMethod';
|
import { AddMethod } from '../../Enums/AddMethod';
|
||||||
import { IAvailableContainer } from '../../Interfaces/IAvailableContainer';
|
import { IAvailableContainer } from '../../Interfaces/IAvailableContainer';
|
||||||
|
import { transformPosition } from '../SVG/Elements/Container';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Select a container
|
* Select a container
|
||||||
|
@ -248,13 +249,30 @@ export function AddContainer(
|
||||||
setHistoryCurrentStep(history.length - 1);
|
setHistoryCurrentStep(history.length - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
function ApplyAddMethod(index: number, containerConfig: IAvailableContainer, parentClone: IContainerModel, x: number): number {
|
/**
|
||||||
|
* Returns a new offset by applying an Add method (append, insert etc.)
|
||||||
|
* See AddMethod
|
||||||
|
* @param index Index of the container
|
||||||
|
* @param containerConfig Configuration of a container
|
||||||
|
* @param parent Parent container
|
||||||
|
* @param x Additionnal offset
|
||||||
|
* @returns New offset
|
||||||
|
*/
|
||||||
|
function ApplyAddMethod(index: number, containerConfig: IAvailableContainer, parent: IContainerModel, x: number): number {
|
||||||
if (index > 0 && (
|
if (index > 0 && (
|
||||||
containerConfig.AddMethod === undefined ||
|
containerConfig.AddMethod === undefined ||
|
||||||
containerConfig.AddMethod === AddMethod.Append)) {
|
containerConfig.AddMethod === AddMethod.Append)) {
|
||||||
const lastChild: IContainerModel | undefined = parentClone.children.at(index - 1);
|
const lastChild: IContainerModel | undefined = parent.children.at(index - 1);
|
||||||
|
|
||||||
if (lastChild !== undefined) {
|
if (lastChild !== undefined) {
|
||||||
x += lastChild.properties.x + Number(lastChild.properties.width);
|
const [transformedX] = transformPosition(
|
||||||
|
Number(lastChild.properties.x),
|
||||||
|
Number(lastChild.properties.y),
|
||||||
|
Number(lastChild.properties.width),
|
||||||
|
lastChild.properties.XPositionReference
|
||||||
|
);
|
||||||
|
|
||||||
|
x += transformedX + Number(lastChild.properties.width);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return x;
|
return x;
|
||||||
|
|
|
@ -130,7 +130,7 @@ function GetChildrenDimensionProps(props: IContainerProps, dimensionMargin: numb
|
||||||
return { childrenId, xChildrenStart, xChildrenEnd, yChildren, textChildren };
|
return { childrenId, xChildrenStart, xChildrenEnd, yChildren, textChildren };
|
||||||
}
|
}
|
||||||
|
|
||||||
function transformPosition(x: number, y: number, width: number, xPositionReference = XPositionReference.Left): [number, number] {
|
export function transformPosition(x: number, y: number, width: number, xPositionReference = XPositionReference.Left): [number, number] {
|
||||||
let transformedX = x;
|
let transformedX = x;
|
||||||
if (xPositionReference === XPositionReference.Center) {
|
if (xPositionReference === XPositionReference.Center) {
|
||||||
transformedX -= width / 2;
|
transformedX -= width / 2;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { IContainerModel } from '../../../Interfaces/IContainerModel';
|
import { IContainerModel } from '../../../Interfaces/IContainerModel';
|
||||||
import { getAbsolutePosition } from '../../../utils/itertools';
|
import { getAbsolutePosition } from '../../../utils/itertools';
|
||||||
|
import { transformPosition } from './Container';
|
||||||
|
|
||||||
interface ISelectorProps {
|
interface ISelectorProps {
|
||||||
selected: IContainerModel | null
|
selected: IContainerModel | null
|
||||||
|
@ -15,6 +16,12 @@ export const Selector: React.FC<ISelectorProps> = (props) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const [x, y] = getAbsolutePosition(props.selected);
|
const [x, y] = getAbsolutePosition(props.selected);
|
||||||
|
const [transformedX, transformedY] = transformPosition(
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
Number(props.selected.properties.width),
|
||||||
|
props.selected.properties.XPositionReference
|
||||||
|
);
|
||||||
const [width, height] = [
|
const [width, height] = [
|
||||||
props.selected.properties.width,
|
props.selected.properties.width,
|
||||||
props.selected.properties.height
|
props.selected.properties.height
|
||||||
|
@ -31,8 +38,8 @@ export const Selector: React.FC<ISelectorProps> = (props) => {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<rect
|
<rect
|
||||||
x={x}
|
x={transformedX}
|
||||||
y={y}
|
y={transformedY}
|
||||||
width={width}
|
width={width}
|
||||||
height={height}
|
height={height}
|
||||||
style={style}
|
style={style}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue