To specify the type of SpinGadget value limits

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Dräc
Enthusiast
Enthusiast
Posts: 150
Joined: Sat Oct 09, 2004 12:10 am
Location: Toulouse (France)
Contact:

To specify the type of SpinGadget value limits

Post by Dräc »

Just to say that SpinGadget value limits is of Word type:

Code: Select all

  If OpenWindow(0, 0, 0, 140, 70, "SpinGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
    SpinGadget     (0, 20, 20, 100, 25, 0, 32767+1)
    SetGadgetState (0, 5) : SetGadgetText(0, "5")   ; set initial value
    Repeat
      Event = WaitWindowEvent()
      If Event = #PB_Event_Gadget
        If EventGadget() = 0
          SetGadgetText(0,Str(GetGadgetState(0)))
        EndIf
      EndIf
    Until Event = #PB_Event_CloseWindow
  EndIf
  
Is it possible to specify the type of this limits ?
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

you'l have to check the event, then react appropriately... this may point you in the right direction (i'm not using callbacks, just calling this routine whenever an event hits a spingadget)

Code: Select all

Procedure x_rollspingadget(gadgetnr.l,event.l,min.l,max.l)           ; simplify handling events on spingadgets
  Protected x.l
  ;
  ; in:        gadgetnr.l           - gadget number
  ;            event.l              - event retrieved from waitwindowevent()
  ;            min.l                - minimal value of spinner
  ;            max.l                - maximal value of spinner
  ; retval:
  ; out:
  ;
  ; when processing events, call this routine, and pass the necessary parameters, saves some typing
  ;
  If event = -1 Or event = 1
    SetGadgetText(gadgetnr,Str(GetGadgetState(gadgetnr)))
  Else
    x = Val(GetGadgetText(gadgetnr))
    If x < min Or x > max
      x = x_limit(x,min,max)
      SetGadgetText(gadgetnr,Str(x))
    EndIf
    SetGadgetState(gadgetnr,x)
  EndIf
EndProcedure
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Post Reply