MCPcopy Create free account
hub / github.com/LibreSprite/LibreSprite / add

Method add

src/app/script/api/dialog_script.cpp:165–193  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

163 }
164
165 ScriptObject* add(const std::string& type, const std::string& id) {
166 auto dialog = this->dialog();
167 if (!dialog)
168 return nullptr;
169
170 if (type.empty() || get(id))
171 return nullptr;
172
173 auto cleanType = base::string_to_lower(type); // "lAbEl" -> "label"
174 auto unprefixedType = cleanType;
175 cleanType[0] = toupper(cleanType[0]); // "label" -> "Label"
176 cleanType += "WidgetScriptObject"; // "Label" -> "LabelWidgetScriptObject"
177
178 auto sobj = getEngine()->create(cleanType);
179 if (!sobj) {
180 return nullptr;
181 }
182
183 auto widget = sobj->handle<ui::Widget>();
184 if (!widget)
185 return nullptr;
186
187 dialog->add(widget);
188
189 auto cleanId = !id.empty() ? id : unprefixedType + std::to_string(m_nextWidgetId++);
190 sobj->set("id", cleanId);
191
192 return sobj;
193 }
194
195 uint32_t m_nextWidgetId = 0;
196};

Callers

nothing calls this directly

Calls 7

dialogMethod · 0.95
string_to_lowerFunction · 0.85
to_stringFunction · 0.85
getFunction · 0.50
emptyMethod · 0.45
createMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected