Italian Chiudere un panello al di furi di esso

ken87

Active Member
Licensed User
Longtime User
Ciao nella mia app di prova ho un panello che mi gestisce un menu, ho la necessità che quando vine generato un evento click al di fuori del panello questo vine chiuso.

B4X:
IF  puntatore fuori panel1 then
panel1.visible = false
end if
Come faccio a dirgli che quando è fuori?
Ho pensato all'evento clik ad esempio se c'e una label:
B4X:
sub label1_click
panel1.visible =false
end sub
Il problema che non tutti i componenti hanno evento click tipo il controllo tab, quindi pensavo alla prima soluzione ma non so come faer rilevare l'evento furi da un ogetto.
Grazie mille
 

Star-Dust

Expert
Licensed User
Longtime User
Metti il pannello del menu attaccarlo a un pannello trasparente grande qua to lo schermo.

Cattura l'evento Touch del pannello trasparente. Al momento che touch chiudi il menu e pannello.
 

Star-Dust

Expert
Licensed User
Longtime User
Esempio grosso modo, perché sono con lo smartphone

B4X:
PanelTrasparent.Addview(PanelMenu,0,0,100%x,100%y)
PanelTrasparent.Color=Colors.Trasparent

Sub PanelTrasparent_Touch( ...)
PanelTrasparent.Visible=False
End Sub
 

ken87

Active Member
Licensed User
Longtime User
Ciao avevo già provato qualcosa di simile
panello trasparente (pan1)
il panello menu sul panello trasparente (pan2)
ma se metto ogetto tipo tab tab (TabStrip) , nell'area dove c'è il tab che è sopra il panello trasparante evento diventa quello del tab? quindi non riese a chiudere
 

LucaMs

Expert
Licensed User
Longtime User
L'unico modo che mi viene in mente per poter gestire il click sulle linguette del TabStrip (a parte che si cambia linguetta, puoi intercettare l'evento PageSelected che può fare le veci dell'evento click, ma soltanto in caso di cambio pagina, appunto) è di sovrapporre un pannello trasparente sulle linguette, pannello che dovrà contenere un button, anch'esso trasparente, per ogni linguetta. Il problema è calcolare le dimensioni esatte.
 

Star-Dust

Expert
Licensed User
Longtime User
Il tab trasparente serve solo intercettare il tocco nello spazio esterno al tab, nello spazio interno al tab il tocco deve essere intercettato dal campo stesso o dal pannello dove c'è il menù.

Dopo che il pannello trasparente viene cliccato, sparirà diventando Invisibile e non interesserà più l'evento touch
 

ken87

Active Member
Licensed User
Longtime User
Ciao ,
allora ho scritto questo
B4X:
#Region  Project Attributes
    #ApplicationLabel: panchiudi
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
Se faccio click sulla parte rossa vedi allegato non ho nessun risultato

    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private Panel2 As Panel
    Private TabStrip1 As TabStrip
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("uno")
    TabStrip1.LoadLayout("due", "Voce 1")
    TabStrip1.LoadLayout("tre", "Voce 2")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub Panel1_Touch (Action As Int, X As Float, Y As Float)
    Panel2.Visible=False
end sub

Se premo il tab a banco non succede nulla perchè e all'inerno del componente.
L'unico evento che ho è questo:

B4X:
Sub TabStrip1_PageSelected (Position As Int)
    Panel2.Visible=False
End Sub
Ma questo funziona se passo da voce 1 a voce 2
ma se premo voce 1 come faccio a chiudere il panello?
 

Attachments

  • fraccia.jpg
    fraccia.jpg
    171.5 KB · Views: 208
Last edited:

Star-Dust

Expert
Licensed User
Longtime User
Scusa ma non ho capito il problema che esponi.

In ogni caso ho trovato un errore nel tuo codice, quando tocchi il pannello trasparente deve sparire il pannello trasparente e il menu.

B4X:
Sub PanelTrasparente_Touch (Action As Int, X As Float, Y As Float)
    PanelTrasparente.Visible=False
    PanelMenu.Visible=false
end sub

PanelTrasparente verrà messo visibile quando riapri il menu
 

Star-Dust

Expert
Licensed User
Longtime User
Ti allego un breve esempio tutto in codice di quello che ti spiego io.
Un menu a comparsa che si apre e chiude da un bottone .... ma se clicchi fuori dal menu si chiude.

Ricopiatelo e provalo.
B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Private PanelTrasparente As Panel
    Private PanelMenu As Panel
    Private ButtonMenu As Button
   
    Private LabelVoce1 As Label
    Private LabelVoce2 As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'pannello trasparente che copre lo schermo
    PanelTrasparente.Initialize("PanelTrasparente")
    PanelTrasparente.Color=Colors.Transparent
    Activity.AddView(PanelTrasparente,0,0,100%x,100%y)
   
    ' Pannello Menu
    PanelMenu.Initialize("PanelMenu")
    PanelMenu.Color=Colors.Yellow
    PanelTrasparente.AddView(PanelMenu,0,0,50%x,100%y)
   
    'Label all'interno del pannello menu
    LabelVoce1.Initialize("")
    LabelVoce1.Text="Voce1"
    LabelVoce1.TextColor=Colors.Black
    PanelMenu.AddView(LabelVoce1,20dip,100dip,50%x,40dip)
   
    LabelVoce2.Initialize("")
    LabelVoce2.Text="Voce2"
    LabelVoce2.TextColor=Colors.Black
    PanelMenu.AddView(LabelVoce2,20dip,140dip,50%x,40dip)
   
    'Bottone apertura e chiusura menu
    ButtonMenu.Initialize("ButtonMenu")
    ButtonMenu.Color=Colors.White
    ButtonMenu.TextColor=Colors.Black
    ButtonMenu.Text="M"
    Activity.AddView(ButtonMenu,5dip,5dip,40dip,40dip)
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub PanelTrasparente_Touch (Action As Int, X As Float, Y As Float)
    PanelTrasparente.Visible=False
End Sub

Sub PanelMenu_Touch (Action As Int, X As Float, Y As Float)
    ' intercetta il tocco ma non fa nulla
End Sub

Sub ButtonMenu_Click
    PanelTrasparente.Visible=Not(PanelTrasparente.Visible)
End Sub
 

ken87

Active Member
Licensed User
Longtime User
Poi provo ad aggiungere l 'istruzione ma se il mouse si trova nella parte rossa del controllo tab non intercetta più il comando di chiusura. Provo e ti dico.. grazie per ora
 

Star-Dust

Expert
Licensed User
Longtime User
Il pannello trasparente dev'essere sotto il TabStrip e non sopra
 

ken87

Active Member
Licensed User
Longtime User
Provo e poi ti dico se poi non riesco posto il progetto di test
 

Star-Dust

Expert
Licensed User
Longtime User
Cambiai Nomi dei Pannelli cosi si capisce meglio. ad esempio
PannelloMenu, PannelloTrasparente ecc...

in ogni caso il pannello del Menu (che tu chiami panel1) dove si trova dentro lo StripTab? Fuori?

Se posti il progetti e metti i nomi più chiari ai pannelli magari ti possiamo aiutare..
 

ken87

Active Member
Licensed User
Longtime User
Non Sono a casa
. Quando arrivo posto tutto ... grazie mille.. il problema lo riacontrato anche con un componente... posto tutto così lo puoi provare ...
 

ken87

Active Member
Licensed User
Longtime User
Ciao, ho provato ma nulla,
Allora ho provato a fare un altro progetto di prova :
C' è un panello rosso (Panmenu) che conterrà il mio menu
icona nella barra per aprirlo e chiuderlo
il Pansfondo = panello colorato verde di sfondo.
quale fa la chiusura
Allego il codice sordente:

B4X:
#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
Dim attiva As Boolean
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private Panmenu As Panel
    Private Pansfondo As Panel
    Private TabStrip1 As TabStrip
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("uno")
    Activity.AddMenuItem3("apri","apri",LoadBitmap(File.DirAssets,"ic_action_overflow.png"),True)
    TabStrip1.LoadLayout("due", "voce due")
    TabStrip1.LoadLayout("tre", " voce tre")
    attiva= False
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub apri_click
    If attiva = False Then
        Panmenu.Visible = True
        attiva = True
    Else
        Panmenu.Visible = False
        attiva = False
    End If

End Sub

Sub Panmenu_Click
    Panmenu.Visible=False
    Panmenu.bringtofront
    attiva = False
End Sub


Sub Pansfondo_Touch (Action As Int, X As Float, Y As Float)
    Panmenu.Visible=False
    Panmenu.bringtofront
    attiva = False
End Sub

Il panello di sfondo chiude il menu:

B4X:
Sub Pansfondo_Touch (Action As Int, X As Float, Y As Float)
    Panmenu.Visible=False
    Panmenu.bringtofront
    attiva = False
End Sub
Infine un
B4X:
Private TabStrip1 As TabStrip

Che ha due voci

B4X:
TabStrip1.LoadLayout("due", "voce due")
    TabStrip1.LoadLayout("tre", " voce tre")

Il problema e che quando premo sulla voce voce due non so come far chidere il menu

Allego nel file le finestre.
Non sono riuscito ad allegare il progetto intero per supera la dimensione consentita
 

Attachments

  • Files.zip
    5.8 KB · Views: 225
Last edited:

Star-Dust

Expert
Licensed User
Longtime User
Per inviare il file zip fai Esporta Zip dal menu File
 

ken87

Active Member
Licensed User
Longtime User
Ciao ho aggiunto un panello sopra inv
che va sopra il controllo tab per poter chiudere il menu.
Con questo codice:
B4X:
Sub inv_Touch (Action As Int, X As Float, Y As Float)
    Panmenu.Visible=False
    Panmenu.bringtofront
    attiva = False
    inv.Enabled =False
End Sub
Cosi il menu si chiude , ma il controllo del mouse sul tab c'ho al secondo click
ecco esempio
 

Attachments

  • menu.zip
    12.7 KB · Views: 210

Star-Dust

Expert
Licensed User
Longtime User
Ho visto il codice, mi sa che hai un gran casino nelle idee.

Cmq ho modificato il codice per adattarlo a quello che hai scritto tu

P.S. il colore trasparente del pannello invisibile, visto che lo hai creato nel design lo puoi impostare direttamente da design.
 

Attachments

  • menu2.zip
    12.8 KB · Views: 207
Top