B4A Library [Class] Floating Windows

Hello,

With this class, you can create floating windows, move them with the finger, dock them, stick them to an edge, maximize them, customize their action bar... You fill them as you fill a panel.

This class needs the Reflection library.

img1.jpg puzzle.png

v1.1:
The class has been splitted in two: ClsFloatingWindow and ClsActionBar.
This version includes a lot of changes.

v1.2:
Fixed bugs
Added a resize button
Added new functions and parameters
Added animations for docking areas and sticky edges
Changed the parameters returned by the custom buttons so as to be consistent with the ready-made buttons
Improved management of overlapping special areas
Improved the formula used to detect a move

v1.21:
Fixed a conflict between StillVisible and the special areas

v1.22:
Fixed two bugs in CheckSpecialAreas (thanks to Awama)

v1.23:
Fixed five bugs (yes, five... :()

v1.24:
Updated the ActionBar class required by this class.

v1.25:
Fixed a bug in the computation of covered areas while docking a window;
Updated the ActionBar class required by this class;
No more warnings with B4A v2.7.

v1.26:
Updated the ActionBar class required by this class.

Fred
 

Attachments

  • FloatingWindows v1.26.zip
    32.6 KB · Views: 1,731
Last edited:

georgelbs

Member
Licensed User
Longtime User
Thanks Informatix, the code worked after a little fix (add parameter Btn as View)

Public Sub ForcePin(Enabled As Boolean, Btn As View)
'Pins the window on its parent (cannot move)
wPinned = Enabled
' 'Update the state drawables
UpdateStateDrawables(wPinned, Btn)
If SubExists(wModule, OnPinWinSub) Then CallSub2(wModule, OnPinWinSub, Me)
End Sub
 

rafaelbr20

Member
Licensed User
Longtime User
Hi Informatix !

Great Class !

I´m using a transparent window with a background image and with hidden title .

I would like to enable the "close button" even when the title is hidden, but when i hide the title the "close button" dissapear.

Could you help me ?

Thanks so Much

Doesn´t work
B4X:
    Dim win As ClsFloatingWindow
    win.Initialize(Activity, 0, 0, dadosDimensao(0), dadosDimensao(1), Me)
    win.EnableResizeButton(True)
    win.EnableCloseButton(True,True,"Before_Close")
    win.ChangeResizeIcon(LoadBitmap(File.DirAssets,"resize.png"))
    win.ChangeCloseIcon(LoadBitmap(File.DirAssets,"fechar.png"))
    win.EnableTitleBar(False) 'Hidden Title bar


Works
B4X:
    Dim win As ClsFloatingWindow
    win.Initialize(Activity, 0, 0, dadosDimensao(0), dadosDimensao(1), Me)
    win.EnableResizeButton(True)
    win.EnableCloseButton(True,True,"Before_Close")
    win.ChangeResizeIcon(LoadBitmap(File.DirAssets,"resize.png"))
    win.ChangeCloseIcon(LoadBitmap(File.DirAssets,"fechar.png"))
    win.EnableTitleBar(True) 'Show Title bar
 

Informatix

Expert
Licensed User
Longtime User
Hi Informatix !

Great Class !

I´m using a transparent window with a background image and with hidden title .

I would like to enable the "close button" even when the title is hidden, but when i hide the title the "close button" dissapear.

Could you help me ?

Thanks so Much

Doesn´t work
B4X:
    Dim win As ClsFloatingWindow
    win.Initialize(Activity, 0, 0, dadosDimensao(0), dadosDimensao(1), Me)
    win.EnableResizeButton(True)
    win.EnableCloseButton(True,True,"Before_Close")
    win.ChangeResizeIcon(LoadBitmap(File.DirAssets,"resize.png"))
    win.ChangeCloseIcon(LoadBitmap(File.DirAssets,"fechar.png"))
    win.EnableTitleBar(False) 'Hidden Title bar


Works
B4X:
    Dim win As ClsFloatingWindow
    win.Initialize(Activity, 0, 0, dadosDimensao(0), dadosDimensao(1), Me)
    win.EnableResizeButton(True)
    win.EnableCloseButton(True,True,"Before_Close")
    win.ChangeResizeIcon(LoadBitmap(File.DirAssets,"resize.png"))
    win.ChangeCloseIcon(LoadBitmap(File.DirAssets,"fechar.png"))
    win.EnableTitleBar(True) 'Show Title bar
1) As the class code is provided, feel free to modify it to fit your needs.
2) The first thing to do is probably to set the visibility of all unneeded buttons to False and the color of wTitleBar to Transparent when the title bar is not enabled. Example:
B4X:
Public Sub EnableTitleBar(Enabled As Boolean)
    If Not(Enabled) Then
        If btnPin.IsInitialized Then btnPin.Visible = False
        If btnMaximize.IsInitialized Then btnMaximize.Visible = False
        wTitleBar.Color = Colors.Transparent
    End If
End Sub
 

rafaelbr20

Member
Licensed User
Longtime User
1) As the class code is provided, feel free to modify it to fit your needs.
2) The first thing to do is probably to set the visibility of all unneeded buttons to False and the color of wTitleBar to Transparent when the title bar is not enabled. Example:
B4X:
Public Sub EnableTitleBar(Enabled As Boolean)
    If Not(Enabled) Then
        If btnPin.IsInitialized Then btnPin.Visible = False
        If btnMaximize.IsInitialized Then btnMaximize.Visible = False
        wTitleBar.Color = Colors.Transparent
    End If
End Sub


Perfect Informatix !

I´ll try it ! Thanks so Much !

Rafael
 

IdasI4A

Active Member
Licensed User
Longtime User
This is wonderful.

Can you make a window is modal?.
I mean, when this visible, only she receives all keyboard events and screen.

(Original:
Esto es maravilloso.

¿Se puede hacer que una ventana sea modal?.
Osea, que cuando este visible, sólo ella reciba todos los eventos del teclado y de la pantalla.)

Thanks.
Sorry for my English.
 

Informatix

Expert
Licensed User
Longtime User
This is wonderful.

Can you make a window is modal?.
I mean, when this visible, only she receives all keyboard events and screen.

No it is not possible as modal windows require a very different code behind. The common workaround in this case is to ignore the events of all windows other than the one you want to be modal (with a global boolean shared by all windows).
 

IdasI4A

Active Member
Licensed User
Longtime User
Based on your code, I have simulated a modal window.
Would you can take a look?

(Spanish: Basandome en tu código, he simulado una ventana modal.
¿Le puedes echar un vistazo?)
 

Attachments

  • WindowModal.zip
    8.1 KB · Views: 326

billyrudi

Active Member
Licensed User
Longtime User
Hi good job
There is a way to loop in each the windows views that i have added?:(
 

deantangNYP

Active Member
Licensed User
Longtime User
Please advise.. Thanks.
From your sample code, if I wish to stop the W(0) from moving, is this the way to do it?
by adding "W(0).Move(-1,-1,False)" ?
B4X:
Sub After_Move(Window As ClsFloatingWindow)
    If Sender = W(0) Then
        W(0).Move(-1,-1,False)
    End If
  
    Log("NewX=" & Window.getLeft)
    Log("NewY=" & Window.getTop)
End Sub
 

Informatix

Expert
Licensed User
Longtime User
Please advise.. Thanks.
From your sample code, if I wish to stop the W(0) from moving, is this the way to do it?
by adding "W(0).Move(-1,-1,False)" ?
B4X:
Sub After_Move(Window As ClsFloatingWindow)
    If Sender = W(0) Then
        W(0).Move(-1,-1,False)
    End If
 
    Log("NewX=" & Window.getLeft)
    Log("NewY=" & Window.getTop)
End Sub
The better way is to modify the class to allow to change the state of wPinned. With wPinned = true, the window cannot move.
 

leonardo pino

Member
Licensed User
Longtime User
Hi, in the Example FloatWinDemo2, I want use an image Background,
but not how to do it,

I try:
Win.SetBackground= LoadBitmap(File.DirAssets,"fruit_0.png")
Win.SetBackground= (File.DirAssets,"fruit_0.png")
Win.SetBackground= ("fruit_0.png")

It Don't Work... :(

Thanks By your help, o_O
 

Informatix

Expert
Licensed User
Longtime User
Hi, in the Example FloatWinDemo2, I want use an image Background,
but not how to do it,

I try:
Win.SetBackground= LoadBitmap(File.DirAssets,"fruit_0.png")
Win.SetBackground= (File.DirAssets,"fruit_0.png")
Win.SetBackground= ("fruit_0.png")

It Don't Work... :(

Thanks By your help, o_O
As the function help says, Background needs a valid drawable, so a bitmap cannot be used here. You have to convert it to a BitmapDrawable.
 

Ondra

Member
Licensed User
Longtime User
Hi !
It is nice work man :) I am trying to do something simillar, but I need to stick panels each other, if the gap beetween panels would be smaller than for exp. 5dip. But because all objects are inserted dynamically, I cannot find way, how to detect collision of the objects. Have you any idea, please ?
I will be glad for any advice ;-)
 
Top