Pretty good.  You may not want to use Autosize and use textWidth/Height
and add some padding instead.

 

________________________________

From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of jandersen1978
Sent: Monday, September 10, 2007 9:19 PM
To: [email protected]
Subject: [flexcoders] Re: variableRowHeight=true in List messing up
height of last row

 

Alex,
Thanks for the suggestion! I've still on the learning curve for
custom actionscript components and haven't used the TextField class a
whole lot but did manage to cobble this together which seems to have
solved my initial problem. (Now I've got some others to deal with... 
the widths are behaving strangely... can't seem to get them to
consistently take a certain percentage of the space...)

If you have a moment, I'd love your input on whether this
(particularly the measure method) is what you had in mind.
Thanks!
-James

public class MessageRendererBase extends UIComponent implements
IDataRenderer, IListItemRenderer
{
protected var _usr:TextField;
protected var _msg:TextField;

public function MessageRendererBase(){

}

protected override function createChildren():void{
_usr = new TextField();
_usr.autoSize = TextFieldAutoSize.LEFT;
_msg = new TextField();
_msg.autoSize = TextFieldAutoSize.LEFT;
_msg.wordWrap = true;

addChild(_usr);
addChild(_msg);
}

protected override function commitProperties():void{
this.percentWidth = 100;
}
protected override function measure():void{
if(!isNaN(this.explicitWidth)){
_usr.width = Math.round(this.explicitWidth * .2);
_msg.width = Math.round(this.explicitWidth * .8);
}
this.measuredWidth = _usr.width + _msg.width;
this.measuredHeight = _msg.height;
}

protected override function
updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void{
super.updateDisplayList(unscaledWidth, unscaledHeight);
_msg.x = _usr.width;

}
--- In [email protected] <mailto:flexcoders%40yahoogroups.com>
, "Alex Harui" <[EMAIL PROTECTED]> wrote:
>
> I would override measure() and see what you're getting for the
> measuredHeight of the renderer. I'm guessing that it won't be right
due
> to fact that flow-based text is "hard" to measure.
>
>
>
> A custom measure() routine would probably be better. Renderers have
> their explicitWidth set when they are measured and you'll need to use
> that to fix the widths of the text widgets to get an accurate height.
>
>
>
> If it were me, I'd use a UIComponent with two TextFields and a custom
> measure() method.
>
>
>
> -Alex
>
> blogs.adobe.com/aharui
>
>
>
> ________________________________
>
> From: [email protected] <mailto:flexcoders%40yahoogroups.com>
[mailto:[email protected] <mailto:flexcoders%40yahoogroups.com>
]
On
> Behalf Of jandersen1978
> Sent: Saturday, September 08, 2007 9:44 PM
> To: [email protected] <mailto:flexcoders%40yahoogroups.com> 
> Subject: [flexcoders] variableRowHeight=true in List messing up height
> of last row
>
>
>
> I'm adding simple chat functionality to an application I'm working on
> and have the following List displaying messages:
>
> <mx:List width="100%" height="85%" id="lstMessages"
> itemRenderer="org.MessageRenderer"
> variableRowHeight="true" dataChange="handleDataChange(event)"
> dataProvider="{messages}">
> </mx:List>
>
> here's the event handler:
> private function handleDataChange(e:FlexEvent):void{
> lstMessages.scrollToIndex(lstMessages.rowCount -1);
> }
>
> the MessageRenderer is as follows:
>
> <mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml
<http://www.adobe.com/2006/mxml> 
> <http://www.adobe.com/2006/mxml <http://www.adobe.com/2006/mxml> > "
width="100%">
> <mx:Text text="{data.fromName}" width="20%" id="lblUser"
> color="{data.color}"/>
> <mx:Text text="{data.message}" id="lblMessage" width="80%"
> color="{data.color}"/>
> </mx:HBox>
>
> What I'm finding is that with variableRowHeight=true the last row in
> the List is always rendered with virtually no height such that none of
> the message text shows up. You can only see that it's there by
> mousing over it to see that it does display a few pixels of height (a
> border or padding perhaps?). When a new message is added, the
> previously squashed row displays normally and the new row is now
> vertically challenged.
>
> With variableRowHeight=false each row displays normally (except that
> text wrapping in the messsages doesn't work which is why I have it set
> to true in the first place...). I tried adding a call to
> lstMessages.invalidate() in handleDataChange but it had no effect.
> One other item of note--with only a single message in the list it
> seems to display OK.
>
> Any ideas?
>

 

Reply via email to