Using Group - cnjinhao/nana GitHub Wiki

Introduction

The group widget is usually used to organize a group of widgets for a certain purpose. It also inherently provides a feature to implement user selection.

User Selection

Selection in Radio Mode

#include <nana/gui.hpp>
#include <nana/gui/widgets/group.hpp>

int main()
{
	using namespace nana;

	form fm;
	group grp(fm);

	grp.caption("Group Example");
	grp.move(rectangle{ 10, 10, 200, 100 });

	grp.add_option("option one");
	grp.add_option("option two");
	grp.add_option("option three");

	fm.events().click([&grp]{
		auto pos = grp.option();
		//check if there is an option has been checked.
		if (grp.npos != pos)
		{

		}
	});

	fm.show();
	exec();
}

Organize Other Widgets

Organize other widgets

#include <nana/gui.hpp>
#include <nana/gui/widgets/label.hpp>
#include <nana/gui/widgets/spinbox.hpp>
#include <nana/gui/widgets/group.hpp>

int main()
{
	using namespace nana;

	form fm;
	group grp(fm);

	grp.move(rectangle{ 10, 10, 200, 70 });
	grp.caption("Rotate");
	grp.div("margin=10 arrange=[50%,50%] angle");

	//Create a label and a spinbox which are children of the group
	label lb(grp);
	lb.caption("Angle:");
	lb.text_align(align::left, align_v::center);

	spinbox spbox(grp);
	spbox.range(0.0, 359.0, 1.0);

	grp["angle"] << lb << spbox;
	grp.collocate();

	fm.show();
	exec();
}

Implement Above Example in Another Way

#include <nana/gui.hpp>
#include <nana/gui/widgets/label.hpp>
#include <nana/gui/widgets/spinbox.hpp>
#include <nana/gui/widgets/group.hpp>

int main()
{
	using namespace nana;

	form fm;
	group grp(fm);

	grp.move(rectangle{ 10, 10, 200, 70 });
	grp.caption("Rotate");
	grp.div("margin=10 <angle><angle_value>");

	grp.create_child<label>("angle")->caption("Angle:");
	grp.create_child<spinbox>("angle_value")->range(0.0, 359.0, 1.0);
	grp.collocate();

	fm.show();
	exec();
}
⚠️ **GitHub.com Fallback** ⚠️