How do I truncate a Flex StyleableTextField after two lines? - apache-flex

In my Flex 4.5 mobile app, I have an actionScript item renderer (that derives from Flex's LabelItemRenderer). I want to fit in exactly 2 lines of text, and then truncate the rest. The width and height of the label are fixed and known statically.
How can I do this? The StyleableTextField.truncateToFit() method only works for one line of text.
I've set wordWrap = true, so the text now flows into the second line - but I need to truncate the text if it doesn't fit in two lines.
I need it to show all the text if there is only one line. (in both cases the label should be vertically middle-aligned in my renderer)
I know how to override layoutContents to do sizing and positioning etc of the StyleableTextField. So I'm looking specifically for ideas to implement custom text truncation with the StyleableTextField).
Any ideas?

Unless you're using something specific to the StyleableTextField try the s:Label. It has a property maxDisplayedLines which you could set to 2 and it will handle the truncation.

Related

Is there a CSS property which acts like android XML "wrap content"?

In particular I have a GWT project with a
TextArea element which I want to conform to a set width and expand as much as needed to the bottom.
ListBox element which I want to conform to a set width and expand vertically to show the entirety of the displayed list item.
Those are two widgets using replaced elements: <textarea> and <select> respectively.
for the TextArea, there's no way to make it really "resize automatically" other than listening to events and computing the new size (there's actually no need to compute the new size, you can just let the browser do it; see http://phaistonian.pblogs.gr/expanding-textareas-the-easy-and-clean-way.html)
for the ListBox, it's impossible to have the items' text wrap. See Word wrap options in a select list for a similar question in pure JS.
Set the width to whatever number and set height to auto.

Flex: Determining number of lines a spark text area can hold without overflowing

I want to implement paging in a spark text area. For that I want to find out the number of lines a spark textArea can hold before the scrollbars appear and just feed that much lines to the text area.
http://blog.flexexamples.com/2010/01/13/determining-the-number-of-lines-in-a-spark-richeditabletext-control-in-flex-4/
The number of lines a TextArea can hold before a vertical ScrollBar appear is determinated by the heightInLines property.
The code
var number_of_lines:int=textArea.heightInLines;
will return inside the variable number_of_lines the number of lines you are looking for, and textArea is the id of the TextArea object you are checking.
var numLines:int=t.heightInLines;
var numChars:int=t.widthInChars;
The documentation:
spark.components.TextArea.heightInLines():Number The default height of
the control, measured in lines. The control's formatting styles, such
as fontSize and lineHeight, are used to calculate the line height in
pixels.
You would, for example, set this property to 5 if you want the height
of the RichEditableText to be sufficient to display five lines of
text.
If this property is NaN (the default), then the component's default
height will be determined from the text to be displayed.
This property will be ignored if you specify an explicit height, a
percent height, or both top and bottom constraints.
RichEditableText's measure() method uses widthInChars and
heightInLines to determine the measuredWidth and measuredHeight. These
are similar to the cols and rows of an HTML TextArea.
Since both widthInChars and heightInLines default to NaN,
RichTextEditable "autosizes" by default: it starts out very small if
it has no text, grows in width as you type, and grows in height when
you press Enter to start a new line.

wordWrap="true" does not work in Flex Datagrid

in Flex Datagrid, I need to support line wrap function in one column.
In theory I need to set wordWrap="true" and variableRowHeight="true". It works well.
But the problem is that if in the cloumn I set itemRenderer="lc.monitoring.logviewer.components.CustomColumnRenderer" properties, then the line wrap funciton does not take effect. It seems that the line wrap function can not work with itemRenderer in the datagrid column.
Any one can help me about this.
Don't use Label - it is for displaying a single line of text.
The Label control displays a single line of noneditable text. Use the Text control to create blocks of multiline noneditable text.
mx.controls.Text supports multiline text and wordwrap
If the control is not as wide as the text, the text will wordwrap. The text is always aligned top-left in the control.
You should try to override measure and updateDisplaylist inside your itemrenderer.
Your item renderer does not know how to resize the height in order to allow showing info inside the dg

Label word wrap in Flex 4

How can the text in a Label control (or a similar control) be wrapped in Flex 4 beta? In Flex 3 I could use the Text control but this is no longer available in Flex 4.
You can use maxDisplayedLines and lineBreak properties with spark Label component:
<s:Label maxDisplayedLines="{-1}" lineBreak="toFit" text="...." />
It works with Flex 4.5.
Try <s:SimpleText />. From the excellent Migration Guide (p. 75):
The lightest-weight component of the
text primitives. The SimpleText class
supports the least number of text
features. This class is similar to the
Label class, except that it supports
multiple lines. It does not support
user ineractivity such as selection,
editing, or scrolling.
Hope that helps!
Spark Label can display multiple lines, which MX Label cannot:
In Spark Label, three character sequences are recognized as explicit
line breaks: CR ("\r"), LF ("\n"), and CR+LF ("\r\n").
If you don't specify any kind of width for a Label, then the longest
line, as determined by these explicit line breaks, determines the
width of the Label.
If you do specify some kind of width, then the specified text is
word-wrapped at the right edge of the component's bounds, because the
default value of the lineBreak style is "toFit". If the text extends
below the bottom of the component, it is clipped.
To disable this automatic wrapping, set the lineBreak style to
"explicit". Then lines are broken only where the text contains an
explicit line break, and the ends of lines extending past the right
edge is clipped.

how to wordwrap in flex tree node

I have a Tree object in my Flex code. It's width is 100%, and it is contained by a Panel with width=200. I am using a custom itemrenderer that extends TreeItemRenderer.
I need the text in each node to word wrap if it's too big (as happens often). I have tried
label.wordWrap = true;
in my item renderer without any luck. Any other suggestions?
If 'label' is an instance of the Label component, you won't be able to get it to wrap, no matter what you do, as the Label component doesn't support wrapping. Or, rather, is meant to be used only for single-line text.
If you are using a Label component, try using a Text component, instead. It's meant to display multi-line text.
With the default TreeItemRenderer you just need to set two properties on your Tree to enable wordWrap:
tree.variableRowHeight = true;
tree.wordWrap = true;
Enjoy.
What is the height that is set on the label? Is there enough room for the text to go vertically?
try setting the label width to a constant width. If your not able to do this because it needs to be dynamic then you need to override the update functions and set the width of the label then. The problem is the label hasn't calculated the actual 100% width at the time of rendering so it doesnt know it has to warp or not.
Dont Use Label. Use ' mx:Text width=" 100%" ' ( Text with 100% width) and it will wrap on its own.

Resources