Announcement

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

    DynamicForm width

    Is there a trick or something to getting the width of a DynamicForm? I've got a form I create without a specific size - it sizes itself based on the content, which is DS-driven. Great. But I want to find out the size of the form at runtime, and I can't - it always returns 100 as the width, no matter what. The Developer Console correctly shows its width (in the high 200s), but everything I try gives 100. I've been using getWidth(), but I've also tried getDefaultWidth(), getOffsetWidth() and getVisibleWidth(). All return 100. I even tried using getRect.getWidth() - still 100. I tried getRight() - getLeft(), and that gave 100.

    So is there something obvious I'm doing wrong?

    #2
    getVisibleWidth() is the right API, but it won't know the width until the form is drawn.

    Comment


      #3
      Originally posted by Isomorphic
      getVisibleWidth() is the right API, but it won't know the width until the form is drawn.
      Thanks, now I know the right call. But in my case, I'm not calling it until well after the form is drawn. Still 100.

      Comment


        #4
        Then that is the actual width, because the width setting acts as a minimum with overflow:visible. If you're trying to shrinkwrap a small form, set a smaller width.

        Comment


          #5
          Originally posted by Isomorphic
          Then that is the actual width, because the width setting acts as a minimum with overflow:visible. If you're trying to shrinkwrap a small form, set a smaller width.
          But as I said, it's not the right width. I can see it's not, and the Developer Console is reporting the actual width, which is in the high 200's.

          Comment


            #6
            The Developer Console is calling getVisibleWidth(). It's likely you're calling the API on a different form from what you're looking at in the Developer Console.

            Comment


              #7
              Originally posted by Isomorphic
              The Developer Console is calling getVisibleWidth(). It's likely you're calling the API on a different form from what you're looking at in the Developer Console.
              Okay, thanks. I'll look into that possibility.

              Thanks for your help and quick replies.

              Comment


                #8
                I'm on SmartGWT 5.0-p20141024.

                I'm having the same problem except for HLayout. Most of the time getVisibleWidth returns the correct result.

                However, when things are drawn in an alternate orders I get 100 for getVisibleWidth. I have called draw(), show(), setVisible(true) before calling getVisibleWidth. None of these have helped. I still get 100 from getVisibleWidth. The "real" visible width is 282. I know this because other HLayouts that are just instances of a class that I extended from HLayout return the correct getVisibleWidth of 282.

                As in the case that Budfudder reported I’m trying to find the width at run time so I can determine how much room I have to put things into the HLayout (this is a wrap scenario). If there is not enough room I create another HLayout below and add things to it. The second HLayout works correctly returning 282 for getVisibleWidth.

                I would surely like to provide you a test case, but at this point my application is too complex to extract a simple test case. Also, as indicated getVisibleWidth doesn't work consistently within my application.

                In reading this thread it’s not really clear whether this issue has been resolved. There was no final answer to Budfudder.

                If possible, could I please get the resolution of this issue if it has been resolved?

                I have no proof, but it seems the circumstantial evidence from my and Budfudder’s experienced suggests there is a bug with getVisibleWidth.

                Comment


                  #9
                  A framebug bug with getVisibleWidth() is rather implausible, since the framework itself uses getVisibleWidth() to size and place widgets, so if it misbehaved you'd see things like overlapping placement of Layout members.

                  Instead, most likely your issue is like Budfudder's - you're just calling getVisibleWidth() at the wrong time. Some examples of calling at the wrong time:

                  1. before the widget is actually drawn (trivial to check, since all Canvases offer an isDrawn() check)

                  2. while the widget is pending a redraw that will change it's size (trivial to check: isDirty())

                  3. for a form or layout, checking the width before items or members are supplied, respectively

                  4. checking the width before data is applied that will cause a widget's width to grow

                  Comment


                    #10
                    Originally posted by Isomorphic View Post
                    1. before the widget is actually drawn (trivial to check, since all Canvases offer an isDrawn() check)
                    Instead, most likely your issue is like Budfudder's - you're just calling getVisibleWidth() at the wrong time.
                    This is correct. isDrawn() is returning false. However, I call draw() and isDrawn returns false after I call draw(). Is there a way to “force” the widget’s state to isDrawn()==true?

                    Originally posted by Isomorphic View Post
                    2. while the widget is pending a redraw that will change it's size (trivial to check: isDirty())
                    isDirty() is returning false before and after a call to draw() and when I call getVisibleWidth() ;

                    Originally posted by Isomorphic View Post
                    3. for a form or layout, checking the width before items or members are supplied, respectively
                    The HLayout widget has 5 members at the time I call getVisibleWidth().


                    Originally posted by Isomorphic View Post
                    4. checking the width before data is applied that will cause a widget's width to grow
                    The problem I’m encountering is not that the widget gets wider, but that getVisibleWidth() is smaller than the actual visible width with 5 members.

                    Comment


                      #11
                      If draw() is called but the widget declines to draw, the reason is always logged in the Developer Console.

                      Make sure you pay attention to the logs in the Developer Console.

                      Comment


                        #12
                        I found a solution to the problem. Hopefully this post will help others who run into the same problem.

                        To summarize the net of this thread:
                        • To get the width of a canvas, you can call getVisibleWidth
                        • To get the correct value from getVisibleWidth for a canvas, the canvas must be drawn.
                        • To know if a canvas is drawn, you can call isDrawn on the canvas.
                        • To draw a canvas that is not drawn, its parent of the canvas (i.e parent.isDrawn()==true) must be drawn.


                        I wrote a small method to follow the ancestor chain to make sure all parents, grandparents, great grandparents, etc. are drawn.

                        Code:
                        public class AncestorDraw {
                        
                        	public static void draw(Canvas canvas) {
                        
                        		if (canvas == null)
                        			return;
                        
                        		if (canvas.isDrawn())
                        			return;
                        
                        		draw(canvas.getParentCanvas());
                        
                        		canvas.draw();
                        	}
                        
                        }

                        Comment

                        Working...
                        X