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

Discussion in 'B4J Libraries & Classes' started by Erel, Dec 10, 2015.

  1. Erel

    Erel Administrator Staff Member Licensed User

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

    [​IMG]

    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.
    Code:
    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(""17TrueTrue))
    tf.AddText(
    "7 8 9").SetColor(fx.Colors.Blue).SetStrikethrough(True).SetFont(fx.DefaultFont(20))
    Dim pane As Pane = tf.CreateTextFlow
    MainForm.RootPane.AddNode(
    pane1010200100)
     

    Attached Files:

    jmon, Mashiane, Cableguy and 6 others like this.
  2. Mashiane

    Mashiane Expert Licensed User

    Adding FontAwesomeText

    In class globals... add

    Code:
    Private awesome As Font
    In the initialize method add

    Code:
    awesome = fx.LoadFont(File.DirAssets, "FontAwesome.otf"12)
    Code:
    public Sub AddFontAwesome(text As String)
        
    Dim lbl As Label
        lbl.Initialize(
    "")
        lbl.Font = awesome
        lbl.Text = 
    ""
        texts.Add(lbl)
        
    Return Me
    End Sub
     
    joulongleu and jmon like this.
  3. Mashiane

    Mashiane Expert Licensed User

    Add any other font

    Code:
    public Sub AddOtherFont(text As String)
        
    Dim lbl As Label
        lbl.Initialize(
    "")
        lbl.Font = fx.LoadFont(
    File.DirAssets, "RemachineScript.ttf"12)
        lbl.Text = text
        texts.Add(lbl)
        
    Return Me
    End Sub
     
    joulongleu likes this.
  4. Mashiane

    Mashiane Expert Licensed User

    Adding Images

    Code:
    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 StringAs 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
     
  5. Tayfur

    Tayfur Well-Known Member Licensed User

    How can i change text aligment.
    CSSutils dont work.

    Code:
    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(""17TrueTrue))
        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(
    pane1010200100)
     
  6. marcopoilo

    marcopoilo New Member

    Is it possible to use it for Labels or TextField, TextArea,...
    Thanks
     
    Last edited by a moderator: May 15, 2018
  7. Erel

    Erel Administrator Staff Member Licensed User

    You should use the returned Node instead of a label. You cannot use it with TextField or TextArea.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice