3 Replies Latest reply on Aug 7, 2011 3:46 AM by Francisc

    IconItemRenderer with alternating icon existence

    Francisc Level 3

      Hello,

       

      I have an IconItemRenderer in which some rows have icons (and decorators) and some do not.

      The ones that do not, align the labelDisplay as if they would and I wanted it to be left aligned.

      Is there something I'm missing, shouldn't a null icon move the label to the left?

       

      I can easily override the layoutContents() method when icon is null, but I'm just curious.

       

      Thank you.

        • 1. Re: IconItemRenderer with alternating icon existence
          Shongrunden Adobe Employee

          Do you set an iconWidth/iconHeight on the renderer?

          • 2. Re: IconItemRenderer with alternating icon existence
            Francisc Level 3

            Ah, that's it.

            Thank you.

            • 3. Re: IconItemRenderer with alternating icon existence
              Francisc Level 3

              Here's what I did.

               

              //For holding default values

              private var defaultIconWidth:Number;
              private var defaultIconHeight:Number;

               

              //Set when overriding the set data method based on data

              private function isHeader:Boolean=false;

               

              override protected function measure():void
              {
                  //Set default values for icon dimensions the first time
                  if(!defaultIconWidth){defaultIconWidth=iconWidth || getElementPreferredWidth(iconDisplay);}
                  if(!defaultIconHeight){defaultIconHeight=iconHeight || getElementPreferredHeight(iconDisplay);}
                 
                  if(!isHeader)
                  {
                      //Reset icon dimensions to what they were set (if they were)
                      iconWidth=defaultIconWidth;
                      iconHeight=defaultIconHeight;
                     
                      super.measure();
                  }
                  else
                  {
                      //No icon for header, set iconWidth and iconHeight to 0 so that layoutContents doesn't take the passed value from MatchDetails.mxml which is 40 into computations
                      iconWidth=0;
                      iconHeight=0;
                     
                      . . .
                  }
              }