|
Re: Group Round buttons (radio buttons)
Quote:
|
Originally Posted by toaster
Hi
|
Hello and Welcome to GIDForums™ Frank.
Quote:
|
Originally Posted by toaster
What is the most efficient  way to implement a group of several round buttons (radio buttons) together such that if one is selected all the other round buttons are deselected?
Frank
|
Here is a small program that shows how to have 3 radio groups. The trick with radio buttons is to contain them in a group and set them all to radio. I also like to set the default button with setonly() or you get a radio group with nothing selected on startup.
The program was generated by fluid and then I just compacted it into a single file for ease of use.
// generated by Fast Light User Interface Designer (fluid) version 1.0107
#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Group.H>
#include <FL/Fl_Round_Button.H>
int main(int argc, char **argv) {
Fl_Double_Window* w;
{ Fl_Double_Window* o = new Fl_Double_Window(367, 198);
w = o;
{ Fl_Group* o = new Fl_Group(10, 10, 347, 73);
o->box(FL_DOWN_BOX);
{ Fl_Round_Button* o = new Fl_Round_Button(32, 20, 64, 15, "button");
o->type(102);
o->down_box(FL_ROUND_DOWN_BOX);
o->setonly();
}
{ Fl_Round_Button* o = new Fl_Round_Button(32, 45, 64, 15, "button");
o->type(102);
o->down_box(FL_ROUND_DOWN_BOX);
}
{ Fl_Round_Button* o = new Fl_Round_Button(106, 34, 64, 15, "button");
o->type(102);
o->down_box(FL_ROUND_DOWN_BOX);
}
{ Fl_Round_Button* o = new Fl_Round_Button(175, 20, 64, 15, "button");
o->type(102);
o->down_box(FL_ROUND_DOWN_BOX);
}
{ Fl_Round_Button* o = new Fl_Round_Button(175, 58, 64, 15, "button");
o->type(102);
o->down_box(FL_ROUND_DOWN_BOX);
}
{ Fl_Round_Button* o = new Fl_Round_Button(261, 34, 64, 15, "button");
o->type(102);
o->down_box(FL_ROUND_DOWN_BOX);
}
o->end();
}
{ Fl_Group* o = new Fl_Group(10, 93, 349, 93);
o->box(FL_DOWN_BOX);
{ Fl_Round_Button* o = new Fl_Round_Button(280, 103, 64, 20, "button");
o->type(102);
o->down_box(FL_ROUND_DOWN_BOX);
o->setonly();
}
{ Fl_Round_Button* o = new Fl_Round_Button(280, 133, 64, 15, "button");
o->type(102);
o->down_box(FL_ROUND_DOWN_BOX);
}
{ Fl_Round_Button* o = new Fl_Round_Button(280, 161, 64, 15, "button");
o->type(102);
o->down_box(FL_ROUND_DOWN_BOX);
}
{ Fl_Group* o = new Fl_Group(10, 93, 89, 93);
{ Fl_Round_Button* o = new Fl_Round_Button(20, 103, 64, 15, "button");
o->type(102);
o->down_box(FL_ROUND_DOWN_BOX);
o->setonly();
}
{ Fl_Round_Button* o = new Fl_Round_Button(20, 128, 64, 15, "button");
o->type(102);
o->down_box(FL_ROUND_DOWN_BOX);
}
{ Fl_Round_Button* o = new Fl_Round_Button(20, 152, 64, 15, "button");
o->type(102);
o->down_box(FL_ROUND_DOWN_BOX);
}
o->end();
}
o->end();
}
o->end();
}
w->show(argc, argv);
return Fl::run();
}
To compile that I ...
Code:
g++ -Wall radio_test.cxx `fltk-config --cxxflags --ldflags` -o RadioTest
Just in case you are interested, here is the fluid project file for the above.
Code:
# data file for the Fltk User Interface Designer (fluid)
version 1.0107
header_name {.h}
code_name {.cxx}
Function {} {open
} {
Fl_Window {} {open
xywh {510 123 367 198} type Double hide
} {
Fl_Group {} {open
xywh {10 10 347 73} box DOWN_BOX
} {
Fl_Round_Button {} {
label button
xywh {32 20 64 15} type Radio down_box ROUND_DOWN_BOX
code0 {o->setonly();}
}
Fl_Round_Button {} {
label button
xywh {32 45 64 15} type Radio down_box ROUND_DOWN_BOX
}
Fl_Round_Button {} {
label button
xywh {106 34 64 15} type Radio down_box ROUND_DOWN_BOX
}
Fl_Round_Button {} {
label button
xywh {175 20 64 15} type Radio down_box ROUND_DOWN_BOX
}
Fl_Round_Button {} {
label button
xywh {175 58 64 15} type Radio down_box ROUND_DOWN_BOX
}
Fl_Round_Button {} {
label button
xywh {261 34 64 15} type Radio down_box ROUND_DOWN_BOX
}
}
Fl_Group {} {open
xywh {10 93 349 93} box DOWN_BOX
} {
Fl_Round_Button {} {
label button
xywh {280 103 64 20} type Radio down_box ROUND_DOWN_BOX
code0 {o->setonly();}
}
Fl_Round_Button {} {
label button
xywh {280 133 64 15} type Radio down_box ROUND_DOWN_BOX
}
Fl_Round_Button {} {
label button
xywh {280 161 64 15} type Radio down_box ROUND_DOWN_BOX
}
Fl_Group {} {open
xywh {10 93 89 93}
} {
Fl_Round_Button {} {
label button selected
xywh {20 103 64 15} type Radio down_box ROUND_DOWN_BOX
code0 {o->setonly();}
}
Fl_Round_Button {} {
label button
xywh {20 128 64 15} type Radio down_box ROUND_DOWN_BOX
}
Fl_Round_Button {} {
label button
xywh {20 152 64 15} type Radio down_box ROUND_DOWN_BOX
}
}
}
}
}
HTH
Mark
__________________ "Opportunity is missed by most people because it comes dressed in overalls and looks like work."
--Thomas Alva Edison
"Those who would give up essential liberty to purchase a little temporary safety, deserve neither liberty nor safety."
--Benjamin Franklin
"A happy person is not a person in a certain set of circumstances, but rather a person with a certain set of attitudes."
--Hugh Downs
|