How to trigger center action by passing position/coordinates as parameter #746
-
I am using vscode version of GLSP, Currently we can use org.eclipse.glsp.server.actions.CenterAction to bring any element to center of the viewport by passing ID as parameter. But I want pass extra parameter along with ID so that particular region/part of element will be shown at the center of viewport. example :
Is any way we can implement this requirement in GLSP? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Yes, you can create an own action that extends
So you would create a new subclass of getNewViewport(bounds: Bounds, model: SModelRoot): Viewport | undefined {
if (!Dimension.isValid(model.canvasBounds)) {
return undefined;
}
const zoom = (this.action.retainZoom && isViewport(model)) ? model.zoom : 1;
const c = Bounds.center(bounds);
return {
scroll: {
x: c.x + this.action.yourRelativeOffsetX - 0.5 * model.canvasBounds.width / zoom,
y: c.y + this.action.yourRelativeOffsetY - 0.5 * model.canvasBounds.height / zoom
},
zoom: zoom
};
} Alternatively, you can add a child node to your node and place it somehwere within its parent node and then center child node instead of the parent node. This may even be the better solution, depending on the structure of your |
Beta Was this translation helpful? Give feedback.
Yes, you can create an own action that extends
CenterAction
and register a custom command for your new action that takes a relative offset into account. So best look at the implementation of theCenterAction
and adjust to your needs:So you would create a new subclass of
CenterAction
and a subclass ofCenterCommand
(orBoundsAwareViewportCommand
), register the command as linked above in yourdi.config.ts
and adjust the implementation of yourCenterCommand
, e.g. as follows (seethis.action.yourRelativeOffsetX
and Y):