Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Dragging child with keepInParentRect=true

    There is a problem when dragging a child canvas that is inside a parent canvas and the child has child.setKeepInParentRect(true). Basically when you try to drag the child out of the parent to the left, top or bottom side it works as expected: nothing happens to the parent and the child "can't get out". When you drag the child out of the parent to the right, the parentcanvas becomes bigger (slowly)

    This was tested on SmartGWT Power 2.5, GWT 2.1.0 and Internet explorer 9

    Code:
    package test.client;
    
    import com.google.gwt.core.client.EntryPoint;
    import com.smartgwt.client.types.Alignment;
    import com.smartgwt.client.types.DragAppearance;
    import com.smartgwt.client.types.Overflow;
    import com.smartgwt.client.types.VerticalAlignment;
    import com.smartgwt.client.widgets.Canvas;
    import com.smartgwt.client.widgets.Label;
    import com.smartgwt.client.widgets.layout.HLayout;
    import com.smartgwt.client.widgets.layout.VLayout;
    
    public class Test implements EntryPoint {
    
    	private Canvas label = new Canvas();
    	private Label child = new Label();
    	private HLayout labelHLayout = new HLayout();
    	private VLayout labelVLayout = new VLayout();
    
    	
    	public void onModuleLoad() {
    		createVisualization();
    		addLabelChild();
    	}
    	
    	private void createVisualization() {
    		label.setBorder("2px solid black");
    		label.setWidth(500);
    		label.setHeight(250);
    		
    		labelHLayout.setWidth100();
    		labelHLayout.setAlign(Alignment.CENTER);
    		labelHLayout.setHeight(250);
    		labelHLayout.addMember(label);
    		
    		labelVLayout.setWidth100();
    		labelVLayout.setHeight100();
    		labelVLayout.setAlign(VerticalAlignment.CENTER);
    		labelVLayout.setOverflow(Overflow.AUTO);
    		labelVLayout.addMember(labelHLayout);
    		labelVLayout.draw();		
    	}
    	
    	private void addLabelChild() {
    		child.setTop(50);
    		child.setLeft(50);
    		child.setWidth(50);
    		child.setHeight(50);
    		
    		child.setBackgroundColor("black");
    		child.setPadding(2);
    		child.setKeepInParentRect(true);
    		child.setCanDragResize(true);
    		child.setCanDragReposition(true);
    		
    		child.setDragAppearance(DragAppearance.TARGET);
    		child.setWrap(true);
    		child.setAutoFit(false);
    		
    		label.addChild(child);		
    	}
    }

    #2
    The parent that you are trying to use for keepInParentRect should be overflow:"hidden". Otherwise it will expand to accommodate contents, as you've noticed.

    Comment

    Working...
    X