B4A Library MaxLabel

I have modified a custom view AutoTextSizeLabel where the font size is maximized either in height or width.
Now it takes into account both borders and padingns. It is packaged in the b4xlib library.


Screenshot_2024.11.22_16.55.42.565.png


MaxLabel
Author: Jerryk
Version: 1.30

Methods:

  • Text As String
Sets or gets text of Label.
  • Base As Label
All Label methods are available through Base (e.g. Maxlabel.Base.TextColor, Maxlabel.Base.Top, etc.)

Properties:
  • PreferHeight As Boolean
Fill height is preferred. In case of long text it will be displayed on multiple lines.
  • MaxSize As Int
Set maximixed size of font. 0 - no limit
  • SingleLine As Boolean
When using the SingleLine property, use "overwritten". This is because it needs to be read for calculations, but in the original it is writeonly.
--------------

Vesion 1.1
added Tag property
Vesion 1.11
fixed error when Background is not ColorDrawable or not set
Vesion 1.20
added PreferHight property
Vesion 1.30
added MaxSize property
Vesion 1.31
fixed error when read new addded property
 

Attachments

  • MaxLabel.zip
    10.4 KB · Views: 53
  • MaxLabel.b4xlib
    1.6 KB · Views: 29
Last edited:

Jerryk

Member
Licensed User
Longtime User
Version 1.1
added Tag property

Example of using the Tag property. For example, you can translate text into another language and adjust the size to the new content directly using the Designer script.
script:
tools.Translate(MaxLabel1, "title")
tools.Translate(MaxLabel2, "desc")
tools:
Private Sub Translate(DesignerArgs As DesignerArgs)
    Sleep(10)  'Do not delete!
    If DesignerArgs.FirstRun Then
        Dim text As String = DesignerArgs.Arguments.Get(1)
        Dim v As B4XView = DesignerArgs.GetViewFromArgs(0)
        If v.Tag Is MaxLabel Then
            Dim ml As MaxLabel
            ml = v.Tag
            ml.Text = Loc(text) 'localization function
        Else
            v.Text = Loc(text) 'localization function
        End If
    End If
End Sub
 
Last edited:

Mehrzad238

Member
I am having this error trying to use this library

B4X:
B4A Version: 13.00
Parsing code.    (0.04s)
    Java Version: 19
Building folders structure.    (0.01s)
Running custom action.    Error
-------------------------------------------------------------------------------
   ROBOCOPY     ::     Robust File Copy for Windows                             
-------------------------------------------------------------------------------
  Started : Monday, November 25, 2024 11:03:19 PM
   Source : F:\MaxLabel\Shared Files\
     Dest : F:\MaxLabel\B4A\Files\
    Files : *.*
        
  Options : *.* /DCOPY:DA /COPY:DAT /R:1000000 /W:30
------------------------------------------------------------------------------
2024/11/25 23:03:19 ERROR 2 (0x00000002) Accessing Source Directory F:\MaxLabel\Shared Files\
The system cannot find the file specified.

can anyone help me?
 

Mehrzad238

Member
I deleted the line but now I am facing with this

B4X:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create (first time) **
Error occurred on line: 36 (MaxLabel)
java.lang.RuntimeException: Cannot parse: null as boolean
    at anywheresoftware.b4a.BA.parseBoolean(BA.java:640)
    at anywheresoftware.b4a.BA.ObjectToBoolean(BA.java:710)
    at b4a.example.maxlabel._designercreateview(maxlabel.java:252)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
    at anywheresoftware.b4a.objects.CustomViewWrapper.AfterDesignerScript(CustomViewWrapper.java:61)
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:147)
    at anywheresoftware.b4a.objects.PanelWrapper.LoadLayout(PanelWrapper.java:134)
    at anywheresoftware.b4a.objects.B4XViewWrapper.LoadLayout(B4XViewWrapper.java:329)
    at b4a.example.b4xmainpage._b4xpage_created(b4xmainpage.java:56)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.debug.Debug.CallSub4(Debug.java:318)
    at anywheresoftware.b4a.debug.Debug.CallSubNew2(Debug.java:285)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.keywords.Common.CallSubDebug2(Common.java:1087)
    at b4a.example.b4xpagesmanager._createpageifneeded(b4xpagesmanager.java:1068)
    at b4a.example.b4xpagesmanager._showpage(b4xpagesmanager.java:425)
    at b4a.example.b4xpagesmanager._addpage(b4xpagesmanager.java:245)
    at b4a.example.b4xpagesmanager._addpageandcreate(b4xpagesmanager.java:259)
    at b4a.example.b4xpagesmanager._initialize(b4xpagesmanager.java:165)
    at b4a.example.main._activity_create(main.java:415)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
    at b4a.example.main.afterFirstLayout(main.java:105)
    at b4a.example.main.access$000(main.java:17)
    at b4a.example.main$WaitForLayout.run(main.java:83)
    at android.os.Handler.handleCallback(Handler.java:938)
 
Top