B4J Question [Solved] Programmatically changing a view's Top or Left doesn't move the view

LucaMs

Expert
Licensed User
Longtime User
B4X:
Sub ShowDialog

    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0, 0, 0, 600dip, 620dip)
    p.LoadLayout("test")

    Dialog.Initialize(MainForm.RootPane)
    Dialog.BackgroundColor = xui.Color_LightGray ' fx.Colors.To32Bit(fx.Colors.LightGray)

    Dim rs As ResumableSub = Dialog.ShowCustom(p, "", "", "Done")
    Sleep(0)

    Pane2.Top = Pane1.top + Pane1.Height + 10dip ' <<<< Issue: Pane2 isn't moving...
    Label1.Left = 150dip ' <<<< ... and neither is Label1

    Wait For (rs) Complete(Result As Int)

End Sub
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Brilliant, thanks a lot @LucaMs ; can you help me understand why my original code didn't work?
An Italian comedian says (purposely making a grammatical mistake):
"Se lo sapessi, te lo dissi" ("If I knew, I told you") 😄

I just did some tests, even without Resumable.
ShowDialog probably needs that Sleep to freshen up the pane.
 
Last edited:
Upvote 0

agraham

Expert
Licensed User
Longtime User
can you help me understand why my original code didn't work?
This is a bit simplistic but might help you see what is happening behind the scenes. Many graphical things are done on the same thread your code is running on. Your thread has a message loop running when your code is not executing that is receiving messages from the OS and possibly other programs and responding to them. This is how, for example your Button Click event works. The OS detects you have pressed the button, posts a message to that effect to your message loop which then runs your Click event Sub. Until you exit your Sub and return to the message loop the messages about moving the views cannot be executed and are sitting there queued for action. A modal dialog does not return to the message loop until you close it.

I suspect you don't need the Resumable Sub. A call to Sleep(0) after you have moved the controls will probably suffice as that returns to the message loop which can then process the messages that move the views. Another message on the message queue posted by Sleep then restarts your Sub where the Sleep left it.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

walt61

Active Member
Licensed User
Longtime User
Thanks for your replies, guys. I had indeed added a Sleep(0) when trying to move the views *before* the 'Dim rs...' but to no avail. It's not a matter of resizing here: the real dialog contains several panes that are visible or not, depending on certain conditions. Some panes in the middle of the dialog could then become invisible, leaving an empty space - and that's what I wanted to avoid: I wanted to bring the bottom ones up then so that they're all adjacent.
 
Upvote 0
Top