Page 1 of 1
Shown button gadget pushed
Posted: Tue Dec 02, 2003 3:36 pm
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.

Posted: Tue Dec 02, 2003 7:31 pm
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
Re: Shown button gadget pushed
Posted: Wed Dec 03, 2003 9:28 am
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
Posted: Wed Dec 03, 2003 11:24 am
by wcardoso
Thanks a lot friends !!

Posted: Wed Dec 03, 2003 5:09 pm
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
Posted: Thu Dec 04, 2003 12:45 am
by PB
> The buttons will toggle from "pushed" to "not pushed" by themselves.
LOL, thanks for that -- I didn't even try it!
