B4J Library [class] TextFlow - Similar to B4A / B4i RichString

This class uses JavaObject to create a TextFlow node. With a TextFlow you can display rich text with different colors, fonts and other attributes.

SS-2015-12-10_13.15.36.png


Usage:
- Add the TextFlow class module to your project (Tools - Add Existing Module).
- Create a TextFlow object.
- Call AddText to add a text section and set its attributes.
- Eventually you should call CreateTextFlow to create the node that will be added to the layout.

Note that the set attributes return the class instance which allows chaining the calls.
B4X:
Dim tf As TextFlow
tf.Initialize
tf.AddText("1 2 3").SetColor(fx.Colors.Red).SetUnderline(True)
tf.AddText(" 4 5 6 ").SetColor(fx.Colors.Green).SetFont(fx.CreateFont("", 17, True, True))
tf.AddText("7 8 9").SetColor(fx.Colors.Blue).SetStrikethrough(True).SetFont(fx.DefaultFont(20))
Dim pane As Pane = tf.CreateTextFlow
MainForm.RootPane.AddNode(pane, 10, 10, 200, 100)
 

Attachments

  • TextFlow.zip
    1.3 KB · Views: 1,364

Mashiane

Expert
Licensed User
Longtime User
Adding FontAwesomeText

In class globals... add

B4X:
Private awesome As Font

In the initialize method add

B4X:
awesome = fx.LoadFont(File.DirAssets, "FontAwesome.otf", 12)

B4X:
public Sub AddFontAwesome(text As String)
    Dim lbl As Label
    lbl.Initialize("")
    lbl.Font = awesome
    lbl.Text = ""
    texts.Add(lbl)
    Return Me
End Sub
 

Mashiane

Expert
Licensed User
Longtime User
Adding Images

B4X:
public Sub AddImage1(img As Image, imgw As Double, imgh As Double) As TextFlow
    Dim uri As ImageView
    uri.Initialize("")
    uri.SetImage(img)
    uri.SetLayoutAnimated(0,0,0,imgw,imgh)
    texts.Add(uri)
    Return Me
End Sub

Public Sub AddImage(dir As String, img As String) As TextFlow
    Dim simg As Image = fx.LoadImage(dir,img)
    Dim uri As ImageView
    uri.Initialize("")
    uri.SetImage(simg)
    uri.SetLayoutAnimated(0,0,0,16,16)
    texts.Add(uri)
    Return Me
End Sub
 

Tayfur

Well-Known Member
Licensed User
Longtime User
How can i change text aligment.
CSSutils dont work.

B4X:
Dim tf As TextFlow
    tf.Initialize
    tf.AddText("1 2 3").SetColor(fx.Colors.Red).SetUnderline(True)
    tf.AddText(" 4 5 6 ").SetColor(fx.Colors.Green).SetFont(fx.CreateFont("", 17, True, True))
    tf.AddText(CRLF)
    tf.AddText("7 8 9").SetColor(fx.Colors.Blue).SetStrikethrough(True).SetFont(fx.DefaultFont(20))
    
    Dim pane As Pane = tf.CreateTextFlow
    'Dim Lb As Label= tf.CreateTextFlow2
    CSSUtils.SetBorder(pane,1,fx.Colors.Red,0)
    CSSUtils.SetStyleProperty(pane, "-fx-alignment", "BOTTOM_RIGHT")
    CSSUtils.SetBorder(pane,0.2,fx.Colors.Black,0)
    
    MainForm.RootPane.AddNode(pane, 10, 10, 200, 100)
 

marcopoilo

Member
Licensed User
Is it possible to use it for Labels or TextField, TextArea,...
Thanks
 
Last edited by a moderator:
Top