5 Replies Latest reply on Mar 30, 2009 12:25 PM by Newsgroup_User

    Container resize

    ysbelman
      I followed an example from cookbook to adjust the parent container size based on what is being added into it. The approach works by overriding measure() in a custom Canvas class. However, the measuredWidth does not return a value I "want" when a child has been positioned with horizontalAlign. Instead of measuring total position (child width+ left offset), measuredWidth returns just the child width.
      In the example below, measuredWidth evaluates to 150 and causes TextArea to get cut off because it's been centered. I tried padding and that worked into my favor, measuredWidth accounted for it.

      What shall i do about "centered" components? Is there a way to force them to re-center after my parent has obtained a new dimension?

      any of this make sense ? :p

      [CODE]
      // MyCanvas.as
      override protected function measure():void{
      super.measure();
      this.minWidth = this.measuredWidth;
      this.minHeight = this.measuredHeight;
      }

      //ResizeTest.mxml
      <test:MyCanvas id="topCanvas" height="100%" width="100%">
      <mx:VBox id="child2" width="100%" height="100%" backgroundColor="#993333" horizontalAlign="center"
      childAdd="onChildAdd(event)">
      <mx:Button label="Test button 3" />
      <mx:Button label="Test button 4" />
      <mx:TextArea width="150" height="300" />
      </mx:VBox>
      </test:MyCanvas>
      [/CODE]
        • 1. Re: Container resize
          Level 7

          "ysbelman" <webforumsuser@macromedia.com> wrote in message
          news:gqmdeo$6pr$1@forums.macromedia.com...
          >I followed an example from cookbook to adjust the parent container size
          >based
          > on what is being added into it. The approach works by overriding measure()
          > in a
          > custom Canvas class. However, the measuredWidth does not return a value I
          > "want" when a child has been positioned with horizontalAlign. Instead of
          > measuring total position (child width+ left offset), measuredWidth returns
          > just
          > the child width.
          > In the example below, measuredWidth evaluates to 150 and causes TextArea
          > to
          > get cut off because it's been centered. I tried padding and that worked
          > into my
          > favor, measuredWidth accounted for it.
          >
          > What shall i do about "centered" components? Is there a way to force them
          > to
          > re-center after my parent has obtained a new dimension?
          >
          > any of this make sense ? :p

          No. The Canvas shouldn't care if it's child's children are centered or not.
          The horizontalAlign is applied to the VBox, not the Canvas. I suspect
          something else is going on here.


          • 2. Re: Container resize
            ysbelman Level 1
            I got it to work.

            My next step is to extend HDividedBox and VDividedBox. I noticed that Box.measure() returns the sum of all children's sizes and ignores the empty space. For example, if i have a
            <MyVDividedBox height="500" width="500">
            <HBox width="100%" height="100%">
            <Button>
            </HBox>
            </MyVDividedBox>

            measuredHeight would return 20 instead of the actual box size. How come? Can i make the box size to be counted instead ?
            • 3. Re: Container resize
              Level 7

              "ysbelman" <webforumsuser@macromedia.com> wrote in message
              news:gqp44q$gin$1@forums.macromedia.com...
              >I got it to work.
              >
              > My next step is to extend HDividedBox and VDividedBox. I noticed that
              > Box.measure() returns the sum of all children's sizes and ignores the
              > empty
              > space. For example, if i have a
              > <MyVDividedBox height="500" width="500">
              > <HBox width="100%" height="100%">
              > <Button>
              > </HBox>
              > </MyVDividedBox>
              >
              > measuredHeight would return 20 instead of the actual box size. How come?
              > Can i
              > make the box size to be counted instead ?

              measuredHeight tells anything the Box might be in that this is the height it
              needs to actually display its children, not the height it actually is.

              HTH;

              Amy


              • 4. Re: Container resize
                ysbelman Level 1
                Amy, what you said makes sense and consistent with what i am observing...almost. When i look at what box returns for measuredHeight after i add/remove a child, it is different then when i "touch" the divider bar. For example, if i add a button my measuredHight may return 477, but if i move the div-bar by a hair, all of a sudden it's 412. The difference is that at first it was measuring the box, and later, just the minimum needed to render those inner buttons.

                Some context to that i am trying to do. I would like to give a framework to my application so that it "flows" more like a webpage, where the width is more or less constrained, but the height can grow without bounds. This will allow a user to scroll down with their browser scrollbars. To do this i have to make sure that each component i add - resizes the parent container that it is in. The resizing should bubble up to a MyCanvas which finally causes to change Application.application.height/width to resize and using sftfit, causes the stage to resize as well. It works for the most part, but i keep running into differences between containers... like the behaviors by DividedBox i was asking some help on.

                I have a feeling that what i am doing might already be supported out of the box by flex 3 (or gumbo). I have seen sites that behave the way i described, but no code to look at.

                Any words on wisdom on that? Shall i attach some code to further illustrate? Unfortunately there is no way to host the app, or display the preformatted code on this bulletin board. How sad :)
                • 5. Re: Container resize
                  Level 7

                  "ysbelman" <webforumsuser@macromedia.com> wrote in message
                  news:gqqvgs$rt6$1@forums.macromedia.com...
                  > Amy, what you said makes sense and consistent with what i am
                  > observing...almost. When i look at what box returns for measuredHeight
                  > after i
                  > add/remove a child, it is different then when i "touch" the divider bar.
                  > For
                  > example, if i add a button my measuredHight may return 477, but if i move
                  > the
                  > div-bar by a hair, all of a sudden it's 412. The difference is that at
                  > first it
                  > was measuring the box, and later, just the minimum needed to render those
                  > inner
                  > buttons.
                  >
                  > Some context to that i am trying to do. I would like to give a framework
                  > to my
                  > application so that it "flows" more like a webpage, where the width is
                  > more or
                  > less constrained, but the height can grow without bounds. This will allow
                  > a
                  > user to scroll down with their browser scrollbars. To do this i have to
                  > make
                  > sure that each component i add - resizes the parent container that it is
                  > in.
                  > The resizing should bubble up to a MyCanvas which finally causes to change
                  > Application.application.height/width to resize and using sftfit, causes
                  > the
                  > stage to resize as well. It works for the most part, but i keep running
                  > into
                  > differences between containers... like the behaviors by DividedBox i was
                  > asking
                  > some help on.
                  >
                  > I have a feeling that what i am doing might already be supported out of
                  > the
                  > box by flex 3 (or gumbo). I have seen sites that behave the way i
                  > described,
                  > but no code to look at.
                  >
                  > Any words on wisdom on that? Shall i attach some code to further
                  > illustrate?
                  > Unfortunately there is no way to host the app, or display the preformatted
                  > code
                  > on this bulletin board. How sad :)

                  Try not specifying height on anything, but only minHeight.

                  HTH;

                  Amy