Skip to content
Snippets Groups Projects
Commit 5269a5f4 authored by rhenck's avatar rhenck
Browse files

[editor] Fix element alignment

- Move the method to the unit service, so the proper 
updateElementProperty method can be used.
- Also improve the logic, reducing variables.
parent a682b6d0
No related branches found
No related tags found
No related merge requests found
...@@ -47,35 +47,4 @@ export class Section { ...@@ -47,35 +47,4 @@ export class Section {
element.positionProps.dynamicPositioning = value; element.positionProps.dynamicPositioning = value;
}); });
} }
static alignElements(elements: PositionedElement[], alignmentDirection: 'left' | 'right' | 'top' | 'bottom'): void {
let newValue: number;
switch (alignmentDirection) {
case 'left':
newValue = Math.min(...elements.map(element => element.positionProps.xPosition));
elements.forEach((element: UIElement) => {
element.xPosition = newValue;
});
break;
case 'right':
newValue = Math.max(...elements.map(element => element.positionProps.xPosition + element.width));
elements.forEach((element: UIElement) => {
element.xPosition = newValue - element.width;
});
break;
case 'top':
newValue = Math.min(...elements.map(element => element.positionProps.yPosition));
elements.forEach((element: UIElement) => {
element.yPosition = newValue;
});
break;
case 'bottom':
newValue = Math.max(...elements.map(element => element.positionProps.yPosition + element.height));
elements.forEach((element: UIElement) => {
element.yPosition = newValue - element.height;
});
break;
// no default
}
}
} }
...@@ -200,6 +200,6 @@ export class ElementSizingPropertiesComponent { ...@@ -200,6 +200,6 @@ export class ElementSizingPropertiesComponent {
constructor(private unitService: UnitService, public selectionService: SelectionService) { } constructor(private unitService: UnitService, public selectionService: SelectionService) { }
alignElements(direction: 'left' | 'right' | 'top' | 'bottom'): void { alignElements(direction: 'left' | 'right' | 'top' | 'bottom'): void {
this.unitService.alignElements(this.selectionService.getSelectedElements(), direction); this.unitService.alignElements(this.selectionService.getSelectedElements() as PositionedElement[], direction);
} }
} }
...@@ -354,8 +354,38 @@ export class UnitService { ...@@ -354,8 +354,38 @@ export class UnitService {
); );
} }
alignElements(elements: UIElement[], alignmentDirection: 'left' | 'right' | 'top' | 'bottom'): void { alignElements(elements: PositionedElement[], alignmentDirection: 'left' | 'right' | 'top' | 'bottom'): void {
Section.alignElements(elements as PositionedElement[], alignmentDirection); switch (alignmentDirection) {
case 'left':
this.updateElementProperty(
elements,
'xPosition',
Math.min(...elements.map(element => element.positionProps.xPosition))
);
break;
case 'right':
this.updateElementProperty(
elements,
'xPosition',
Math.max(...elements.map(element => element.positionProps.xPosition))
);
break;
case 'top':
this.updateElementProperty(
elements,
'yPosition',
Math.min(...elements.map(element => element.positionProps.yPosition))
);
break;
case 'bottom':
this.updateElementProperty(
elements,
'yPosition',
Math.max(...elements.map(element => element.positionProps.yPosition))
);
break;
// no default
}
this.elementPropertyUpdated.next(); this.elementPropertyUpdated.next();
this.veronaApiService.sendVoeDefinitionChangedNotification(); this.veronaApiService.sendVoeDefinitionChangedNotification();
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment