Announcement

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

    resizedHandler called multiple times

    Hi,

    this is probably obvious, but I still can not figure this out.

    I have a (SmartGWT) Canvas object, embedded in several layers of Layouts.

    I add a ResizedHandler to the canvas.

    When the browser window is resized, the attached handler is called several times. (The number is probably close to the number of embedded layers.)

    How can I avoid doing the (potentially costy) resize operation several times, and do it just once, when everything has finished?

    Thank you for your help:

    Csillag

    #2
    You should not generally see this unless you've got a widget that is misbehaving, for example, it is allocated a new size, overflows that size, is given a size matching the overflowed content, but then overflows this size again.

    Both the "layout" and "sizing" logs can be used to track this down, but you may want to simplify first (they produce lots of output).
    Last edited by Isomorphic; 26 Feb 2011, 08:17.

    Comment


      #3
      Originally posted by Isomorphic
      You should generally see this unless you've got a widget that is misbehaving,
      You mean, I generally should NOT see this, right?

      Comment


        #4
        Yes, sorry (corrected previous post too).

        Comment


          #5
          Originally posted by Isomorphic
          You should not generally see this unless you've got a widget that is misbehaving, for example, it is allocated a new size, overflows that size, is given a size matching the overflowed content, but then overflows this size again.
          OK, so I am obviously abusing the layout system somehow. Here is a simple example:

          Code:
          public class LayoutTester implements EntryPoint {
          	@Override public void onModuleLoad() {
          		// A title label
          		Label title = new Label("Title here.");
          		title.setAutoHeight();
          		// A header space (for title and the like)
          		VLayout titlePart = new VLayout();
          		titlePart.setShowEdges(true);
          		titlePart.setAutoHeight();
          		titlePart.setLayoutMargin(5);
          		titlePart.addMember(title);
          		// Space for main content
          		VLayout mainPart = new VLayout();
          		mainPart.setShowEdges(true);
          		mainPart.addResizedHandler(new ResizedHandler() {
          			@Override public void onResized(ResizedEvent event) {
          				SC.logWarn("Resized.");
          			}
          		});
          		// Page
          		VLayout page = new VLayout();
          		page.setShowEdges(true);
          		page.setWidth100();
          		page.setHeight100();
          		page.setLayoutMargin(5);
          		page.setMembersMargin(5);
          		page.addMember(titlePart);
          		page.addMember(mainPart);
          		page.draw();
          	}
          }
          If it wouldn't be obvious, my intent here is simply to
          - partition the available space into two parts
          - make the first part minimal, so that it's size is determined by it's content (in this case, a label)
          - make the second part take all the available space.

          With the above code, I get the layout I want, but the attached resized handler gets called
          - 9 times during the initial draw,
          - 8 times when I decrease browser window size,
          - 6 times when I increase browser window size.

          So, I am obviously doing something totally wrong, right?

          Would you please show me how to achieve the same properly?

          Thank you for your help:

          Csillag

          Comment


            #6
            I forgot to mention this:

            GWT version: 2.2.0
            SmartGWT version: SC_SNAPSHOT-2011-02-23/PowerEdition
            Browser: Mozilla/5.0 (X11; U; Linux i686 (x86_64); hu; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13

            Comment


              #7
              It's a little unclear if this is being reported correctly. Can you try turning on the "resize" log category and showing what it logs? This will report resizes only of components that have a DOM (otherwise the cost is negligible).

              Comment


                #8
                This what I get with the "resize" log category set to INFO, when I maximize my browser window. (As you can see from the "Resize handler called." messages, the resize handler is called 6 times during this.)

                Code:
                Global Log Priorities updated: Modified categories: {
                    "resize":4
                }
                22:39:05.962:TMR8:INFO:resize:isc_VLayout_2:resize of drawn component: new width/height: 1596,1017, old width/height: 620,746, delta width/height: 976,271
                22:39:05.964:TMR8:INFO:resize:isc_VLayout_0:resize of drawn component: new width/height: 1574,1, old width/height: 598,1, delta width/height: 976,0
                22:39:05.966:TMR8:INFO:resize:isc_Label_0:resize of drawn component: new width/height: 1552,1, old width/height: 576,1, delta width/height: 976,0
                22:39:05.970:TMR8:INFO:resize:isc_EdgedCanvas_0:resize of drawn component: new width/height: 1574,35, old width/height: 598,35, delta width/height: 976,0
                22:39:05.972:TMR8:INFO:resize:isc_VLayout_1:resize of drawn component: new width/height: 1574,989, old width/height: 598,684, delta width/height: 976,305
                22:39:05.973:TMR8:INFO:resize:isc_EdgedCanvas_1:resize of drawn component: new width/height: 1574,989, old width/height: 598,684, delta width/height: 976,305
                22:39:05.976:TMR8:WARN:Log:Resize handler called.
                22:39:05.986:TMR8:INFO:resize:isc_VLayout_1:resize of drawn component: new width/height: 1574,955, old width/height: 1574,989, delta width/height: 0,-34
                22:39:05.994:TMR8:INFO:resize:isc_EdgedCanvas_1:resize of drawn component: new width/height: 1574,955, old width/height: 1574,989, delta width/height: 0,-34
                22:39:06.002:TMR8:WARN:Log:Resize handler called.
                22:39:06.010:TMR8:INFO:resize:isc_EdgedCanvas_2:resize of drawn component: new width/height: 1596,1017, old width/height: 620,746, delta width/height: 976,271
                22:39:06.015:TMR8[E]:INFO:resize:isc_VLayout_1:resize of drawn component: new width/height: 1574,989, old width/height: 1574,955, delta width/height: 0,34
                22:39:06.016:TMR8[E]:INFO:resize:isc_EdgedCanvas_1:resize of drawn component: new width/height: 1574,989, old width/height: 1574,955, delta width/height: 0,34
                22:39:06.025:TMR8[E]:WARN:Log:Resize handler called.
                22:39:06.027:TMR8[E]:INFO:resize:isc_VLayout_1:resize of drawn component: new width/height: 1574,955, old width/height: 1574,989, delta width/height: 0,-34
                22:39:06.028:TMR8[E]:INFO:resize:isc_EdgedCanvas_1:resize of drawn component: new width/height: 1574,955, old width/height: 1574,989, delta width/height: 0,-34
                22:39:06.034:TMR8[E]:WARN:Log:Resize handler called.
                22:39:06.061:TMR3[E]:INFO:resize:isc_VLayout_1:resize of drawn component: new width/height: 1574,989, old width/height: 1574,955, delta width/height: 0,34
                22:39:06.062:TMR3[E]:INFO:resize:isc_EdgedCanvas_1:resize of drawn component: new width/height: 1574,989, old width/height: 1574,955, delta width/height: 0,34
                22:39:06.064:TMR3[E]:WARN:Log:Resize handler called.
                22:39:06.066:TMR3[E]:INFO:resize:isc_VLayout_1:resize of drawn component: new width/height: 1574,955, old width/height: 1574,989, delta width/height: 0,-34
                22:39:06.067:TMR3[E]:INFO:resize:isc_EdgedCanvas_1:resize of drawn component: new width/height: 1574,955, old width/height: 1574,989, delta width/height: 0,-34
                22:39:06.070:TMR3[E]:WARN:Log:Resize handler called.
                This is what I get when I restore the previous browser size (from maximized):

                Code:
                22:41:51.375:TMR5:INFO:resize:isc_VLayout_2:resize of drawn component: new width/height: 605,731, old width/height: 1596,1017, delta width/height: -991,-286
                22:41:51.377:TMR5:INFO:resize:isc_VLayout_0:resize of drawn component: new width/height: 583,1, old width/height: 1574,1, delta width/height: -991,0
                22:41:51.378:TMR5:INFO:resize:isc_Label_0:resize of drawn component: new width/height: 561,1, old width/height: 1552,1, delta width/height: -991,0
                22:41:51.383:TMR5:INFO:resize:isc_EdgedCanvas_0:resize of drawn component: new width/height: 583,35, old width/height: 1574,35, delta width/height: -991,0
                22:41:51.385:TMR5:INFO:resize:isc_VLayout_1:resize of drawn component: new width/height: 583,703, old width/height: 1574,955, delta width/height: -991,-252
                22:41:51.387:TMR5:INFO:resize:isc_EdgedCanvas_1:resize of drawn component: new width/height: 583,703, old width/height: 1574,955, delta width/height: -991,-252
                22:41:51.390:TMR5:WARN:Log:Resize handler called.
                22:41:51.394:TMR5:INFO:resize:isc_VLayout_1:resize of drawn component: new width/height: 583,669, old width/height: 583,703, delta width/height: 0,-34
                22:41:51.396:TMR5:INFO:resize:isc_EdgedCanvas_1:resize of drawn component: new width/height: 583,669, old width/height: 583,703, delta width/height: 0,-34
                22:41:51.398:TMR5:WARN:Log:Resize handler called.
                22:41:51.403:TMR5:INFO:resize:isc_EdgedCanvas_2:resize of drawn component: new width/height: 605,731, old width/height: 1596,1017, delta width/height: -991,-286
                22:41:51.406:TMR5[E]:INFO:resize:isc_VLayout_1:resize of drawn component: new width/height: 583,703, old width/height: 583,669, delta width/height: 0,34
                22:41:51.407:TMR5[E]:INFO:resize:isc_EdgedCanvas_1:resize of drawn component: new width/height: 583,703, old width/height: 583,669, delta width/height: 0,34
                22:41:51.409:TMR5[E]:WARN:Log:Resize handler called.
                22:41:51.411:TMR5[E]:INFO:resize:isc_VLayout_1:resize of drawn component: new width/height: 583,669, old width/height: 583,703, delta width/height: 0,-34
                22:41:51.412:TMR5[E]:INFO:resize:isc_EdgedCanvas_1:resize of drawn component: new width/height: 583,669, old width/height: 583,703, delta width/height: 0,-34
                22:41:51.414:TMR5[E]:WARN:Log:Resize handler called.
                22:41:51.469:TMR0:INFO:resize:isc_VLayout_2:resize of drawn component: new width/height: 620,746, old width/height: 605,731, delta width/height: 15,15
                22:41:51.471:TMR0:INFO:resize:isc_VLayout_0:resize of drawn component: new width/height: 598,1, old width/height: 583,1, delta width/height: 15,0
                22:41:51.472:TMR0:INFO:resize:isc_Label_0:resize of drawn component: new width/height: 576,1, old width/height: 561,1, delta width/height: 15,0
                22:41:51.476:TMR0:INFO:resize:isc_EdgedCanvas_0:resize of drawn component: new width/height: 598,35, old width/height: 583,35, delta width/height: 15,0
                22:41:51.478:TMR0:INFO:resize:isc_VLayout_1:resize of drawn component: new width/height: 598,718, old width/height: 583,669, delta width/height: 15,49
                22:41:51.479:TMR0:INFO:resize:isc_EdgedCanvas_1:resize of drawn component: new width/height: 598,718, old width/height: 583,669, delta width/height: 15,49
                22:41:51.481:TMR0:WARN:Log:Resize handler called.
                22:41:51.483:TMR0:INFO:resize:isc_VLayout_1:resize of drawn component: new width/height: 598,684, old width/height: 598,718, delta width/height: 0,-34
                22:41:51.484:TMR0:INFO:resize:isc_EdgedCanvas_1:resize of drawn component: new width/height: 598,684, old width/height: 598,718, delta width/height: 0,-34
                22:41:51.486:TMR0:WARN:Log:Resize handler called.
                22:41:51.488:TMR0:INFO:resize:isc_EdgedCanvas_2:resize of drawn component: new width/height: 620,746, old width/height: 605,731, delta width/height: 15,15
                22:41:51.492:TMR0[E]:INFO:resize:isc_VLayout_1:resize of drawn component: new width/height: 598,718, old width/height: 598,684, delta width/height: 0,34
                22:41:51.493:TMR0[E]:INFO:resize:isc_EdgedCanvas_1:resize of drawn component: new width/height: 598,718, old width/height: 598,684, delta width/height: 0,34
                22:41:51.496:TMR0[E]:WARN:Log:Resize handler called.
                22:41:51.497:TMR0[E]:INFO:resize:isc_VLayout_1:resize of drawn component: new width/height: 598,684, old width/height: 598,718, delta width/height: 0,-34
                22:41:51.498:TMR0[E]:INFO:resize:isc_EdgedCanvas_1:resize of drawn component: new width/height: 598,684, old width/height: 598,718, delta width/height: 0,-34
                22:41:51.500:TMR0[E]:WARN:Log:Resize handler called.
                (Total: 8 resize calls)

                And this is what I get during the initial draw:

                Code:
                22:42:24.979:INFO:Log:initialized
                22:42:25.361:WARN:AutoObserver:Use addInterfaceProperties() to add methods to interface [Class AutoObserver]
                22:42:29.356:WARN:Log:Resize handler called.
                22:42:29.367:WARN:Log:Resize handler called.
                22:42:29.423:INFO:resize:isc_VLayout_1:resize of drawn component: new width/height: 1574,955, old width/height: 1574,989, delta width/height: 0,-34
                22:42:29.424:INFO:resize:isc_EdgedCanvas_1:resize of drawn component: new width/height: 1574,955, old width/height: 1574,989, delta width/height: 0,-34
                22:42:29.426:WARN:Log:Resize handler called.
                22:42:29.500:INFO:Log:isc.Page is loaded
                22:42:29.543:TMR0:INFO:resize:isc_VLayout_1:resize of drawn component: new width/height: 1574,989, old width/height: 1574,955, delta width/height: 0,34
                22:42:29.545:TMR0:INFO:resize:isc_EdgedCanvas_1:resize of drawn component: new width/height: 1574,989, old width/height: 1574,955, delta width/height: 0,34
                22:42:29.547:TMR0:WARN:Log:Resize handler called.
                22:42:29.555:TMR0:INFO:resize:isc_VLayout_1:resize of drawn component: new width/height: 1574,955, old width/height: 1574,989, delta width/height: 0,-34
                22:42:29.556:TMR0:INFO:resize:isc_EdgedCanvas_1:resize of drawn component: new width/height: 1574,955, old width/height: 1574,989, delta width/height: 0,-34
                22:42:29.560:TMR0:WARN:Log:Resize handler called.
                22:42:29.588:TMR3[E]:INFO:resize:isc_VLayout_1:resize of drawn component: new width/height: 1574,989, old width/height: 1574,955, delta width/height: 0,34
                22:42:29.604:TMR3[E]:INFO:resize:isc_EdgedCanvas_1:resize of drawn component: new width/height: 1574,989, old width/height: 1574,955, delta width/height: 0,34
                22:42:29.615:TMR3[E]:WARN:Log:Resize handler called.
                22:42:29.639:TMR3[E]:INFO:resize:isc_VLayout_1:resize of drawn component: new width/height: 1574,955, old width/height: 1574,989, delta width/height: 0,-34
                22:42:29.640:TMR3[E]:INFO:resize:isc_EdgedCanvas_1:resize of drawn component: new width/height: 1574,955, old width/height: 1574,989, delta width/height: 0,-34
                22:42:29.649:TMR3[E]:WARN:Log:Resize handler called.
                22:42:29.683:TMR6[E]:INFO:resize:isc_VLayout_1:resize of drawn component: new width/height: 1574,989, old width/height: 1574,955, delta width/height: 0,34
                22:42:29.684:TMR6[E]:INFO:resize:isc_EdgedCanvas_1:resize of drawn component: new width/height: 1574,989, old width/height: 1574,955, delta width/height: 0,34
                22:42:29.687:TMR6[E]:WARN:Log:Resize handler called.
                22:42:29.693:TMR6[E]:INFO:resize:isc_VLayout_1:resize of drawn component: new width/height: 1574,955, old width/height: 1574,989, delta width/height: 0,-34
                22:42:29.694:TMR6[E]:INFO:resize:isc_EdgedCanvas_1:resize of drawn component: new width/height: 1574,955, old width/height: 1574,989, delta width/height: 0,-34
                22:42:29.698:TMR6[E]:WARN:Log:Resize handler called.
                22:42:29.724:TMR9[E]:INFO:resize:isc_VLayout_1:resize of drawn component: new width/height: 1574,989, old width/height: 1574,955, delta width/height: 0,34
                22:42:29.725:TMR9[E]:INFO:resize:isc_EdgedCanvas_1:resize of drawn component: new width/height: 1574,989, old width/height: 1574,955, delta width/height: 0,34
                22:42:29.727:TMR9[E]:WARN:Log:Resize handler called.
                22:42:29.731:TMR9[E]:INFO:resize:isc_VLayout_1:resize of drawn component: new width/height: 1574,955, old width/height: 1574,989, delta width/height: 0,-34
                22:42:29.733:TMR9[E]:INFO:resize:isc_EdgedCanvas_1:resize of drawn component: new width/height: 1574,955, old width/height: 1574,989, delta width/height: 0,-34
                22:42:29.735:TMR9[E]:WARN:Log:Resize handler called.
                (9 resize requests on the main area.)

                Comment


                  #9
                  Thanks for the info. We're looking into it and will let you know what we find

                  Isomorphic Software

                  Comment


                    #10
                    Several resizes can be eliminated with better settings. Presumably, you do not want to overflow the overall page size and introduce browser-level scrollbars, if so, setOverflow(hidden) on the "page" Layout. Likewise, if you are trying to stay within the page, you probably want "mainPart" to be overflow:"hidden" or perhaps overflow:"auto".

                    What this basically does is turn off auto-sizing for these parts of the page, so there will never be an attempt to resize them then see if they can actually fit in the specified space.

                    Comment


                      #11
                      (Unfortunately I did not notice your answer earlier.)

                      * * *

                      I tested again with the nightly from 03.03. With this version, without any modification to my code, the resize numbers for load/max/restore went down from the original 9/6/8 to 5/2/4. Have you changed something about the layout engine?

                      When applying the modifications you have suggested, I got the numbers down to 2/1/2, which is totally OK for now. (Intetestingly, this is all because of the mainPart settings; the page settings did not seem to do any difference.)

                      Thank you for your help:

                      Csillag

                      Comment


                        #12
                        We removed some redundant page-level resize notifications that could cause extra resizes.

                        Comment


                          #13
                          Thank you, that definitely helped, too.

                          Comment

                          Working...
                          X