Announcement

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

    markForRedraw() not working

    I am trying to redraw my layout when the user resizes the window.

    You can see it running here: https://dev.3dmathpuzzles.com/3dmp/D...therlink2.html
    The div containing the layout has a green border. It resizes when the window resizes.

    My WindowResizeHandler is getting called when I resize the window (I get a Window alert), but the onDraw method of the LayoutHandler is not getting called.

    Here is a sample application:
    Code:
    package com._3dmathpuzzles.gwt.client;
    
    import com.google.gwt.core.client.EntryPoint;
    import com.google.gwt.dom.client.Document;
    import com.google.gwt.dom.client.Element;
    import com.google.gwt.user.client.Window;
    import com.smartgwt.client.widgets.drawing.DrawPane;
    import com.smartgwt.client.widgets.layout.VLayout;
    
    public class DiagonalSlitherlink2 implements EntryPoint {
      private DrawPane drawPane;
    
      public void onModuleLoad() {
        drawPane = new DrawPane();
        drawPane.setShowEdges(true);
        drawPane.setEdgeSize(1);
        drawPane.setCanDragScroll(true);
        drawPane.setZoomLevel(1.0);
        drawPane.addDrawHandler(new DiagonalSlitherlinkDrawHandler2());
    
        Element gwtElement = Document.get().getElementById("gwt");
        VLayout layout = new VLayout();
        layout.addDrawHandler(new LayoutDrawHandler());
        layout.addDrawHandler(new ButtonDrawHandler(drawPane));
        layout.setHtmlElement(gwtElement);
        layout.addMember(drawPane);
        layout.setLayoutMargin(0);
        layout.setMembersMargin(0);
        layout.setRedrawOnResize(true);
        layout.draw();
    
        Window.addResizeHandler(new WindowResizeHandler(layout,drawPane));
      }
    }
    Here is the WindowResizeHandler:
    Code:
    package com._3dmathpuzzles.gwt.client;
    
    import com.google.gwt.event.logical.shared.ResizeEvent;
    import com.google.gwt.event.logical.shared.ResizeHandler;
    import com.google.gwt.user.client.Window;
    import com.smartgwt.client.widgets.drawing.DrawPane;
    import com.smartgwt.client.widgets.layout.Layout;
    
    public class WindowResizeHandler implements ResizeHandler {
      private Layout layout;
      private DrawPane drawPane;
    
      public WindowResizeHandler(Layout layout, DrawPane drawPane) {
        this.layout = layout;
        this.drawPane = drawPane;
      }
    
      public void onResize(ResizeEvent event) {
        Window.alert("In WindowResizeHandler.onResize()");
        layout.markForRedraw();
        layout.redraw();
        layout.draw();
        drawPane.markForRedraw();
        drawPane.redraw();
        drawPane.draw();
      }
    }
    Here is the draw handler:
    Code:
    package com._3dmathpuzzles.gwt.client;
    
    import com.smartgwt.client.widgets.drawing.DrawLine;
    import com.smartgwt.client.widgets.drawing.DrawPane;
    import com.smartgwt.client.widgets.drawing.Point;
    import com.smartgwt.client.widgets.events.DrawEvent;
    import com.smartgwt.client.widgets.events.DrawHandler;
    
    public class DiagonalSlitherlinkDrawHandler2 implements DrawHandler {
      public void onDraw(DrawEvent event) {
        DrawPane drawPane = (DrawPane) event.getSource();
    
        DrawLine drawLine = new DrawLine();
        drawLine.setStartPoint(new Point(0,0));
        drawLine.setEndPoint(new Point(1000,1000));
        drawLine.setDrawPane(drawPane);
        drawLine.draw();
      }
    }

    #2
    In a previous thread, you showed that you're setting the width and height of the layout manually in code on initial draw() - so you'll have to do that again when your window/container-element resizes.

    If your SmartGWT DrawPane is sized at 100% of the SmartGWT Layout, it should resize when you resize the Layout.

    Comment


      #3
      Yes, my LayoutDrawHandler sets the width and height of the VLayout:
      Code:
      package com._3dmathpuzzles.gwt.client;
      
      import com.google.gwt.dom.client.Element;
      import com.google.gwt.user.client.Window;
      import com.smartgwt.client.widgets.events.DrawEvent;
      import com.smartgwt.client.widgets.events.DrawHandler;
      import com.smartgwt.client.widgets.layout.Layout;
      
      public class LayoutDrawHandler implements DrawHandler {
        public void onDraw(DrawEvent event) {
          Window.alert("In LayoutDrawHandler.onDraw()");
          Layout layout = (Layout) event.getSource();
      
          Element element = layout.getHtmlElement();
          int elementWidth = element.getOffsetWidth();
          int elementHeight = element.getOffsetHeight();
          int min = elementWidth;
          if( min > elementHeight )
            min = elementHeight;
          layout.setWidth(min);
          layout.setHeight(min);
        }
      }
      But, the onDraw method in it is not being called even though I called layout.markForRedraw() from WindowResizeHandler
      Last edited by NeilAgg; 23 Dec 2024, 09:51.

      Comment


        #4
        onDraw is called on initial draw, not redraw.

        You can just use the layoutChildren override point or the Resized event.

        Also, there is no obvious need to redraw here per se - just resize. Resizing will cause a redraw if the component needs to; many do not need to on a resize.

        Comment

        Working...
        X