Page 1 of 1

SpinGadget

Posted: Sun Oct 19, 2025 6:09 pm
by Realizimo
hello!
Is it possible to only visit the routine "test()" once for each click instead of twice.
And is it possible to make the blue background behind the numbers to disappear.

Code: Select all

OpenWindow(0, 0, 0, 140, 70, "SpinGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
#spin=1
SpinGadget     (#spin, 20, 20, 100, 25, 0, 1000, #PB_Spin_Numeric)
SetGadgetState (#spin, 555) 

Procedure test()
  Debug GetGadgetState(#spin)
EndProcedure

BindGadgetEvent(#spin, @test())

Repeat
  Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow

Re: SpinGadget

Posted: Sun Oct 19, 2025 6:26 pm
by RASHAD
Hi

Code: Select all

OpenWindow(0, 0, 0, 140, 70, "SpinGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
#spin=1
SpinGadget     (#spin, 20, 20, 100, 25, 0, 1000, #PB_Spin_Numeric)
SetGadgetState (#spin, 555) 

Procedure test()
  Debug GetGadgetState(#spin)
  SetActiveGadget(-1)
EndProcedure

BindGadgetEvent(#spin, @test(),#PB_EventType_Change)

Repeat
  Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow

Re: SpinGadget

Posted: Sun Oct 19, 2025 6:31 pm
by Realizimo
wonderfully

Re: SpinGadget

Posted: Sun Oct 19, 2025 6:35 pm
by ChrisR
Same as Rashad, while maintaining focus when entering the number

Code: Select all

OpenWindow(0, 0, 0, 140, 70, "SpinGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
#spin=1
SpinGadget     (#spin, 20, 20, 100, 25, 0, 1000, #PB_Spin_Numeric)
SetGadgetState (#spin, 555) 

Procedure test()
  If EventType() = #PB_EventType_Change
    Debug GetGadgetState(#spin)
  Else
    SetActiveGadget(-1)
  EndIf
EndProcedure

BindGadgetEvent(#spin, @test())

Repeat
  Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow

Re: SpinGadget

Posted: Tue Oct 21, 2025 4:34 pm
by Realizimo
Is this the best way if I want to use the arrow keys?

Code: Select all

#win=1
#spin1=1
#spin2=2
OpenWindow(#win, 0, 0, 140, 120, "SpinGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

SpinGadget     (#spin1, 20, 20, 100, 25, 0, 1000,#PB_Spin_Numeric)
SpinGadget     (#spin2, 20, 60, 100, 25, 0, 1000,#PB_Spin_Numeric)
SetGadgetState (#spin1, 555)
SetGadgetState (#spin2, 555) 
AddKeyboardShortcut(#win,#PB_Shortcut_Down,1)
AddKeyboardShortcut(#win,#PB_Shortcut_Up,3)

Global prevgad=1
Procedure test()
  If EventType() = #PB_EventType_Change
    prevgad=EventGadget()
    Debug GetGadgetState(prevgad)
  Else : SetActiveGadget(-1)
  EndIf
EndProcedure

Procedure key()
  If GetActiveGadget()>-1:prevgad=GetActiveGadget():EndIf
  SetGadgetState(prevgad, GetGadgetState(prevgad)+EventMenu()-2)
  PostEvent(#PB_Event_Gadget,#win,prevgad,#PB_EventType_Change)
EndProcedure

BindGadgetEvent(#spin1, @test())
BindGadgetEvent(#spin2, @test())
BindEvent(#PB_Event_Menu, @key(),#win,1)
BindEvent(#PB_Event_Menu, @key(),#win,3)

Repeat
  Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow

Re: SpinGadget

Posted: Tue Oct 21, 2025 5:21 pm
by Mindphazer
I'd say yes, but :
This is much simpler

Code: Select all

#win=1
#spin1=1
#spin2=2
OpenWindow(#win, 0, 0, 140, 120, "SpinGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

SpinGadget     (#spin1, 20, 20, 100, 25, 0, 1000,#PB_Spin_Numeric)
SpinGadget     (#spin2, 20, 60, 100, 25, 0, 1000,#PB_Spin_Numeric)
SetGadgetState (#spin1, 555)
SetGadgetState (#spin2, 555) 
AddKeyboardShortcut(#win,#PB_Shortcut_Down,1)
AddKeyboardShortcut(#win,#PB_Shortcut_Up,3)


Procedure key()

  Gadget = GetActiveGadget()
  If Gadget <> -1
    Select EventMenu()
      Case 1
        SetGadgetState(Gadget, GetGadgetState(Gadget) - 1)
      Case 3
        SetGadgetState(Gadget, GetGadgetState(Gadget) + 1)
    EndSelect
    
  EndIf
  
EndProcedure

BindEvent(#PB_Event_Menu, @key(),#win,1)
BindEvent(#PB_Event_Menu, @key(),#win,3)

Repeat
  Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
And only the gadget which has the focus is modified