Page 1 of 1

PB 6.10 Beta 2/3: SetActiveGadget not working

Posted: Sun Feb 04, 2024 9:19 am
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

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

Posted: Sun Feb 04, 2024 10:13 am
by mk-soft
Your bug.

There are not an any gadget 'chk1'

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

Posted: Sun Feb 04, 2024 10:15 am
by Lord
chk1 <> btn1
chk1 <> btn2

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

Posted: Sun Feb 04, 2024 11:02 am
by infratec
Always use ...

Code: Select all

EnableExplicit
To deselect all Gadgets, you can use:

Code: Select all

SetActiveGadget(-1)

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

Posted: Sun Feb 04, 2024 2:50 pm
by OBrien
Sry,
SetActiveGadget(btn2)
Is not working for me.
Do you test this ?

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

Posted: Sun Feb 04, 2024 3:26 pm
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

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

Posted: Sun Feb 04, 2024 7:07 pm
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

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

Posted: Sun Feb 04, 2024 7:14 pm
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.

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

Posted: Sat Feb 10, 2024 10:42 am
by Fred
Works as expected on Ubuntu, can anybody else confirm ?

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

Posted: Thu Feb 15, 2024 8:43 am
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.