B4A Library [B4X] BCTextEngine / BBCodeView - Text engine + BBCode parser + Rich Text View

Status
Not open for further replies.

Erel

B4X founder
Staff member
Licensed User
Longtime User
I've removed ')' from WordBoundaries and made WordBoundaries a public variable:

1.57 - BCTextEngine.WordBoundaries is now a public variable. Its default value is: "&*+-/.<>=\' ,:{}" & TAB & CRLF & Chr(13)
You can modify it and change the list of characters that are treated as separators.
 

William Lancee

Well-Known Member
Licensed User
Longtime User
The Span tag doesn't work when the contents is zero or one blank.
The Vertical tag doesn't work when the contents are empty or blanks. Therefore need to insert empty lines.

B4X:
$"
-----------------------------------
[Vertical=100] [/Vertical]
-----------------------------------









[Span MinWidth=5%x]  [/Span][View=btn Vertical=15/]Lets add a [Color=#ff0000][b]button:[/b][/color] and more text here...



Lets add another [Color=#ff0000][b]button:[/b][/color] and more text here...
[Span MinWidth=10%x]  [/Span][View=btn2 Vertical=0/]
-----------------------------------
"$


 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Most tags affect their content. If the content is empty they will not do anything. Spaces are not drawn so they are not affected by these properties.

A bit hacky workaround is to add content with the same color as the background:
B4X:
[Vertical=100][color=white]X[/color][/Vertical]
[Span MinWidth=10%x][color=white]X[/color][/Span]
 

William Lancee

Well-Known Member
Licensed User
Longtime User
Thanks. I was going to ask if there was a non-printable character, but same color as background is ok.
 

William Lancee

Well-Known Member
Licensed User
Longtime User
Can I get the background color?

B4X:
Sub vSpace (Height As Int) As String
    Return $"[Vertical=${Height}][Color=${BBCVCol}]X[/Color][/Vertical]"$
End Sub

Sub hSpace (Width As Int) As String
    Return $"[Span MinWidth=${Width}][Color=${BBCVCol}]X[/Color][/Span]"$
End Sub

Sub BBCVCol As String
    'Dim col As String = $"#${Bit.ToHexString(???).substring(2)}"$            ??? background color B4A, B4J
    Dim col As String = $"#${Bit.ToHexString(xui.Color_White).substring(2)}"$
    Return col
End Sub
 

William Lancee

Well-Known Member
Licensed User
Longtime User
Right, my formula was wrong. It works now, but as you said, I did have to set the background color in the designer.

BTW, I am always amazed at the efficiency and clarity of Smart Strings.

B4X:
Sub BBCVCol As String
    Dim bc As ByteConverter
    Dim bytes() As Byte = bc.IntsToBytes(Array As Int(BBCV.mBase.Color))
    Return "#" & bc.HexFromBytes(bytes).SubString(2)
End Sub
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
1.60 - Important update. Adds support for "lazy loading". In this mode the text is only drawn when it becomes visible and is removed when it becomes invisible.
With this change it is possible to use BBCodeView to show text made of thousands of lines.
Lazy loading is enabled by default. It is set in the designer. Uncheck this option if you want to get a single bitmap with all the text.

Without lazy loading a single bitmap is created with all the text. This can work with text made of several tenths of lines.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
1.62 - Adds support for Justify alignment.

B4X:
BBCodeView1.Padding.Right = BBCodeView1.Padding.Right + 5dip
BBCodeView1.Text = $"
[Alignment=justify]Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis sit amet augue sit amet purus laoreet varius. Quisque quis odio accumsan, cursus diam ac, accumsan nibh. Phasellus placerat enim quis dolor imperdiet, eu ullamcorper sem interdum. Sed in massa lorem. Aliquam auctor auctor lacus, et fringilla nisi cursus volutpat. Etiam egestas pharetra erat, in elementum est suscipit id. Aenean sed lectus risus. [/alignment]

[Alignment=justify]Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis sit amet augue sit amet purus laoreet varius. Quisque quis odio accumsan, cursus diam ac, accumsan nibh. Phasellus placerat enim quis dolor imperdiet, eu ullamcorper sem interdum. Sed in massa lorem. Aliquam auctor auctor lacus, et fringilla nisi cursus volutpat. Etiam egestas pharetra erat, in elementum est suscipit id. Aenean sed lectus risus. [/alignment]

[Alignment=justify]Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis sit amet augue sit amet purus laoreet varius. Quisque quis odio accumsan, cursus diam ac, accumsan nibh. Phasellus placerat enim quis dolor imperdiet, eu ullamcorper sem interdum. Sed in massa lorem. Aliquam auctor auctor lacus, et fringilla nisi cursus volutpat. Etiam egestas pharetra erat, in elementum est suscipit id. Aenean sed lectus risus. [/alignment]
"$

 

js486dog

Active Member
Licensed User
Longtime User
Erel Please is it possible to do somethink like this ?

Dim txtsize As Int
Dim alig As String

txtsize = 16
alig = "justify"

$" [TextSize=txtsize]
$" [Alignment=alig]
...
$" [TextSize] = txtsize
$" [TextSize] = alig

OR

there have to be:

$" [TextSize=22]
$" [Alignment=justify]
 

js486dog

Active Member
Licensed User
Longtime User
Thank you very much Erel.
Works fine.

B4X:
Sub Globals
    Private MyView As BBCodeView
    Private TextEngine As BCTextEngine
    
    Private MyText As String
    Dim txtsize As Int
    Dim alig As String
End Sub


Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Layout1")
TextEngine.Initialize(Activity)
    
MyText = File.ReadString(File.DirAssets, "from.txt")
txtsize = 16
alig = "justify"
    
MyView.Text = $" [Alignment=${alig}][TextSize=${txtsize}] "$ & MyText & $" [/TextSize][/alignment] "$
End Sub
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…