Resize Rack1...very strange

Hi!!

I am testing these component, and I would like to know how to resolve this problem in Planogrammer example:

I insert 2 nodes into Rack1, and check “move and resize display” option.
When I resize Rack1, nodes not moves together, very strange!!
See my image as example…And when I move Rack2, 2 nodes are with it yet

Thanks!

Yes, it looks like if you resize the left or top sides, the objects within the rack don’t “stick” to the spot they are supposed to.



I’ll see what I can do…

Please, I will wait your answer, ( another way…) because it´s very strange .
Thank you !

Add this to the Rack class (or the Display class if you want the same behavior for Shelf).



protected override void OnChildBoundsChanged(GoObject child, RectangleF old) {

base.OnChildBoundsChanged(child, old);

if (child is RackGrid && child != null) {

float dX = child.Left - old.X;

float dY = child.Top - old.Y;

if (dX != 0 || dY != 0) {

foreach (GoObject obj in GetEnumerator()) {

if (!(obj is Item)) continue;

RectangleF r = obj.Bounds;

obj.Bounds = new RectangleF(r.X + dX, r.Y + dY, r.Width, r.Height);

}

}

}

}





Note there isn’t any code here that prevents the RackGrid from getting smaller than the objects contained within it, so there is still an issue there. If you care about that, you could fix that in RackGrid.ComputeResize and limit the grid so it always is big enough to contain all the Item objects.

Hi Jake!!

I inserted protected override void OnChildBoundsChanged() event, but as you said, there is still an issue there... Do you have a code example to insert in RackGrid.ComputeResize() ?
Thank you very much!

Replace RackGrid.ComputeResize with this:



// it can be resized only in positive multiples of Item.UnitSize

public override RectangleF ComputeResize(RectangleF origRect, PointF newPoint, int handle, SizeF min, SizeF max, bool reshape) {

RectangleF r = base.ComputeResize(origRect, newPoint, handle, min, max, reshape);

Rack rack = this.Parent as Rack;

if (rack != null) {

RectangleF rMin = new RectangleF();

bool any = false;

foreach (GoObject obj in rack.GetEnumerator()) {

if (obj is Item) {

if (!any) {

rMin = obj.Bounds;

any = true;

}

else {

// add the object’s bounding rect to this one

rMin = UnionRect(rMin, obj.Bounds);

}

}

}

if (any) r = UnionRect(r, rMin);

}



r.Width = Math.Max(1, (float)Math.Round(r.Width / Item.UnitSize)) * Item.UnitSize;

r.Height = Math.Max(1, (float)Math.Round(r.Height / Item.UnitSize)) * Item.UnitSize;



return r;

}



static RectangleF UnionRect(RectangleF a, RectangleF b) {

float minx = Math.Min(a.X, b.X);

float miny = Math.Min(a.Y, b.Y);

float maxr = Math.Max(a.X + a.Width, b.X + b.Width);

float maxb = Math.Max(a.Y + a.Height, b.Y + b.Height);

return new RectangleF(minx, miny, maxr - minx, maxb - miny);

}

Thank you! Now It´s good.