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

Method addItemToForm

source/MaterialXView/Editor.cpp:150–636  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

148}
149
150void PropertyEditor::addItemToForm(const mx::UIPropertyItem& item, const std::string& group,
151 ng::ref<ng::Widget> container, Viewer* viewer, bool editable)
152{
153 const mx::UIProperties& ui = item.ui;
154 mx::ValuePtr value = item.variable->getValue();
155 if (!value)
156 {
157 return;
158 }
159
160 std::string label = item.label;
161 const std::string& unit = item.variable->getUnit();
162 if (!unit.empty())
163 {
164 label += std::string(" (") + unit + std::string(")");
165 }
166 const std::string& path = item.variable->getPath();
167 const mx::StringVec& enumeration = ui.enumeration;
168 const std::vector<mx::ValuePtr> enumValues = ui.enumerationValues;
169
170 if (!group.empty())
171 {
172 ng::ref<ng::Widget> twoColumns = new ng::Widget(container);
173 twoColumns->set_layout(_gridLayout2);
174 ng::ref<ng::Label> groupLabel = new ng::Label(twoColumns, group);
175 groupLabel->set_font_size(20);
176 groupLabel->set_font("sans-bold");
177 new ng::Label(twoColumns, "");
178 }
179
180 // Integer input. Can map to a combo box if an enumeration
181 if (value->isA<int>())
182 {
183 const size_t INVALID_INDEX = std::numeric_limits<size_t>::max();
184 auto indexInEnumeration = [&value, &enumValues, &enumeration]()
185 {
186 size_t index = 0;
187 for (auto& enumValue : enumValues)
188 {
189 if (value->getValueString() == enumValue->getValueString())
190 {
191 return index;
192 }
193 index++;
194 }
195 index = 0;
196 for (auto& enumName : enumeration)
197 {
198 if (value->getValueString() == enumName)
199 {
200 return index;
201 }
202 index++;
203 }
204 return std::numeric_limits<size_t>::max(); // INVALID_INDEX;
205 };
206
207 // Create a combo box. The items are the enumerations in order.

Callers

nothing calls this directly

Calls 15

createValueFunction · 0.85
createFloatWidgetFunction · 0.85
Color3Function · 0.85
FilePathFunction · 0.85
set_valueMethod · 0.80
linearToSrgbMethod · 0.80
srgbToLinearMethod · 0.80
maxFunction · 0.50
getValueMethod · 0.45
emptyMethod · 0.45
getValueStringMethod · 0.45
getSelectedMaterialMethod · 0.45

Tested by

no test coverage detected