Resizing parent container does not properly resize its children [message #1840574] |
Mon, 19 April 2021 15:48 |
Alex Kravets Messages: 561 Registered: November 2009 |
Senior Member |
|
|
When I resize shape above I also want to resize its children - change position of the image and change width of horizontal line. Here is my resizeShape method
@Override
public void resizeShape(IResizeShapeContext context) {
super.resizeShape(context);
ContainerShape container = (ContainerShape) context.getPictogramElement();
EList<Shape> children = container.getChildren();
Shape image = children.get(0);
Shape line = children.get(1);
Shape text = children.get(2);
GraphicsAlgorithm containerGA = container.getGraphicsAlgorithm();
GraphicsAlgorithm lineGA = line.getGraphicsAlgorithm();
GraphicsAlgorithm imageGA = image.getGraphicsAlgorithm();
// reposition image
1. int x = (container.getGraphicsAlgorithm().getWidth() - 30) / 2;
Graphiti.getGaService().setLocation(imageGA, x, 5);
// reposition line
2. Graphiti.getGaService().setLocationAndSize(lineGA, lineGA.getX(), lineGA.getY(), containerGA.getWidth(), lineGA.getHeight());
}
The issues I am having with this code are:
In (1) I have to offset 'x' by 30 in order for the image be centered, it's centered initially, so why is offset needed? Without offset the image is positioned right of the center.
In (2) setting width to that of the container after it had been resized does noting to change the width of the line. Calling setLocationAndSize() works because if I change x and y of the lineGA to different values, I can see the line moving there after resize, so why does changing line width does not work?
[Updated on: Mon, 19 April 2021 15:51] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.03902 seconds