Announcement

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

    how to get notified when a widget moves?

    Hi all,

    I would like to register a handler that gets called whenever a given widget is moved - that is, it's absolute position in the page is changed.

    (It can move because of several reasons, including window resize, changes in other widgets, layout changes, etc.)

    I have found the handlers for drag move (different use case), for resize (different use case), but can't find a simple "Moved" event handler.

    So, how can one do that?

    Thank you for your help:

    Csillag

    #2
    GWT has addWindowResizeListener(WindowResizeListener listener).

    Layouts implement Interface HasResizedHandlers:
    HandlerRegistration addResizedHandler(ResizedHandler handler)
    Observable method called whenever a Canvas changes size.

    These seem like they could be used to solve most if not all of your problem.

    -=> Gregg <=-

    Comment


      #3
      Let's assume I have a VLayout, with 10 auto-sized members, and I want to know when the last member moves.

      If the content (and therefore, size) of any of the first 9 members changes, the tenth member will be moved, So, to catch this, I would need to register resized handlers for all the other members! (And I could still not be sure that I have covered all possible reasons for movement.)

      So, I think I am looking for something else.

      (But thanks, anyway.)

      Csillag

      Comment


        #4
        If you're only interested in one particular widget, can't you simply register the handler for the layout, capture the position state of that widget within the layout before any movement occurs and then compare that previous state with the state of the widget each time the layout changes and react when the widget position state changes?

        -=> Gregg <=-

        Comment


          #5
          Originally posted by gsl1
          If you're only interested in one particular widget, can't you simply register the handler for the layout,
          Which handler, and which layout? You mean the parent layout?

          Typically, a given widget can be nested inside several levels of layouts, maybe more the 10 layouts inside layouts. Any change in these layouts will affect the widget.

          Are you suggesting to register resize handlers to all parent layouts?

          That does not sound too good, especially because the widget in question is usually not aware of it's environment - why should it be.

          So, I still think this should be handled locally, on the widget level, not by observing other layouts...

          Comment


            #6
            If there is a more elegant solution, maybe someone else can suggest one.

            -=> Gregg <=-

            Comment


              #7
              Currently I am considering to add a timer to check the position of the widgets periodically, and call repaint when the saved position changed.

              This would definitly work, but there is a penalty performance, so I would like to avoid doing this, is possible.

              So, I am really interested in how this is supposed to be done properly...

              Thank you for your help:

              Csillag

              Comment


                #8
                Another possibility might be to extend your widget to another class possibly with just an anonymous class, override the moveTo method, call its parent method with super and do whatever it is you want to do when the widget moves. This assumes that the toolkit invokes the moveTo method when it lays out the widget. If not this will, of course, not work.

                -=> Gregg <=-

                Comment


                  #9
                  If I am not mistaken, moveTo() is called when the widget is moved _locally_, that is, compared to it's parent.

                  However, I need to track _any_ movement, that is, both local and global - thus including those cases when the widget is not moving compared to it's parent, but moving together with it.

                  So I think I need more that this..

                  Thank you anyway:

                  Csillag

                  Comment


                    #10
                    Dear Isomorphic,

                    Do you have any idea how could I handle this properly?

                    Thank you for your help:

                    Csillag

                    Comment


                      #11
                      Hi Csillag,
                      We've exposed 2 new event handlers "moved()" [fired when a component explicitly moves due to setLeft() / setTop, etc] and "parentMoved()" [fired when an ancestor moves, which will of course reposition the component on the screen].

                      These will be present in the next nightly build

                      Thanks
                      Isomorphic Software

                      Comment


                        #12
                        Sounds great, thank you. I will check it out.

                        One more question:

                        - Will moved() fire when the movement is result of mouse drag?

                        - Will parentMoved() fire when the movement is result of mouse drag?

                        - When parentMoved() fires, is there a way to find out which parent was it?
                        (I can imagine use cases when I am only interested in movements in some lower part of the chain of ancestors, so I need to check.)

                        - When a parent moves, all children are re-positioned on the screen. The children's children don't get a new round of parentMoved() calls, do they?

                        Thank you:

                        Csillag

                        Comment


                          #13
                          moved() fires in response to the widget being moved via a call to 'setLeft()', 'setTop()', moveBy() (etc) or by dragging. It fires any time the specified top/left coordinate of the component changes.
                          The event has 'deltaX' and 'deltaY' attributes allowing you to see how much the coordinates changed (or you can just call getTop() / getLeft() etc).

                          This same set of events also triggers the component to fire "parentMoved()" on all its descendants, recursively.

                          So a component with a parentMoved handler in place will be notified when any ancestor (at any level, so immediate parent, or parent of immediate parent, etc) is moved.
                          The parentMoved event has 'deltaX' and 'deltaY' attributes, and also a 'parent' attribute which points to the Canvas that was actually moved.

                          Try it out and let us know if it doesn't work as expected for you.

                          Comment


                            #14
                            In Smart GWT these will appear as addMovedHandler(..) and add ParentMovedHandler(..)

                            Sanjiv

                            Comment


                              #15
                              Originally posted by sjivan
                              In Smart GWT these will appear as addMovedHandler(..) and add ParentMovedHandler(..)

                              Sanjiv
                              Any ETA for the SmartGWT (power) nightly that will contain this?

                              Comment

                              Working...
                              X