Ejemplo n.º 1
0
static void buildNumericPropertyUI(ComponentWeakPtr weak, ValueProperty<T>& property)
{
	std::vector<gluit::Component::Ptr> components;

	gluit::Label::Ptr propertyName = gluit::Component::create<gluit::Label>();
	propertyName->setText(property.getName());
	components.push_back(propertyName);

	unsigned int precision = std::numeric_limits<T>::is_integer ? 0 : 2;

	Constraint<T> constraint = property.getConstraint();
	if (std::fabs(constraint.max - constraint.min) > 10000) {
		gluit::Spinner::Ptr spinner = gluit::Component::create<gluit::Spinner>();
		spinner->setMinimum(constraint.min);
		spinner->setMaximum(constraint.max);
		spinner->setStepSize(constraint.step);
		spinner->setValue(property.getValue());
		spinner->setDisplayPrecision(precision);

		property.onValueChange.connect(
			typename PropertyEvent<T>::Signal::slot_type(&setSpinnerValue<T>, SpinnerWeakPtr(spinner), _1).track(spinner));
		spinner->onValueChange.connect(boost::bind(&setNumericPropertyValue<double, T> , boost::ref(property), _1));

		components.push_back(spinner);
	} else {
		gluit::Slider::Ptr slider = gluit::Component::create<gluit::Slider>();
		slider->setMinimum(constraint.min);
		slider->setMaximum(constraint.max);
		slider->setMinStepSize(constraint.step);
		slider->setValue(property.getValue());
		slider->setDisplayPrecision(precision);

		property.onValueChange.connect(
			typename PropertyEvent<T>::Signal::slot_type(&setSliderValue<T>, SliderWeakPtr(slider), _1).track(slider));
		slider->onValueChange.connect(boost::bind(&setNumericPropertyValue<double, T> , boost::ref(property), _1));

		components.push_back(slider);
	}

	gluit::invokeInEventLoop(boost::bind(&replaceContents, weak, components));
}
Ejemplo n.º 2
0
gluit::Component::Ptr createPropertyUI<ValueProperty<bool> >(ValueProperty<bool>& property)
{
	gluit::Component::Ptr panel = gluit::Component::create<gluit::Component>();
	panel->setLayout(boost::make_shared<gluit::VerticalLayout>());
	panel->setActive(property.isEnabled());

	gluit::Checkbox::Ptr propertyValue = gluit::Component::create<gluit::Checkbox>();
	propertyValue->setText(property.getName());
	propertyValue->setChecked(property.getValue());
	panel->add(propertyValue);

	property.onValueChange.connect(
		PropertyEvent<bool>::Signal::slot_type(&setCheckboxChecked, CheckboxWeakPtr(propertyValue), _1).track(propertyValue));
	propertyValue->onCheckChange.connect(boost::bind(&setPropertyValue<bool>, boost::ref(property), _1));

	property.onSelfChange.connect(
		Property::Signal::slot_type(&setComponentActive, ComponentWeakPtr(panel), boost::ref(property)).track(panel));

	return panel;
}