MCPcopy Index your code
hub / github.com/cifertech/DisplayKit / addAssetElementToCanvas

Function addAssetElementToCanvas

app.js:3317–3369  ·  view source on GitHub ↗
(assetId)

Source from the content-addressed store, hash-verified

3315}
3316
3317function addAssetElementToCanvas(assetId) {
3318 const a = (assets || []).find((x) => x && x.id === assetId);
3319 if (!a) return;
3320 const w = a.width || 32;
3321 const h = a.height || 32;
3322 const x = Math.max(0, Math.round((dispWidth - w) / 2));
3323 const y = Math.max(0, Math.round((dispHeight - h) / 2));
3324 const id = makeId();
3325
3326 if (a.kind === "icon") {
3327 const el = createElementWithDefaults("icon", {
3328 id,
3329 x,
3330 y,
3331 w,
3332 h,
3333 assetId,
3334 iconSrc: a.dataUrl || "",
3335 imageName: `icon_${safeSymbolFromPath(a.sourceName || a.name || a.id)}_${id.replace(/[^a-zA-Z0-9_]/g, "_")}`,
3336 imageWidth: w,
3337 imageHeight: h,
3338 rgb565: a.rgb565 || undefined,
3339 monoBitmap: a.monoBitmap || undefined,
3340 });
3341 elements.push(el);
3342 } else {
3343 const el = createElementWithDefaults("image", {
3344 id,
3345 x,
3346 y,
3347 w,
3348 h,
3349 assetId,
3350 previewUrl: a.dataUrl || "",
3351 imageName: `img_${id.replace(/[^a-zA-Z0-9_]/g, "_")}`,
3352 imageWidth: w,
3353 imageHeight: h,
3354 rgb565: a.rgb565 || undefined,
3355 });
3356 elements.push(el);
3357 }
3358
3359 syncActiveScreenElements();
3360 selectedId = id;
3361 selectedIds = new Set([id]);
3362 updatePreviewSize();
3363 renderElements();
3364 renderLayers();
3365 updatePropsInputs();
3366 updateCode();
3367 pushHistory();
3368 setInspectorTab("selection");
3369}
3370
3371function deleteAsset(assetId) {
3372 if (!assetId) return;

Callers 1

renderAssetsFunction · 0.85

Calls 11

makeIdFunction · 0.85
safeSymbolFromPathFunction · 0.85
syncActiveScreenElementsFunction · 0.85
updatePreviewSizeFunction · 0.85
renderElementsFunction · 0.85
renderLayersFunction · 0.85
updatePropsInputsFunction · 0.85
updateCodeFunction · 0.85
pushHistoryFunction · 0.85
setInspectorTabFunction · 0.85

Tested by

no test coverage detected