iOS Question Canvas

jamesnz

Active Member
Licensed User
Longtime User
I have a canvas (c) which is declared in main and initialised in my start routine for a separate module
B4X:
Public Sub StartShow
    If pg.IsInitialized = False Then
        pg.Initialize("pg")
        pg.RootPanel.LoadLayout("Show")
    End If
    Main.NavControl.ShowPage(pg)
    interimList.Initialize
    parseSegmentsIntoObjects
    gmap.Initialize("gmap", ApiKey)
    addmap
    Main.c.Initialize(ChartPanelx)  '<==
    initialsetupchart
End Sub



What is the recommended method of clearing the canvas c.release and c.initialize do not clear it, if I return to the screen it has drawn one canvas over the top of the previous unless I restart the entire application

I have tried declaring the canvas in main , habe tried removing the canvas panel from the root panel, but even when re added it contains the old canvas data
 

JanPRO

Well-Known Member
Licensed User
Longtime User
Hi,

before initializing the canvas new, set it to Null. This will deallocate the object (ARC):

B4X:
Sub ClearCanvas(C As Canvas)
    Dim V As View = C.View 'be sure Canvas.Release wasn't called before
    V.RemoveViewFromParent
    C = Null
    Dim C As Canvas
    C.Initialize(V)
    C.Refresh
End Sub

Jan
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
You may try this:
Move this two lines
Main.c.Initialize(ChartPanelx) '<==
initialsetupchart

insides the If / Then so you initialize the canvas only once.
B4X:
Public Sub StartShow
    If pg.IsInitialized = False Then
        pg.Initialize("pg")
        pg.RootPanel.LoadLayout("Show")
        Main.c.Initialize(ChartPanelx)  '<==
        initialsetupchart
    End If
    Main.NavControl.ShowPage(pg)
    interimList.Initialize
    parseSegmentsIntoObjects
    gmap.Initialize("gmap", ApiKey)
    addmap
End Sub
 
Upvote 0

jamesnz

Active Member
Licensed User
Longtime User
OK I have moved these lines into the ISInitialized test and added Jans clear canvas method (thanks Jan) but the canvas plots still persists.
In my process_globals I have
Dim C As Canvas
Private ChartPanelx As Panel (made with designer)
have nothing in my page appear disappear or resize ( tried running canvasclear in pg_disappear, no difference)

B4X:
Sub ClearCanvas(Cv As Canvas)
   
    Dim V As View = Cv.View 'be sure Canvas.Release wasn't called before
    V.RemoveViewFromParent
    Cv = Null
    Dim Cv As Canvas
    Cv.Initialize(V)
    Cv.Refresh
    'pg.RootPanel.AddView(C,0,0,50%x,50%y)
End Sub

Public Sub StartShow
   
    If pg.IsInitialized = False Then
        pg.Initialize("pg")
        pg.RootPanel.LoadLayout("Show")
    C.Initialize(ChartPanelx)   
    End If
   
    Main.NavControl.ShowPage(pg)
    interimList.Initialize
    parseSegmentsIntoObjects
    gmap.Initialize("gmap", ApiKey)
    addmap
    initialsetupchart
End Sub


The clue perhaps is that if I just initialising the canvas onto ChartPanelx , it won't show it at all, Instead I have to add Chartpanel x through the sub initialsetupchart (4th line) ***


B4X:
Sub initialsetupchart
   
    Log("setting up chart")
    ClearCanvas(C)
   *** pg.RootPanel.AddView(ChartPanelx,0,pg.RootPanel.height/2,pg.RootPanel.Width,pg.RootPanel.Height/2)
   'if I leave the above line out I get no chart at all, yet it's added in the designer
    left=0
   
    Log ( "size of interim list = " & interimList.Size)
    For Each section As segment In interimList
        plotrectangle(interimList.Size, section.averageSpeed)
    Next
   
    C.refresh
    Log("finished drawing chart")
End Sub
 
Upvote 0

jamesnz

Active Member
Licensed User
Longtime User
apologies for delay, press the go button on screen1, the canvas will appear, note the size of the initial plots too.
Go back to screen 1 , press button again and note the canvas keeps the old plot values and draws new ones over the top of the old.
 

Attachments

  • tempcanvasclear.zip
    4.3 KB · Views: 281
Upvote 0

jamesnz

Active Member
Licensed User
Longtime User
I think somewhere in the background it's actually taking a screenshot of the canvas . The reason I say this is if I put a red button on top of the canvaspanelx , when I redraw the canvas a copy of the button remains in the same position.
 
Upvote 0

jamesnz

Active Member
Licensed User
Longtime User
If I comment that line out I get nothing, just a blank panel.
This has me confused also because in the smaller demo project I uploaded a post ago I don't need to add it programatically.
I have tried rebuilding the layout, renaming the panels, re ordering the panels in the designer,
Ive also tried initialising them in the Main Module as well as the Showx module
 
Upvote 0
Top