Page 1 of 1

No #PB_EventType_Change for OptionGadget

Posted: Fri Apr 08, 2022 4:55 am
by jacdelad
Hello,
ist there a particular reason, why there's no #PB_EventType_Change for OptionGadgets? I searched Google and didn't find information about this being asked before, though it seems like a logical thing for me.

Re: No #PB_EventType_Change for OptionGadget

Posted: Fri Apr 08, 2022 5:12 am
by BarryG
I agree that a change event should occur when their status changes from on/off, but then the new gadget would be the EventGadget() and not the previous OptionGadget whose on/off state just changed. So it's probably not possible?

You have to detect it something like this:

Code: Select all

If OpenWindow(0, 300, 300, 140, 110, "OptionGadget", #PB_Window_SystemMenu)
  OptionGadget(0, 30, 20, 60, 20, "Option 1")
  OptionGadget(1, 30, 45, 60, 20, "Option 2")
  OptionGadget(2, 30, 70, 60, 20, "Option 3")
  SetGadgetState(1, 1)
  oldgad=-1
  Repeat
    ev=WaitWindowEvent()
    If ev=#PB_Event_Gadget
      newgad=EventGadget()
      If newgad<>oldgad
        oldgad=newgad
        If GadgetType(newgad)=#PB_GadgetType_Option
          Debug "changed"
        EndIf
      EndIf
    EndIf
  Until ev=#PB_Event_CloseWindow
EndIf

Re: No #PB_EventType_Change for OptionGadget

Posted: Fri Apr 08, 2022 5:41 am
by jacdelad
Well, a change would occur in the new gadget. The programmer has to take care of it anyway (and can get the status with GetGadgetState()). Also, only one OptionGadget of a group can be activated, so I store a value in a variable, which indicates which OptionGadget is activated. If the new one sends a Change-Message I overwrite the value and don't need to check the other gadgets anyway.