Page 1 of 1

Layerbuttons when swapping layer positions

Posted: Mon May 04, 2020 6:40 pm
by jPV
If I have overlapping layer buttons and change layers order, the original layerbutton stays in front even when the layer it's attached into isn't in front anymore. I think this is a bug or is there some explanation or work-around?

Code: Select all

Function p_LayerEvent(msg)
    DebugPrint("Mouse moved over layer:", msg.layer, msg.layername)
EndFunction

Function p_SwapLayers()
    Local id, name$
    SwapLayers(1, 2)
    id, name$ = GetLayerAtPos(10, 10)
    DebugPrint("Mouse clicked,", name$, "is in front.")
EndFunction

EnableLayers()
SetFillStyle(#FILLCOLOR)
Box(10, 10, 100, 100, #RED, {Name="red"})
Box(10, 10, 100, 100, #BLUE, {Name="blue"})
MakeButton(1, #LAYERBUTTON, "red", False, False, {OnMouseOver=p_LayerEvent})
MakeButton(2, #LAYERBUTTON, "blue", False, False, {OnMouseOver=p_LayerEvent})

EscapeQuit(True)

InstallEventHandler({OnMouseUp=p_SwapLayers})

Repeat
    WaitEvent()
Forever
The result looks like this:

Mouse moved over layer: 2 blue
Mouse clicked, red is in front.
Mouse moved over layer: 1 blue
Mouse clicked, blue is in front.
Mouse moved over layer: 2 blue
Mouse clicked, red is in front.
Mouse moved over layer: 1 blue

As you can see, the events will come always from the layer that was in front originally even though it isn't visible anymore. Looks like button order doesn't follow the layer order.

Re: Layerbuttons when swapping layer positions

Posted: Mon May 04, 2020 10:06 pm
by Bugala
I have used "LayerToFront" and it have worked fine so far, but in one thread where i was asking about this, I think Andreas said that there is no guarantee that top most layerbutton actually is topmost button.

Re: Layerbuttons when swapping layer positions

Posted: Tue May 05, 2020 6:30 am
by jPV
Ok... but I need to organize layers without bringing them always to front, but shuffle them in the middle too, so that work-around doesn't work for me.

Re: Layerbuttons when swapping layer positions

Posted: Tue May 05, 2020 3:26 pm
by Bugala
If LayerToFront works, you can reorder several of them. It isnt good, but it can be a workaround.

That let's say we have Layers:

A, B, C, D, E

and now I want E to middle

LayertoFront(C)
LayertoFront(D)

and it looks A, B, E, C, D


Not ideal, but works as long as LayerToFront works with the button placing.

Re: Layerbuttons when swapping layer positions

Posted: Tue May 05, 2020 5:09 pm
by jPV
I made a work-around by deleting and recreating all buttons always when the layer order changes, it seems to work so far... but thanks for your suggestion too.

Re: Layerbuttons when swapping layer positions

Posted: Tue May 05, 2020 5:26 pm
by Bugala
I think deleting and recreating is a safer option since basically there is no guarantee that layertofront would work either, could change on the next version or something.

Re: Layerbuttons when swapping layer positions

Posted: Sat May 09, 2020 12:46 pm
by airsoftsoftwair
jPV wrote: Mon May 04, 2020 6:40 pm As you can see, the events will come always from the layer that was in front originally even though it isn't visible anymore. Looks like button order doesn't follow the layer order.
Yes, but that's more of a feature instead of a bug because AFAICS layer order currently doesn't have any effect on button order because MakeButton() simply chains the buttons into a list and that list is the sole determiner of the order of handling. That's probably not a very desirable implementation but of course changing this will break compatibility...

Re: Layerbuttons when swapping layer positions

Posted: Sat Dec 12, 2020 7:23 pm
by airsoftsoftwair

Code: Select all

- New: When used with type #LAYERBUTTON, MakeButton() now supports a new table tag named "ZOrder"; if this
  is set to TRUE, the layer button will respect the layer z-order; this is useful for buttons attached to
  overlapping layers; if those buttons have the "ZOrder" tag set, they will trigger in the order defined
  by the layer stack z-order