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."
Gadget_BringToFront()
Re: Gadget_BringToFront()
Do you mean that it is layered above other gadgets or do you want to set the focus on that gadget?
macOS Catalina 10.15.7
Re: Gadget_BringToFront()
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
Windows (x64)
Raspberry Pi OS (Arm64)
Raspberry Pi OS (Arm64)
Re: Gadget_BringToFront()
Thanks wilbert you must be top dog around here cheers
Re: Gadget_BringToFront()
Don't think socodeit wrote:Thanks wilbert you must be top dog around here cheers
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
Last edited by wilbert on Sun Jan 06, 2019 10:47 am, edited 1 time in total.
Windows (x64)
Raspberry Pi OS (Arm64)
Raspberry Pi OS (Arm64)
Re: Gadget_BringToFront()
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
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()
I hope someone else can help you out with this one.codeit wrote:Please could you pass your eyes over it for me and see what's gone wrong.
I don't know a lot about the form designer. Usually I add gadgets by code.
Windows (x64)
Raspberry Pi OS (Arm64)
Raspberry Pi OS (Arm64)
Re: Gadget_BringToFront()
Ok thank's
-
- Always Here
- Posts: 6425
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: Gadget_BringToFront()
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
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.