iOS Question canvas draw overlapping

gjoisa

Active Member
Licensed User
Longtime User
Try to draw text on canvas different texts on same position on the button click event > But Texts overlap every time . Previous text should be deleted and new text should be drawn . But it is not happening .
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public App As Application
    Public NavControl As NavigationController
    Private Page1 As Page
    Private CanvasK As Canvas
    Private PanelK As Panel
    Private rect1 As Rect
    Private index As Int
End Sub

Private Sub Application_Start (Nav As NavigationController)
    'SetDebugAutoFlushLogs(True) 'Uncomment if program crashes before all logs are printed.
    
    NavControl = Nav
    Page1.Initialize("Page1")
    Page1.Title = "Planet Info"
    Page1.RootPanel.Color = Colors.Gray
    Page1.RootPanel.LoadLayout("Main")
    
    index = 0
    CanvasDraw
    NavControl.ShowPage(Page1)
    NavControl.ToolBarVisible = True
End Sub

Private Sub Page1_Resize(Width As Int, Height As Int)
    
End Sub

Private Sub Application_Background
    
End Sub

Sub Page1_BarButtonClick (Tag As String)
    If Tag = "refresh" Then
        CanvasDraw
    End If
End Sub

Sub CanvasDraw
    index = index + 1
    CanvasK.Initialize(PanelK)
    rect1.Initialize(10%x,10%x,80%x,80%x)
    CanvasK.DrawRect(rect1,Colors.Black,False,2)
    CanvasK.DrawText("Hello  " & index ,20%x,25%x,Font.CreateNewBold(25),Colors.Black,"LEFT")
    CanvasK.Refresh
    
End Sub
 

Star-Dust

Expert
Licensed User
Longtime User
The operation you got is correct. if you have to write again on the same position you must delete or color the space below.

If you use B4XCanvas you can measure the text and create a colored background rectangle and goes to cover up previo text
 
Upvote 0
Top