Skip to content

Commit

Permalink
fix space thingy
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisShank committed Dec 12, 2024
1 parent 497dc9d commit d7abdf7
Showing 1 changed file with 34 additions and 24 deletions.
58 changes: 34 additions & 24 deletions src/folk-space-projector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export class FolkSpaceProjector extends FolkBaseSet {
override firstUpdated(changedProperties: PropertyValues<this>): void {
super.firstUpdated(changedProperties);

this.#spreadsheet.style.setProperty('--cell-width', '50px');

this.#shape.appendChild(this.#spreadsheet);

this.renderRoot.append(this.#shape);
Expand All @@ -40,39 +42,43 @@ export class FolkSpaceProjector extends FolkBaseSet {
this.#spreadsheet.removeEventListener('propagate', this.#onPropagate);
}

#lock = false;

#onPropagate = (event: Event) => {
if (this.#lock) return;

const cell = event.target as FolkSpreadSheetCell;

const shape = this.sourceElements
.values()
.drop(cell.row)
.drop(cell.row - 1)
.find(() => true);

if (!(shape instanceof FolkShape)) return;

// infinite event loop
// switch (cell.column) {
// case 'A': {
// shape.x = cell.value;
// return;
// }
// case 'B': {
// shape.y = cell.value;
// return;
// }
// case 'C': {
// shape.width = cell.value;
// return;
// }
// case 'D': {
// shape.height = cell.value;
// return;
// }
// case 'E': {
// shape.rotation = cell.value;
// return;
// }
// }
// beware of infinite event loop
switch (cell.column) {
case 'A': {
shape.x = cell.value;
return;
}
case 'B': {
shape.y = cell.value;
return;
}
case 'C': {
shape.width = cell.value;
return;
}
case 'D': {
shape.height = cell.value;
return;
}
case 'E': {
shape.rotation = (cell.value * Math.PI) / 180;
return;
}
}
};

override update(changedProperties: PropertyValues<this>): void {
Expand All @@ -85,6 +91,7 @@ export class FolkSpaceProjector extends FolkBaseSet {

if (this.sourcesMap.size !== this.sourceElements.size) return;

this.#lock = true;
const rects = this.sourceRects;
for (let i = 0; i < rects.length; i += 1) {
const row = i + 1;
Expand All @@ -103,5 +110,8 @@ export class FolkSpaceProjector extends FolkBaseSet {
this.#spreadsheet.getCell('D', row)!.expression = Math.round(rect.height);
}
}
Promise.resolve().then(() => {
this.#lock = false;
});
}
}

0 comments on commit d7abdf7

Please sign in to comment.