B4J Question [B4X] Prevent pane overlapping in layout

Alexander Stolte

Expert
Licensed User
Longtime User
The goal is the following:
zKNBJDcPkH3AIXD3zd8Sfm2pVKpwlq6gIctlOqbYh5r9NZPJgm.jpeg


CSQxLeMhLbUuodJ5zfMgFpqCAk5rJXg1txVb6hblR73rzPDEIT.jpeg

The top position and the height of the panel must be kept, only the width and left position should be adjusted.
I rebuilt the laoyut from the 1st image, I can't get it to write a function that determines the best width and adjusts the panels to the left position.
 

Attachments

  • test.zip
    3.1 KB · Views: 82
Last edited:

LucaMs

Expert
Licensed User
Longtime User
The goal is the following:
View attachment 132393View attachment 132394
The top position and the height of the panel must be kept, only the width and left position should be adjusted.
I rebuilt the laoyut from the 1st image, I can't get it to write a function that determines the best width and adjusts the panels to the left position.
If you attach a project where the layout is totally different, how should we help you? :oops:
 
Upvote 0

Alexander Stolte

Expert
Licensed User
Longtime User
If you attach a project where the layout is totally different, how should we help you? :oops:
Where is the layout different from the photo?????

In the example project is a layout with:
1 Big Pane like Test1
2 panes like Test2 and Test4
under the 2 panes are one pane as Test3

Only all panes in my example have all the same length, because this is my starting position. From there the panels must be adjusted in width and from the left value, so that it looks like in the 1st picture.
 
Upvote 0

PaulMeuris

Active Member
Licensed User
From this situation:

panetest1.png


Go to this situation:
panetest2.png

Or a wider window:
panetest3.png

Here is some code to accomplish this:
set layout:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private devwidth As Int
    Private devheight As Int
End Sub
Public Sub Initialize
    B4XPages.GetManager.LogEvents = True
End Sub
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("frm_main")
End Sub
Private Sub B4XPage_Appear
    set_layout  
End Sub
Private Sub B4XPage_Resize (Width As Int, Height As Int)
    set_layout
End Sub
Private Sub set_layout
    devwidth = B4XPages.GetNativeParent(B4XPages.MainPage).RootPane.Width
    devheight = B4XPages.GetNativeParent(B4XPages.MainPage).RootPane.Height
    Dim lpos1 As Int = 0
    Dim lpos2 As Int = devwidth / 3
    Dim lpos3 As Int = lpos2 * 2
    Dim labelwidth As Int = devwidth / 3
    For i = 0 To Root.NumberOfViews -1
        Dim xpnl As B4XView = Root.GetView(i)
        Select i
            Case 0
                xpnl.Width = labelwidth
                xpnl.SetLayoutAnimated(0,lpos3,0,xpnl.Width,xpnl.Height)
            Case 1
                xpnl.Width = labelwidth
                xpnl.SetLayoutAnimated(0,lpos1,0,xpnl.Width,xpnl.Height)
            Case 2
                xpnl.Width = labelwidth * 2
                xpnl.SetLayoutAnimated(0,lpos1,xpnl.height,xpnl.Width,xpnl.Height)
            Case 3
                xpnl.Width = labelwidth
                xpnl.SetLayoutAnimated(0,lpos2,0,xpnl.Width,xpnl.Height)
        End Select
    Next
End Sub
Does this give you some idea?
This layout only adjusts when you resize the window from left to right or from right to left.
Happy coding!
Paul

EDIT: the pane width now takes the correct value.
 
Last edited:
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Have a look at the new designer scripts extensions . The SpreadControlsHorizontally method goes some way towards what you want. Create your own class, copy the code from the DDD class (there are a lot of method dependencies in the class). Create a new method based on the SpreadControlsHorizontally method. That should give you a start.
 
Last edited:
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Just re-read your post. You don't say if you want to automate it, or just get a script that works, This is the latter.
 

Attachments

  • test2.zip
    2.9 KB · Views: 76
Upvote 0

Alexander Stolte

Expert
Licensed User
Longtime User
I will explain it better later, I am not at home right now.
I need this for my scheduler, for the dayviev. My current algorithm does not cover all appointment scenarios.There I check if there are overlaps. This works well, but in the scenarios like in picture 1 and picture 2 it does not find all overlaps.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Luca,
Did you see message # 5 or @Erel is there some delay on the forum that doesn't display my messages?
I have seen it but I have not read it well, because if I have not misunderstood @Alexander Stolte has not published the layout he would like to obtain with the exception of the panel to be positioned well. I saw that you wrote some code to get it, starting from the published one, which contains only 4 Labels positioned very differently.
 
Upvote 0

Alexander Stolte

Expert
Licensed User
Longtime User
I have created a new thread, with a more detailed example project and 2 functions that almost give the desired result.
 
Upvote 0
Top