MCPcopy Create free account
hub / github.com/AcademySoftwareFoundation/MaterialX / createFloatWidget

Function createFloatWidget

source/MaterialXView/Editor.cpp:753–813  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

751}
752
753ng::ref<ng::FloatBox<float>> createFloatWidget(ng::ref<ng::Widget> parent, const std::string& label, float value,
754 const mx::UIProperties* ui, std::function<void(float)> callback)
755{
756 new ng::Label(parent, label);
757
758 ng::ref<ng::Slider> slider = new ng::Slider(parent);
759 slider->set_value(value);
760
761 ng::ref<ng::FloatBox<float>> box = new ng::FloatBox<float>(parent, value);
762 box->set_fixed_width(60);
763 box->set_font_size(15);
764 box->set_alignment(ng::TextBox::Alignment::Right);
765
766 if (ui)
767 {
768 std::pair<float, float> range(0.0f, 1.0f);
769 if (ui->uiMin)
770 {
771 box->set_min_value(ui->uiMin->asA<float>());
772 range.first = ui->uiMin->asA<float>();
773 }
774 if (ui->uiMax)
775 {
776 box->set_max_value(ui->uiMax->asA<float>());
777 range.second = ui->uiMax->asA<float>();
778 }
779 if (ui->uiSoftMin)
780 {
781 range.first = ui->uiSoftMin->asA<float>();
782 }
783 if (ui->uiSoftMax)
784 {
785 range.second = ui->uiSoftMax->asA<float>();
786 }
787 if (range.first != range.second)
788 {
789 slider->set_range(range);
790 }
791 if (ui->uiStep)
792 {
793 box->set_value_increment(ui->uiStep->asA<float>());
794 box->set_spinnable(true);
795 box->set_editable(true);
796 }
797 }
798
799 auto sliderPtr = slider.get();
800 auto boxPtr = box.get();
801 slider->set_callback([boxPtr, callback](float value)
802 {
803 boxPtr->set_value(value);
804 callback(value);
805 });
806 box->set_callback([sliderPtr, callback](float value)
807 {
808 sliderPtr->set_value(value);
809 callback(value);
810 });

Callers 2

addItemToFormMethod · 0.85

Calls 2

set_valueMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected