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
1. Update to v1.51.

2. B4J code:
B4X:
Sub Process_Globals
   Private fx As JFX
   Private MainForm As Form
   Private TextEngine As BCTextEngine
   Private xui As XUI
End Sub

Sub AppStart (Form1 As Form, Args() As String)
   MainForm = Form1
   MainForm.RootPane.LoadLayout("1") 'Load the layout file.
   TextEngine.Initialize(MainForm.RootPane)
   MainForm.Show
   For Each v As B4XView In MainForm.RootPane.GetAllViewsRecursive
       If v.Tag Is BBLabel Then ResizeToFit(v.Tag)
   Next
End Sub

Sub ResizeToFit(Label As BBLabel)
   If Label.Paragraph.IsInitialized = False Then Return
   Dim iv As B4XView = Label.mBase.GetView(0)
   Do While Label.Paragraph.TextLines.Size > 1 Or iv.Width > Label.mBase.Width - 4dip
       Dim f As B4XFont = Label.ParseData.DefaultFont
       Dim b As B4XFont = Label.ParseData.DefaultBoldFont
       If f.Size <= 8 Then Return
       Label.ParseData.DefaultFont = xui.CreateFont2(f, f.Size - 2)
       Label.ParseData.DefaultBoldFont = xui.CreateFont2(b, b.Size - 2)
       Label.ParseAndDraw
   Loop
End Sub

 

Toky Olivier

Active Member
Licensed User
Longtime User
I just compile and run the b4a example in the emulator and this is what I get. A little problem with the Image in the BBLabel.

Device layout: 480 x 854, scale = 1.0 (160 dpi)

 

William Lancee

Well-Known Member
Licensed User
Longtime User
I would like to implement an horizontal swipe, but this code does not work. Is there another way?

B4X:
BBCodeView1_OnTouchEvent (Action As Int, X As Float, Y As Float, MotionEvent As Object)
 

William Lancee

Well-Known Member
Licensed User
Longtime User
You can put a transparent panel over BBCodeView. It will work if the BBCodeView doesn't need to be vertically scrollable.

Thank you. That worked exactly as I wanted.

B4X:
    Dim clearPanel As Panel: clearPanel.Initialize("clearPanel")
    Dim cd As ColorDrawable
    cd.Initialize (Colors.Transparent, 0)
    clearPanel.Background = cd
    Activity.AddView(clearPanel, 0, 0, 100%x, 100%y)

B4X:
Sub clearPanel_Touch (Action As Int, X As Float, Y As Float)
    Log(Action)
End Sub
 

William Lancee

Well-Known Member
Licensed User
Longtime User
I spoke too soon. The panel also blocks clicks on URLs, buttons, and other Views. I bypassed the problem by adding a narrow touch panel at the top of the screen.
 

William Lancee

Well-Known Member
Licensed User
Longtime User
What are you using it for? Can you post a screenshot?

I am planning a book-like presentation of interactive pages. The horizontal swipe gesture is a good one for going from one page to the next and back. Pages are complex and include mostly text but also listviews, buttons, and URLs. The BBCodeView is a good approach for showing rich text, and also because the pages are dynamically generated. At this point I don't have much to show yet. What works for now is allocating a narrow area at the top (above URLs and views) that is sensitive to the swipe.
 

William Lancee

Well-Known Member
Licensed User
Longtime User


I am trying it out with B4J. The spacing between "r" and the following "e" seems a bit too much.

The spacing with some other letters is also a bit off: "r" "y" "k" too much space on right.
"i" too little space left and right.
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
I am trying it out with B4J. The spacing between "r" and the following "e" seems a bit too much.

The spacing with some other letters is also a bit off: "r" "y" "k" too much space on right.
"i" too little space left and right.
Kerning is currently not supported. This makes the spacing for non-monospaced fonts not as perfect as in native text controls.

Also, the word wrap breaks at "(" when the next char is NOT a blank.
Fixed in v1.56.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…