Shown button gadget pushed

Everything else that doesn't fall into one of the other PB categories.
wcardoso
User
User
Posts: 80
Joined: Fri Apr 25, 2003 5:06 pm
Location: Uruguay

Shown button gadget pushed

Post by wcardoso »

Hi.
How can I make a button gadget to look pushed when I push it and change his look to unpushed when I push in other button ? ( like a toggle one but interlocked with another button).
The idea is to make a serie of buttons that act like radiobuttons.
Thanks to all in advance. :)
with love from Uruguay
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Post by GPI »

You mean radio-buttons/option-gadget?

Create the buttons withe the #pb_button_toggle flag. When you get a event, that one of this radio-buttons is pressed, you must release all the other buttons (with setgadgetstate(#button,#false))

GPI
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Shown button gadget pushed

Post by PB »

> The idea is to make a serie of buttons that act like radiobuttons

This is quick and dirty but should get you started:

Code: Select all

If OpenWindow(0,0,0,222,200,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"ButtonGadgets") And CreateGadgetList(WindowID(0)) 
  ButtonGadget(1, 10, 10, 60, 20, "Button1", #PB_Button_Toggle) 
  ButtonGadget(2, 10, 50, 60, 20, "Button2", #PB_Button_Toggle) 
  ButtonGadget(3, 10, 90, 60, 20, "Button3", #PB_Button_Toggle) 
  SetGadgetState(1,#TRUE) ; Push first button in.
  cur=1 ; Remember which gadget is currently pushed in.
  Repeat
    ev=WaitWindowEvent()
    If ev=#PB_Event_Gadget
      id=EventGadgetID()
      If id=cur ; Same gadget pressed, so push it back "in" again!
        SetGadgetState(cur,#TRUE)
      Else
        SetGadgetState(cur,#FALSE) ; Push old button "out".
        SetGadgetState(id,#TRUE) ; Push new button "in".
        cur=id ; Remember new button.
      EndIf
    EndIf
  Until ev=#PB_Event_CloseWindow 
EndIf
wcardoso
User
User
Posts: 80
Joined: Fri Apr 25, 2003 5:06 pm
Location: Uruguay

Post by wcardoso »

Thanks a lot friends !! :)
with love from Uruguay
ebs
Enthusiast
Enthusiast
Posts: 561
Joined: Fri Apr 25, 2003 11:08 pm

Post by ebs »

PB,

You don't need to "un-push" the current button, or "push" the new button in your example. The buttons will toggle from "pushed" to "not pushed" by themselves.

In other words:

Code: Select all

If OpenWindow(0,0,0,222,200,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"ButtonGadgets") And CreateGadgetList(WindowID(0))
  ButtonGadget(1, 10, 10, 60, 20, "Button1", #PB_Button_Toggle)
  ButtonGadget(2, 10, 50, 60, 20, "Button2", #PB_Button_Toggle)
  ButtonGadget(3, 10, 90, 60, 20, "Button3", #PB_Button_Toggle)
  SetGadgetState(1,#True) ; Push first button in.
  cur=1 ; Remember which gadget is currently pushed in.
  Repeat
    ev=WaitWindowEvent()
    If ev=#PB_Event_Gadget
      id=EventGadgetID()
      If id <> cur  ; <-- CHANGED IF STATEMENT HERE
        SetGadgetState(cur,#False) ; Push old button "out".
        ; REMOVED STATEMENT HERE
        cur=id ; Remember new button.
      EndIf
    EndIf
  Until ev=#PB_Event_CloseWindow
EndIf
Eric
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> The buttons will toggle from "pushed" to "not pushed" by themselves.

LOL, thanks for that -- I didn't even try it! :)
Post Reply