Adding measure to new compile code. Cleaning up debug

This commit is contained in:
Dustin Swan 2026-02-08 20:14:13 -07:00
parent 2cd5a609bb
commit cc9f5959d7
No known key found for this signature in database
GPG key ID: 30D46587E2100467
5 changed files with 63 additions and 20 deletions

View file

@ -33,7 +33,6 @@ export const _rt = {
storeSearch: (query: string) => {
const results: string[] = [];
const searchTerm = query.toLowerCase();
console.log("in storeSearch. query: ", searchTerm);
for (const name of Object.keys(store)) {
if (searchTerm === '' || name.toLowerCase().includes(searchTerm)) {
results.push(name);
@ -53,4 +52,62 @@ export const _rt = {
obj[path[path.length - 1]] = maybeValue;
}
},
measure: (ui: any): { width: number, height: number } => {
switch (ui._tag) {
case 'Rect': return { width: ui.w, height: ui.h };
case 'Text': return { width: ui.content.length * 10, height: 20 }; // TODO
case 'Clip': return { width: ui.w, height: ui.h };
case 'Row': {
let totalWidth = 0;
let maxHeight = 0;
for (const child of ui.children) {
const size = _rt.measure(child);
totalWidth += size.width;
maxHeight = Math.max(maxHeight, size.height);
}
totalWidth += ui.gap * (ui.children.length - 1);
return { width: totalWidth, height: maxHeight };
}
case 'Column': {
let totalHeight = 0;
let maxWidth = 0;
for (const child of ui.children) {
const size = _rt.measure(child);
totalHeight += size.height;
maxWidth = Math.max(maxWidth, size.width);
}
totalHeight += ui.gap * (ui.children.length - 1);
return { width: maxWidth, height: totalHeight };
}
case 'Padding': {
const childSize = _rt.measure(ui.child);
return {
width: childSize.width + ui.amount * 2,
height: childSize.height + ui.amount * 2,
}
}
case 'Stack': {
let maxWidth = 0;
let maxHeight = 0;
for (const child of ui.children) {
const size = _rt.measure(child);
maxWidth = Math.max(maxWidth, size.width);
maxHeight = Math.max(maxHeight, size.height);
}
return { width: maxWidth, height: maxHeight };
}
case 'Clickable':
case 'Opacity':
case 'Positioned':
return _rt.measure(ui.child);
default:
return { width: 0, height: 0 };
}
}
}