B4J Question [B4J] [CSSUtils] Changing FontSize of a Node...

Magma

Expert
Licensed User
Longtime User
Well i am trying...
to set specific font size to a node - seems that style get the property / but result not seen at screen...

Is actually for the snippet here:

replace SizeControls with this:
B4X:
Sub SizeControls(t As Form, width1 As Double, height1 As Double, width2 As Double, height2 As Double)
    Dim praxi1 As String, praxi2 As String
    Dim mp1 As Double, mp2 As Double
    Dim sstyle As String, ss As Int
    If width2 > width1 Then praxi1="*" Else praxi1=":"
    If height2 > height1 Then praxi2="*" Else praxi2=":"
    If praxi1="*" Then
        mp1=width2/width1
        Else
        mp1=width1/width2
    End If
    If praxi2="*" Then
        mp2=height2/height1
    Else
        mp2=height1/height2
    End If

        For a = 0 To t.RootPane.NumberOfNodes -1
            Dim N As Node = t.RootPane.GetNode(a)
            If praxi1="*" Then n.Left=n.left * mp1 Else n.Left=n.left / mp1
            If praxi2="*" Then n.Top=n.Top*mp2 Else n.Top=n.Top/mp2
            If praxi1="*" Then n.PrefWidth=n.PrefWidth*mp1 Else n.PrefWidth=n.PrefWidth/mp1
            If praxi2="*" Then n.PrefHeight=n.PrefHeight*mp2 Else n.PrefHeight=n.PrefHeight/mp2

         
            sstyle=CSSUtils.GetStyleProperty(N,"-fx-font-size")
            Log(sstyle)
            If sstyle.Trim="" Or sstyle.Trim=Null Then sstyle="0"
            ss=sstyle.Trim
            If ss=0 Then
                sstyle="15.00"
                ss=15
            End If
         
                    If praxi2="*" Then
                    ss=ss * mp2
                    sstyle=NumberFormat2(ss,1,2,2,False)
                  CSSUtils.setStyleProperty(N, "-fx-font-size",sstyle)  'seems that setstyle setting the style - because after recalling sizecontrols getting the new style... but not see the result !
                    Else
                    ss=ss / mp2
                    sstyle=NumberFormat2(ss,1,2,2,False)
                    CSSUtils.setStyleProperty(N,"-fx-font-size",sstyle)
                    End If
                 
            'For Each subN As Node In N. -------------> how to get sub nodes and recall the sizecontrols to size them all ?
            '-------
            '-----
            'Next
        Next
End Sub

CSSUtils.setStyleProperty(N,"-fx-font-size",sstyle) ??
 

stevel05

Expert
Licensed User
Longtime User
This is something that is so much simpler using B4xView:

B4X:
    For Each V As B4XView In N.GetAllViewsRecursive  'Assuming N is a B4xView or a Pane
        V.TextSize = 10
    Next

You don't need to worry about CSSUtils, or whether the node supports the TextSize property .
 
Last edited:
Upvote 1

Magma

Expert
Licensed User
Longtime User
This is something that is so much simpler using B4xView:

B4X:
    For Each V As B4XView In N.GetAllViewsRecursive
        V.TextSize = 10
    Next

You don't need to worry about CSSUtils, or whether the node supports the TextSize property .
Thanks but if not... a b4xview ?... and want it like a node ?
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
You can cast each view to a B4xView:

B4X:
N.As(B4xView).textSize = 10
 
Upvote 1

Magma

Expert
Licensed User
Longtime User
The first you said works... but the second (if cast) is not... changing successfully textsize property... but not seen that change in screen...

B4X:
Sub SizeControls(t As Form, width1 As Double, height1 As Double, width2 As Double, height2 As Double)
    Dim praxi1 As String, praxi2 As String
    Dim mp1 As Double, mp2 As Double
    Dim ss As Int
    If width2 > width1 Then praxi1="*" Else praxi1=":"
    If height2 > height1 Then praxi2="*" Else praxi2=":"
    If praxi1="*" Then
        mp1=width2/width1
        Else
        mp1=width1/width2
    End If
    If praxi2="*" Then
        mp2=height2/height1
    Else
        mp2=height1/height2
    End If

        For a = 0 To t.RootPane.NumberOfNodes -1
            Dim N As Node = t.RootPane.GetNode(a)
            
            If praxi1="*" Then n.Left=n.left * mp1 Else n.Left=n.left / mp1
            If praxi2="*" Then n.Top=n.Top*mp2 Else n.Top=n.Top/mp2
            If praxi1="*" Then n.PrefWidth=n.PrefWidth*mp1 Else n.PrefWidth=n.PrefWidth/mp1
            If praxi2="*" Then n.PrefHeight=n.PrefHeight*mp2 Else n.PrefHeight=n.PrefHeight/mp2

                        
            If n Is B4XView Then 
                ss=N.As(B4XView).TextSize
                'Log("???" & ss)
            End If

            If ss<7 Then ss=7
            If ss>120 Then ss=120

                    If praxi2="*" Then
                        ss=ss * mp2
                        If n Is B4XView Then N.As(B4XView).TextSize=ss
                    Else
                        ss=ss / mp2
                        If n Is B4XView Then N.As(B4XView).TextSize=ss
                    End If
                    
        Next
End Sub
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
If you are calling the resize sub directly after loading the layout, you may need to insert a Sleep(0) before the call to allow the layout to load.

If that doesn't work, can you upload an example project?
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
This is a lot more complicated than it looks as the views in the layout are Custom views. Each can have a different internal structure and respond differently to being resized. So it's not as simple as iterating all of the views and changing the sizes by a relative amount. Some have nodes, within nodes that may not need to be resized. Unless you go through each possible view and work out how it should respond and program that explicitly, it will only ever be an approximation and not look as you would like.

The attached sort of works, but there is a lot more work to do on it. and it won't be simple.
 

Attachments

  • XUI Views Example2.zip
    10.2 KB · Views: 206
Upvote 0
Top