Cleaning
This commit is contained in:
parent
59dc90cfa5
commit
a39c80fc74
6 changed files with 9 additions and 76 deletions
36
src/ui.ts
36
src/ui.ts
|
|
@ -126,38 +126,6 @@ function renderUI(ui: UIValue, ctx: CanvasRenderingContext2D, x: number, y: numb
|
|||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 'text-input': {
|
||||
ctx.fillStyle = ui.value ? '#000000' : '#999999';
|
||||
ctx.font = '16px "SF Mono", "Monaco", "Menlo", "Consolas", "Courier New", monospace';
|
||||
ctx.fillText(
|
||||
ui.value || ui.placeholder,
|
||||
x + ui.x + 8,
|
||||
y + ui.y + ui.h / 2 + 6
|
||||
);
|
||||
|
||||
// Draw cursor
|
||||
if (ui.focused) {
|
||||
const textWidth = ctx.measureText(ui.value).width;
|
||||
ctx.fillStyle = '#000000';
|
||||
ctx.fillRect(x + ui.x + 8 + textWidth, y + ui.y + 8, 2, ui.h - 16);
|
||||
}
|
||||
|
||||
textInputRegions.push({
|
||||
x: x + ui.x,
|
||||
y: y + ui.y,
|
||||
width: ui.w,
|
||||
height: ui.h,
|
||||
inputConstructor: ui.onInput,
|
||||
submitConstructor: ui.onSubmit
|
||||
});
|
||||
|
||||
if (ui.focused && focusedInput && (ui.onInput as any).name === (focusedInput as any).name) {
|
||||
currentInputValue = ui.value;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -223,8 +191,8 @@ function measure(ui: UIValue): { width: number, height: number } {
|
|||
return { width: maxWidth, height: maxHeight };
|
||||
}
|
||||
|
||||
case 'text-input':
|
||||
return { width: ui.w, height: ui.h };
|
||||
case 'stateful':
|
||||
throw new Error('Stateful components cannot be measured');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue