Android Question MeasureMultilineTextHeight and CSBuilder

alon

Active Member
Licensed User
Longtime User
Hi,

I am using CSBuilder on a Label,
for a reason that I do not understand, the Height I am getting from MeasureMultilineTextHeight ,
is not as it should be, it is too short for all the text.


Thanks in advance.



B4X:
Sub DrawListView
   
    Dim Table As List
    Dim i As Int
    Dim su As StringUtils
    '
   
    clvDoh.Clear
   
    Dim sQuery As String
    sQuery="select * " & _           
           " from kriot WHERE LeTarik = " & _
            DBUtils.Fmsg(sCurDate) 
           
    If Starter.bShowAll = False Then
        sQuery=sQuery &  " AND status = 0 "
    End If
   
    '       
    sQuery=sQuery & " ORDER BY status,RecId"
         
   
    Table = DBUtils.ExecuteMemoryTable(Starter.sql,sQuery  ,Null  , 0)
   
    If Table.Size =0 Then Return  ' if no records
   
    For i = 0 To Table.Size - 1 'Creating The Itmes Parents and childs
        Cols = Table.Get(i)
        clvDoh.Add(CreateListItem( clvDoh.AsView.Width, clvDoh.AsView.Height) , $"Item #${i}"$) '24-10-2019
    Next
   
End Sub   
Sub CreateListItem( Width As Int, Height As Int) As Panel
    Dim p As Panel
    Dim su As StringUtils
    Dim stmp As String 
    Dim item As ItemProp
    p.Initialize("")
    p.SetLayout(0 ,  0,  Width, Height) '24-10-2019
    p.LoadLayout("listitem") 
    p.Color = Colors.White 
   
    lblDetails.TextColor = Colors.Black
    lblTel.TextColor = Colors.Black
   
    Try   
        item.Initialize
        item.Recid = Cols(0)
        item.MisparTofes = Cols(1)
        item.Shlav = Cols(13)
       
       
        lblDetails.Tag = item    '
        If ModFunc.Val (Cols(13)) > 0 Then
            stmp =  Cols(6).Trim & " [ ק " & Cols(1) & "/" & Cols(13) & " ]"  & CRLF    &  Cols(5).Trim                 'sha + shemlako
        Else
            stmp =  Cols(6).Trim & " [ ק " & Cols(1) & " ]"  & CRLF    &  Cols(5).Trim                 'sha + shemlako
        End If
       
       
        If ModFunc.Len(Cols(7)) > 0 Then 'ktovetlako
            stmp = stmp &  CRLF & Cols(7)       
        End If
       
        If ModFunc.Len(Cols(10)) > 0 Then 'teorparit
            stmp = stmp & CRLF & "תאור: " & Cols(10)
        End If
       
        If ModFunc.Len(Cols(11)) > 0 Then 'degem
            stmp = stmp & CRLF & "דגם: " & Cols(11)
        End If
        '===================================
        '26-11-2017
        If Starter.bShowTarikHatkana Then
            If ModFunc.Len(Cols(25)) > 0 And Cols(25) <> "01.01.1900" Then 'TarikHatkana
                stmp = stmp & CRLF & "תאריך התקנה: " & Cols(25)
            End If
        End If
        '===================================
        If ModFunc.Len(Cols(12)) > 0 Then 'takala
            stmp = stmp & CRLF & Starter.sTakalaName &  Cols(12)  '26-09-2019
        End If
       
        stmp = stmp & CRLF 
        '==================================
        '21-01-2018
        If ModFunc.Len(Cols(12)) > 0 Then 'takala
            cs =  ModFunc.MarkPattern2(stmp, "\d\d\d\d\d\d\d\d\d+", 0,Starter.sTakalaName &  Cols(12)) '19-11-2019
        Else
            cs =  ModFunc.MarkPattern(stmp, "\d\d\d\d\d\d\d\d\d+", 0)
        End If       
       
        lblDetails.Text = cs
        cs.EnableClickEvents(lblDetails)
        '==================================
        lblTel.Text = Cols(8)
        If Cols(34).Length > 0 Then '26-09-2019 Akrai
            lblTel.Text = Cols(8) & CRLF & Cols(34)
            lblTel.Height = su.MeasureMultilineTextHeight (lblTel,lblTel.Text) + 1%y '18-11-2019
        End If
        '==================================
        '02-01-2018
        lblHatra.Visible = False
        If ModFunc.Val(Cols(18)) > 0 Then
            lblHatra.Top = lblTel.Top + lblTel.Height + 0.5%y '19-11-2019
            lblHatra.Text = "התראה " & Cols(18) & " דק'"
            lblHatra.Visible = True
        End If
        '==================================
        If stmp.Length > 0 Then
            lblDetails.Height= su.MeasureMultilineTextHeight(lblDetails, cs )+ 2%y
            iItemHeight = lblDetails.Height
        End If
        '==================================
        '07-01-2018
        lblOved.Visible = False
        If Starter.bMenahelAvoda Then
            If ModFunc.Len(Cols(26)) > 2 Then
                '18-11-2019 = Adding Cols(15)
                lblOved.Text = "טכנאי: " & Cols(15) & " | " & Cols(26).SubString2(0,Cols(26).Length -2)
                lblOved.Visible = True
                lblOved.Top = lblDetails.Top + lblDetails.Height   + 2%y
                iItemHeight = iItemHeight + lblOved.Height
            Else
                If ModFunc.Len(Cols(15)) > 2 Then
                    lblOved.Text = "טכנאי: " &  Cols(15)
                    lblOved.Visible = True
                    lblOved.Top = lblDetails.Top + lblDetails.Height  + 2%y
                    iItemHeight = iItemHeight + lblOved.Height + 2%y
                End If
            End If
        End If
        '==================================
   
       
    Catch
        Log(LastException)
    End Try
    p.Height = iItemHeight  '24-10-2019
    Return p
End Sub
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
B4X:
  Dim sQuery As String
    sQuery="select * " & _           
           " from kriot WHERE LeTarik = " & _
            DBUtils.Fmsg(sCurDate)
A bit better:
B4X:
  Dim sQuery As String = $"select *
         from kriot WHERE LeTarik = ${DBUtils.Fmsg(sCurDate)}"$

I've made a simple test and it does measure the CSBuilder string correctly:

i_view64_ZZI9e7Quup.png


B4X:
Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("1")
   Dim su As StringUtils
   Dim cs As CSBuilder
   Dim s As String = $"sj dlkfj sdlkfj sldkf sdf
jwlkefj wlkefjwelkf wlkef wef"$
   cs.Initialize.Size(40).Append(s).PopAll
   Label1.Text = cs
   Label1.Height = su.MeasureMultilineTextHeight(Label1, cs)
   cs.Initialize.Size(10).Append(s).PopAll
   Label2.Text = cs
   Label2.Height = su.MeasureMultilineTextHeight(Label2, cs)
End Sub
 
Upvote 0

alon

Active Member
Licensed User
Longtime User
B4X:
  Dim sQuery As String
    sQuery="select * " & _          
           " from kriot WHERE LeTarik = " & _
            DBUtils.Fmsg(sCurDate)
A bit better:
B4X:
  Dim sQuery As String = $"select *
         from kriot WHERE LeTarik = ${DBUtils.Fmsg(sCurDate)}"$

I've made a simple test and it does measure the CSBuilder string correctly:

i_view64_ZZI9e7Quup.png


B4X:
Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("1")
   Dim su As StringUtils
   Dim cs As CSBuilder
   Dim s As String = $"sj dlkfj sdlkfj sldkf sdf
jwlkefj wlkefjwelkf wlkef wef"$
   cs.Initialize.Size(40).Append(s).PopAll
   Label1.Text = cs
   Label1.Height = su.MeasureMultilineTextHeight(Label1, cs)
   cs.Initialize.Size(10).Append(s).PopAll
   Label2.Text = cs
   Label2.Height = su.MeasureMultilineTextHeight(Label2, cs)
End Sub


Well in some cases it works fine but in some other cases it does not.
by the way in some devices everything looks fine.

as you can see in the pics , there are 2 items that looks fine , and the next one looks bad.
 

Attachments

  • good.jpeg
    good.jpeg
    111.9 KB · Views: 185
  • bad.jpeg
    bad.jpeg
    246.2 KB · Views: 216
Upvote 0

alon

Active Member
Licensed User
Longtime User
This is handled internally so there isn't much that you can do about it except of increasing the extra height.
If it was non-LTR text then I would've suggested to use BCTextEngine. However it will not work properly with LTR text.

I have already increase it by 2%y

what else can I do?
 
Upvote 0
Top