iOS Question problem Canvas on panel

Discussion in 'iOS Questions' started by electro179, Jul 19, 2019.

  1. electro179

    electro179 Active Member Licensed User

    Hello

    I have a list of panel
    on each panel I put a canvas

    This function creates a new panel with 5 labels and I init a canvas on this panel

    The problem is I have the impression that he writes everything in duplicate.
    I click on a panel and I want to change the color of panel to show that it is selected it does not work and if I change the value of a label I have a double display, the old value and the new one as if he wrote twice the same label in the panel

    if i remove canvas.refresh not problem except that the canvas is not drawn

    can3 is a global variable

    Code:
    Sub AddLineList(text1 As String,text2 As String,text3 As String,text4 As String,text5 As String,deviceid As Int,output As Int)
        
    Dim panel As Panel

        
    Dim left As Int
        
    Dim width As Int
        
    Dim nbr As Int
        
    Dim top As Int
        
    Dim height As Int
        
        height = 
    40dip
        
        nbr =     ScrollView2.Panel.NumberOfViews
        
    panel.Initialize("selectline")

        
        
        top =( (nbr) * (height+
    3dip))+5dip
        
    Dim label1 As Label
        
    Dim label2 As Label
        
    Dim label3 As Label
        
    Dim label4 As Label
        
    Dim label5 As Label
        label1.Initialize(
    "")
        label2.Initialize(
    "")
        label3.Initialize(
    "")
        label4.Initialize(
    "")
        label5.Initialize(
    "")
    '    btn.Initialize("")
        label1.Text = text1
        label2.Text = text2
        label3.Text = text3
        label4.Text = text4
        label5.Text = text5
        
        label1.textColor = 
    Colors.white
        label2.textColor = 
    Colors.white
        label3.textColor = 
    Colors.white
        label4.textColor = 
    Colors.white
        label5.textColor = 
    Colors.white
        
    If (Main.Istablet = TrueThen
            
    Dim Font1 As Font = Font.CreateNew(16)
        
    Else
            
    Dim Font1 As Font = Font.CreateNew(12)
        
    End If
        label1.font =Font1
        label2.font =Font1
        label3.font =Font1
        label4.font =Font1
        label5.font =Font1

        label2.TextAlignment = label2.ALIGNMENT_CENTER
        label3.TextAlignment = label3.ALIGNMENT_CENTER
        label4.TextAlignment = label4.ALIGNMENT_CENTER
        label5.TextAlignment = label4.ALIGNMENT_CENTER

        
        
        
    Dim info(4As Int
        info(
    0) = deviceid
        info(
    1) = output
        info(
    2) = nbr+1
        info(
    3) = text5
        
        
    panel.Color = Main.colorDark
        
    panel.Tag = info
        
    Dim widthscroll As Int
        widthscroll= ScrollView2.Width
        
    If (Main.Istablet = TrueThen
            left = 
    5
            width = (widthscroll/
    7)*2.5
            
    panel.AddView(label1,left,3,(widthscroll/7)*2.5,height)
            
            left = left + width
            width = ((widthscroll)/
    7)*1
            
    panel.AddView(label2,left,3,width,height)
            
            left = left + width
            width = ((widthscroll)/
    7)*1
            
    panel.AddView(label3,left,3,width,height)

            left = left + width
            width = ((widthscroll)/
    7)*1.5   
            
    panel.AddView(label4,left,3,width,height)
            
            left = left + width
            width = ((widthscroll)/
    7)*1
            
            
    panel.AddView(label5,left,0dip,width,40)
        
    Else
            left = 
    3dip
            width = ((ScrollView2.Width)/
    7)*2.5
            
    panel.AddView(label1,left,0dip,((ScrollView2.Width)/7)*2.5,height)
            
            left = left + width
            width = ((ScrollView2.Width)/
    7)*1
            
    panel.AddView(label2,left,0,width,height)
            
            left = left + width
            width = ((ScrollView2.Width)/
    7)*1
            
    panel.AddView(label3,left,0,width,height)

            left = left + width
            width = ((ScrollView2.Width)/
    7)*1.2   
            
    panel.AddView(label4,left,0,width,height)
            
            left = left + width
            width = ((ScrollView2.Width)/
    7)*1.25
        
            
    panel.AddView(label5,left,0dip,width,40)
        
    End If
        
    panel.SetBorder(0,Colors.Black,7)
        
        
        
        
        ScrollView2.Panel.AddView(
    panel,0dip,top,ScrollView2.Width,height)
        ScrollView2.ContentHeight = ((nbr+
    1)*(height+3dip))+5dip
        can3.Initialize(
    panel)
        can3.DrawLine(title1.left + title1.Width+
    1-ScrollView2.left,0,title1.left + title1.Width+1-ScrollView2.left,height,Colors.RGB(0x33,0x33,0x33),1dip)
        can3.DrawLine(title2.left + title2.Width+
    1-ScrollView2.left,0,title2.left + title2.Width+1-ScrollView2.left,height,Colors.RGB(0x33,0x33,0x33),1dip)
        can3.DrawLine(title3.left + title3.Width+
    1-ScrollView2.left,0,title3.left + title3.Width+1-ScrollView2.left,height,Colors.RGB(0x33,0x33,0x33),1dip)
        can3.DrawLine(title4.left + title4.Width+
    1-ScrollView2.left,0,title4.left + title4.Width+1-ScrollView2.left,height,Colors.RGB(0x33,0x33,0x33),1dip)
        can3.Refresh
        

    End Sub
     
  2. Semen Matusovskiy

    Semen Matusovskiy Well-Known Member Licensed User

    Guess, you call this Sub some times.

    Code:
    Dim panel As Panel
    ...
    ScrollView2.Panel.AddView(
    panel,0dip,top,ScrollView2.Width,height)
    Each time your sub creates a new panel. Meanwhile you need to remove previous instance.

    Declare panel in Process_Global and add

    Code:
    If panel.IsInitialized Then panel.RemoveViewFromParent
    before
    Code:
    panel.Initialize("selectline")
     
  3. electro179

    electro179 Active Member Licensed User

    the sub AddLineList(....,....,....) is called for each lines
    It can call once or some times

    the panel is declared in the sub AddLineList and so it is never initalized before

    Code:
    panel.Initialize("selectline")
    I have the problem even I call AddLineList() once.
     
  4. electro179

    electro179 Active Member Licensed User

    if I do
    Code:
    If panel.IsInitialized Then panel.RemoveViewFromParent
    The previous lines (previous panel) will be empty

    I have the impression that if I initialize a canvas in a panel that already contains another element, it duplicates the elements
    The layout is

    ScrollView
    Panel
    Label1

    /label1
    Label2

    /label2
    Label3

    /label3
    Label4

    /label4
    Label5

    /label5

    Canvas initialized in this panel​
    /Panel


    Panel
    Label1

    /label1
    Label2

    /label2
    Label3

    /label3
    Label4

    /label4
    Label5

    /label5

    Canvas initialized in this panel​
    /Panel​



    /scrollview
     
  5. Semen Matusovskiy

    Semen Matusovskiy Well-Known Member Licensed User

    Maybe I am wrong, but canvas requires a lot of memory.
    Did you try to replace lines by panels / labels ?
    For example, in my forms I add underline lines for textfields (like in Android) using label with height = 1 or 2 and use SetBorder to set a color.
     
  6. electro179

    electro179 Active Member Licensed User

    Ok thank you

    I create a panel to create a line :)
     
  7. klaus

    klaus Expert Licensed User

    You could also use the background color of the ScrollView.Panel, leaving a small space between the different panels.
     
    Erel and emexes like this.
  8. emexes

    emexes Well-Known Member Licensed User

    +1 always good to have a Plan B
    -1 a bit iffy, in that if the panel placement is off by a pixel, or if some pixel-position calculation rounds the wrong way, then the gap for the line of background might be occluded

    I did wonder why not use the panel's border? - I assumed that the extra lines on the left and right of the panel were too much... ???
     
  9. Erel

    Erel Administrator Staff Member Licensed User

    You should probably use xCustomListView instead of ScrollView.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice