PB 6.10 Beta 2/3: SetActiveGadget not working

Just starting out? Need help? Post your questions and find answers here.
OBrien
User
User
Posts: 12
Joined: Fri Dec 22, 2023 10:37 pm

PB 6.10 Beta 2/3: SetActiveGadget not working

Post by OBrien »

Hello all,

This is really a big problem:

Code: Select all


win = OpenWindow(#PB_Any, 100,100,400,400,"Test",#PB_Window_SystemMenu)
btn1 = ButtonGadget(#PB_Any, 10,10,200,30,"")
btn2 = ButtonGadget(#PB_Any, 10,50,200,30,"")

SetActiveGadget(chk1)

Repeat
  E = WaitWindowEvent()
Until E = #PB_Event_CloseWindow
Can anyone confirm the issue, please?

Best regards

OS Linux Mint 21.2 / Subsystem GTK
User avatar
mk-soft
Always Here
Always Here
Posts: 6320
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: PB 6.10 Beta 2/3: SetActiveGadget not working

Post by mk-soft »

Your bug.

There are not an any gadget 'chk1'
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
Lord
Addict
Addict
Posts: 907
Joined: Tue May 26, 2009 2:11 pm

Re: PB 6.10 Beta 2/3: SetActiveGadget not working

Post by Lord »

chk1 <> btn1
chk1 <> btn2
Image
infratec
Always Here
Always Here
Posts: 7662
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: PB 6.10 Beta 2/3: SetActiveGadget not working

Post by infratec »

Always use ...

Code: Select all

EnableExplicit
To deselect all Gadgets, you can use:

Code: Select all

SetActiveGadget(-1)
OBrien
User
User
Posts: 12
Joined: Fri Dec 22, 2023 10:37 pm

Re: PB 6.10 Beta 2/3: SetActiveGadget not working

Post by OBrien »

Sry,
SetActiveGadget(btn2)
Is not working for me.
Do you test this ?
infratec
Always Here
Always Here
Posts: 7662
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: PB 6.10 Beta 2/3: SetActiveGadget not working

Post by infratec »

Strange btn1 works, btn2 not:

Code: Select all

EnableExplicit

Define.i win, btn1, btn2, E

win = OpenWindow(#PB_Any, 100,100,400,400,"Test",#PB_Window_SystemMenu)
btn1 = ButtonGadget(#PB_Any, 10,10,200,30,"")
btn2 = ButtonGadget(#PB_Any, 10,50,200,30,"")

SetActiveGadget(btn2)

Repeat
  E = WaitWindowEvent()
Until E = #PB_Event_CloseWindow
PB 6.10b5 x86 asm and C backend on Win10 x64

This works:

Code: Select all

EnableExplicit

Define.i win, btn1, btn2, E

OpenWindow(0, 100,100,400,400,"Test",#PB_Window_SystemMenu)
ButtonGadget(0, 10,10,200,30,"")
ButtonGadget(1, 10,50,200,30,"")

SetActiveGadget(1)

Repeat
  E = WaitWindowEvent()
Until E = #PB_Event_CloseWindow
Again a problem of #PB_Any
breeze4me
Enthusiast
Enthusiast
Posts: 633
Joined: Thu Mar 09, 2006 9:24 am
Location: S. Kor

Re: PB 6.10 Beta 2/3: SetActiveGadget not working

Post by breeze4me »

infratec wrote: Sun Feb 04, 2024 3:26 pm Strange btn1 works, btn2 not:

Code: Select all

EnableExplicit

Define.i win, btn1, btn2, E

win = OpenWindow(#PB_Any, 100,100,400,400,"Test",#PB_Window_SystemMenu)
btn1 = ButtonGadget(#PB_Any, 10,10,200,30,"")
btn2 = ButtonGadget(#PB_Any, 10,50,200,30,"")

SetActiveGadget(btn2)

Repeat
  E = WaitWindowEvent()
Until E = #PB_Event_CloseWindow
PB 6.10b5 x86 asm and C backend on Win10 x64

This works:

Code: Select all

EnableExplicit

Define.i win, btn1, btn2, E

OpenWindow(0, 100,100,400,400,"Test",#PB_Window_SystemMenu)
ButtonGadget(0, 10,10,200,30,"")
ButtonGadget(1, 10,50,200,30,"")

SetActiveGadget(1)

Repeat
  E = WaitWindowEvent()
Until E = #PB_Event_CloseWindow
Again a problem of #PB_Any
On Windows, it seems that the focus rectangle is sometimes not drawn.
It doesn't always fail to draw, but it seems to be more likely to happen when compiling without a debugger.
The same issue occurs in both PB 6.10 b5 x64 and x86 versions.

Workaround:
https://www.purebasic.fr/english/viewto ... 65#p315265

Code: Select all

EnableExplicit

#UIS_SET        = 1
#UIS_CLEAR      = 2
#UIS_INITIALIZE = 3
#UISF_HIDEFOCUS = 1
#UISF_HIDEACCEL = 2
#UISF_ACTIVE    = 4

Procedure SetUIState(hwnd, LoWord, HiWord)
  SendMessage_(hwnd, #WM_UPDATEUISTATE, (LoWord & $FFFF) | (HiWord<<16), 0)
EndProcedure

Define.i win, btn1, btn2, E

win = OpenWindow(#PB_Any, 100,100,400,400,"Test",#PB_Window_SystemMenu)
btn1 = ButtonGadget(#PB_Any, 10,10,200,30,"")
btn2 = ButtonGadget(#PB_Any, 10,50,200,30,"")

SetUIState(WindowID(win), #UIS_CLEAR, #UISF_HIDEFOCUS | #UISF_HIDEACCEL)

SetActiveGadget(btn2)

Repeat
  E = WaitWindowEvent()
Until E = #PB_Event_CloseWindow
User avatar
Demivec
Addict
Addict
Posts: 4281
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: PB 6.10 Beta 2/3: SetActiveGadget not working

Post by Demivec »

I believe the focus rectangle is shown when the keyboard is used, i.e using Tab.

You can test if the button has focus by using the keyboard and pressing Enter or Space to do the same as clicking it.
Fred
Administrator
Administrator
Posts: 18351
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: PB 6.10 Beta 2/3: SetActiveGadget not working

Post by Fred »

Works as expected on Ubuntu, can anybody else confirm ?
OBrien
User
User
Posts: 12
Joined: Fri Dec 22, 2023 10:37 pm

Re: PB 6.10 Beta 2/3: SetActiveGadget not working

Post by OBrien »

Okay, the Button is focused but is not focusring (focusring is not visible).
It's like Demivec said - i hove to bush an action key (space, enter) to see that the button is focused.
Post Reply