Page 1 of 1
Gadget_BringToFront()
Posted: Sun Jul 23, 2017 1:03 pm
by codeit
Is there a way to bring a gadget to the front of all gadgets?
been looking but the only thing i have found is CocoaMessage Gadget_BringToFront
but when i try and use it i just get errors.
Thanks
"Talk is cheap. Show me the code."
Re: Gadget_BringToFront()
Posted: Sun Jul 23, 2017 2:21 pm
by Wolfram
Do you mean that it is layered above other gadgets or do you want to set the focus on that gadget?
Re: Gadget_BringToFront()
Posted: Sun Jul 23, 2017 3:19 pm
by wilbert
Click a button and it will move to the front.
Code: Select all
Procedure Gadget_BringToFront(Gadget)
Protected.i v, sv, subs
v = GadgetID(Gadget)
sv = CocoaMessage(0, v, "superview")
subs = CocoaMessage(0, 0, "NSMutableArray arrayWithArray:", CocoaMessage(0, sv, "subviews"))
If subs
CocoaMessage(0, subs, "removeObject:", v)
CocoaMessage(0, subs, "addObject:", v)
CocoaMessage(0, sv, "setSubviews:", subs)
EndIf
EndProcedure
If OpenWindow(0, 0, 0, 600, 340, "Gadget Reordering", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_ScreenCentered)
RandomSeed(0)
For i = 0 To 30
ButtonGadget(i, Random(500), Random(310), 100, 30, "Button " + Str(i))
Next
Repeat
EventID = WaitWindowEvent()
If EventID = #PB_Event_Gadget
Gadget_BringToFront(EventGadget())
EndIf
Until EventID = #PB_Event_CloseWindow
EndIf
Re: Gadget_BringToFront()
Posted: Sun Jul 23, 2017 3:44 pm
by codeit
Thanks wilbert you must be top dog around here cheers

Re: Gadget_BringToFront()
Posted: Sun Jul 23, 2017 3:48 pm
by wilbert
codeit wrote:Thanks wilbert you must be top dog around here cheers

Don't think so
I just tried a different approach which is a bit shorter and seems to eat up less cpu time.
You might want to try it instead.
Code: Select all
Procedure Gadget_BringToFront(Gadget)
Protected.i v = GadgetID(Gadget)
CocoaMessage(0, CocoaMessage(0, v, "superview"), "addSubview:", v)
EndProcedure
If OpenWindow(0, 0, 0, 600, 340, "Gadget Reordering", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_ScreenCentered)
RandomSeed(0)
For i = 1 To 30
ButtonGadget(i, Random(500), Random(310), 100, 30, "Button " + Str(i))
Next
Repeat
EventID = WaitWindowEvent()
If EventID = #PB_Event_Gadget
Gadget_BringToFront(EventGadget())
EndIf
Until EventID = #PB_Event_CloseWindow
EndIf
Re: Gadget_BringToFront()
Posted: Sun Jul 23, 2017 6:51 pm
by codeit
Thank's wilbert but i have gone wrong

i had to re create the form using form designer
and now i can't get it working at all i have played with but it looks like the bind event is not working
Please could you pass your eyes over it for me and see what's gone wrong.
https://www.dropbox.com/s/8byxcc8tdcfpt ... e.zip?dl=0
Re: Gadget_BringToFront()
Posted: Sun Jul 23, 2017 7:08 pm
by wilbert
codeit wrote:Please could you pass your eyes over it for me and see what's gone wrong.
I hope someone else can help you out with this one.
I don't know a lot about the form designer. Usually I add gadgets by code.
Re: Gadget_BringToFront()
Posted: Sun Jul 23, 2017 7:11 pm
by codeit
Ok thank's
Re: Gadget_BringToFront()
Posted: Mon Jul 24, 2017 12:19 pm
by IdeasVacuum
You could also consider temporarily hiding the other gadgets that are in the same location as the gadget you want to bring-to-front, no API required.
Code: Select all
HideGadget(#MyGadget01, #True)
HideGadget(#MyGadget02, #True)
HideGadget(#MyGadget03, #False) ;bring-to-front