Can I set text on a flexible graphic object?

In any case, I can effectively call equiv. setText on a Flex Graphics object?

In particular, I use my own cell renderer to display data in a datagrid. The renderer uses the Graphics object to set the background color of only part of the cell (say, the left half) based on the underlying data. I would like to have text only for that part of the cell that has a background color (for example, with the center in the left half).

I know all the widths (of both the cell itself and the graphic object), but I do not know how I can set the text (in the center) above the graphic object.

Anyone have any ideas? Tks vm

+3
source share
4

, :

    private function WriteText(text:String, rect:Rectangle):void
    {
        var uit:UITextField = new UITextField();
        uit.text = text;
        uit.width = rect.width;
        var textBitmapData:BitmapData = ImageSnapshot.captureBitmapData(uit);
        var matrix:Matrix = new Matrix();
        var x:int = rect.x;
        var y:int = rect.y;
        matrix.tx = x;
        matrix.ty = y;
        graphics.beginBitmapFill(textBitmapData,matrix,false);
        graphics.drawRect(x,y,uit.measuredWidth,uit.measuredHeight);
        graphics.endFill();
    }

, UITextField , .

Adobe Developer Connection.

+4

, Graphics. , (, , ..) .

, updateDisplayList, - :

override protected function updateDisplayList( unscaledWidth:Number, unscaledHeight:Number ):void
{
    super.updateDisplayList( unscaledWidth, unscaledHeight );

    // perform all your custom painting

    var label:Label = new Label();
    label.text = "Some text";

    label.width = widthOfCustomPainting;
    // can also set x- and y-coordinates of label too

    label.setStyle( "textAlign", "center" );

    this.addChild( label );
}

, , , , .

, . , , .

+1

, , . . , .

AS MXML .

0
source

using textformat for uit defaulttextformat is the solution to my problem ...

0
source

Source: https://habr.com/ru/post/1721766/


All Articles