I need a dynamic solution to adjust panels in width and left so that they are displayed without colliding.
In my example i have 4 Appointements, 3 Appointments start at the same time but end at different times. The 4th appointment "Test3" starts after the 2 other appointments, but still collides with the "Test1" appointment. I need a dynamic function that detects this and adjusts the panels to it.
My picture was taken with the following code:
I have written a 2nd function that looks a bit simpler but still has problems with the right width
The function thinks that Test1 was divided by 2 and not by 3, so Test3 is too short.
In my example i have 4 Appointements, 3 Appointments start at the same time but end at different times. The 4th appointment "Test3" starts after the 2 other appointments, but still collides with the "Test1" appointment. I need a dynamic function that detects this and adjusts the panels to it.
My picture was taken with the following code:
B4X:
Private Sub CheckOverlapping(i As Int,xlbl_Appointment As B4XView,Appointment1 As Appointment)
Dim Appointment2 As Appointment = IIf(i > 0,lst_Appointments.Get(i -1),lst_Appointments.Get(i)) 'Get the Appointment that is before Appointment1
Dim Go As Boolean = False 'If Go = True then no more collissions detected
If CheckKolission(Appointment1,Appointment2) Then
lstCollission.Add(i) 'If the previous appointment conflicts with our appointment, add the index to the list.
If i > 0 Then
'Checks if the item is already in the list
Dim Found As Boolean = False
For Each test As Int In lstCollission
If test = (i -1) Then Found = True
Next
If Found = False Then lstCollission.Add(i-1)
End If
Else
Go = True 'no more collissions detected
End If
If i = (lst_Appointments.Size -1) Then Go = True 'or the appointment is the last item in the list
If Go = True Then
lstCollission.Sort(True)
'Adjusts the appointments in width and left
For app2 = 0 To lstCollission.Size -1
Dim xlbl_Item As B4XView = Root.GetView(lstCollission.Get(app2))
Dim ListSize As Int = lstCollission.Size
xlbl_Item.Left = (Root.Width/ListSize)*app2
xlbl_Item.Width = Root.Width/ListSize
Next
lstCollission.Clear
End If
End Sub
I have written a 2nd function that looks a bit simpler but still has problems with the right width
The function thinks that Test1 was divided by 2 and not by 3, so Test3 is too short.
B4X:
Private Sub CheckOverlapping2(xlbl_Appointment As B4XView,Appointment1 As Appointment)
Dim Divider As Int = 1
For test = 0 To lst_Appointments.Size -1
Dim Appointment2 As Appointment = lst_Appointments.Get(test)
If Appointment1.id <> Appointment2.Id And CheckKolission(Appointment1,Appointment2) Then
Dim Appointment3 As Appointment = IIf((test -1) >= 0,lst_Appointments.Get(test -1),lst_Appointments.Get(test +1))
If CheckKolission(Appointment3,Appointment2) = True Then
Divider = Divider +1
If CheckKolission(Appointment3,Appointment1) = False Then
LeftPosition = 0
End If
End If
End If
Next
LeftPosition = LeftPosition +1
If Divider = 0 Or Divider = 1 Then LeftPosition = 0
xlbl_Appointment.Width = ((Root.Width)/Divider)
xlbl_Appointment.Left = xlbl_Appointment.Width * LeftPosition
End Sub