Skip to content

Commit

Permalink
feat(drawers): drawer selection (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
JyTosTT authored Sep 14, 2023
1 parent cadc2c7 commit d05e4fe
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
12 changes: 10 additions & 2 deletions front/src/services/canvas/Drawer.manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ export const DrawerManager: TDrawerManager = {
...StateCanvas,

findDrawer (position: IPosition): TDrawerOrNullify {
return this.drawers.find(drawer =>
drawer.factory!.isSelected(position))
return this.drawers
.slice()
.reverse()
.find(drawer =>
drawer.factory!.isSelected(position))
},

clearSelectedDrawer (): void {
Expand Down Expand Up @@ -60,5 +63,10 @@ export const DrawerManager: TDrawerManager = {

drawer.factory?.updatePosition(drawerPosition)
})
},

putDrawerOnTopLayer (drawer: TDrawer): TDrawer[] {
const cleanedDrawers = this.drawers.filter(d => d !== drawer)
return [...cleanedDrawers, drawer]
}
}
2 changes: 2 additions & 0 deletions front/src/services/canvas/MouseEvent.manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ const MouseEventManager: TMouseEventManager = {
y: position.y - drawer.factory!.positionY
}

this.drawers = this.putDrawerOnTopLayer(drawer)

this.selectDrawer(drawer)
} else if (this.selectedConnector == null) {
this.clearSelectedDrawer()
Expand Down
3 changes: 2 additions & 1 deletion front/src/types/canvas/Drawer.manager.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type IPosition } from '../../interfaces/Position.interface'
import { type TStateCanvas } from './State.canvas'
import { type TServiceDrawer } from '../board/drawer/Service.drawer'
import { type TDrawerOrNullify } from '../Drawer'
import { type TDrawer, type TDrawerOrNullify } from '../Drawer'

export type TDrawerManager =
TStateCanvas &
Expand All @@ -12,4 +12,5 @@ export type TDrawerManager =
clearOnHoverDrawer: () => void
updateHoverDrawer: (position: IPosition) => void
moveDrawersByPosition: (deltaPosition: IPosition) => void
putDrawerOnTopLayer: (drawer: TDrawer) => TDrawer[]
}

0 comments on commit d05e4fe

Please sign in to comment.