forked from cnjinhao/nana-docs
-
Notifications
You must be signed in to change notification settings - Fork 6
Widget group
James Bremner edited this page Apr 5, 2019
·
1 revision
Here is a complete program to construct a frame and title around a group of radio buttons.
#include <nana/gui.hpp>
#include <nana/gui/widgets/checkbox.hpp>
#include <nana/gui/widgets/group.hpp>
int main()
{
nana::form fm;
// construct frame & title to be displayed on fm
// this must be done first, otherwise it hides the radiobuttons
nana::group title( fm );
// locate on fm
title.move( {10,10, 120, 130} );
// title
title.caption( "Group example");
/** match background color to frame
The default background color for group does not match the form or the the radiobuttons
The result is ugly, but this line makes things look better
*/
title.bgcolor( fm.bgcolor() );
// construct checkboxes to be displayed on fm
nana::checkbox rb1( fm );
nana::checkbox rb2( fm );
nana::checkbox rb3( fm );
// Convert checkboxes to radiobuttons by adding to radio_goup
nana::radio_group rg;
rg.add( rb1 );
rg.add( rb2 );
rg.add( rb3 );
// locate on fm
rb1.move({ 20,30, 100,25});
rb2.move({ 20,60, 100,25});
rb3.move({ 20,90, 100,25});
// captions
rb1.caption("Option 1");
rb2.caption("Option 2");
rb3.caption("Option 3");
fm.show();
nana::exec();
}
Note that you can place the radiobuttons inside the group widget. This is supposed to look after arrangement of the buttons and other things automatically. I prefer not to do this and keep control of everything in my code. The automatic code in the group is very complex and does not always do what is expected or wanted. If you have a large number of radiobuttons and need, for example, to arrange them in two columns then you will have to do the arranging outside the group code, so I recommend doing so for all cases, even simple ones like this example.