Dead code. cleaning up parse. allowing trailing commas. starting to work on the 'os' palette
This commit is contained in:
parent
a30d2217b8
commit
2d687b5d38
5 changed files with 77 additions and 112 deletions
70
src/ui.ts
70
src/ui.ts
|
|
@ -8,19 +8,7 @@ type ClickRegion = {
|
|||
event: Value;
|
||||
};
|
||||
|
||||
type TextInputRegion = {
|
||||
x: number;
|
||||
y: number;
|
||||
width: number;
|
||||
height: number;
|
||||
inputConstructor: Value;
|
||||
submitConstructor: Value;
|
||||
}
|
||||
|
||||
let clickRegions: ClickRegion[] = [];
|
||||
let textInputRegions: TextInputRegion[] = [];
|
||||
let focusedInput: Value | null = null;
|
||||
let focusedInputSubmit: Value | null = null;
|
||||
|
||||
export function render(ui: UIValue, canvas: HTMLCanvasElement) {
|
||||
const ctx = canvas.getContext('2d');
|
||||
|
|
@ -32,7 +20,6 @@ export function render(ui: UIValue, canvas: HTMLCanvasElement) {
|
|||
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
|
||||
|
||||
clickRegions = [];
|
||||
textInputRegions = [];
|
||||
renderUI(ui, ctx, 0, 0);
|
||||
}
|
||||
}
|
||||
|
|
@ -209,60 +196,3 @@ export function hitTest(x: number, y: number): { event: Value, relativeX: number
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
let currentInputValue: string = '';
|
||||
|
||||
export function hitTestTextInput(x: number, y: number): boolean {
|
||||
for (const region of textInputRegions) {
|
||||
if (x >= region.x && x < region.x + region.width &&
|
||||
y >= region.y && y < region.y + region.height) {
|
||||
focusedInput = region.inputConstructor;
|
||||
focusedInputSubmit = region.submitConstructor;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
focusedInput = null;
|
||||
focusedInputSubmit = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
export function getFocusedInput(): Value | null {
|
||||
return focusedInput;
|
||||
}
|
||||
|
||||
export function handleKeyboard(key: string): Value | null {
|
||||
if (!focusedInput) return null;
|
||||
|
||||
if (key === 'Enter') {
|
||||
if (!focusedInputSubmit) return null;
|
||||
return {
|
||||
kind: 'constructor',
|
||||
name: (focusedInputSubmit as any).name,
|
||||
args: [{ kind: 'string', value: currentInputValue }]
|
||||
};
|
||||
}
|
||||
|
||||
if (key === 'Backspace') {
|
||||
const newValue = currentInputValue.slice(0, -1);
|
||||
currentInputValue = newValue;
|
||||
return {
|
||||
kind: 'constructor',
|
||||
name: (focusedInput as any).name,
|
||||
args: [{ kind: 'string', value: newValue }]
|
||||
};
|
||||
}
|
||||
|
||||
// Character
|
||||
if (key.length === 1) {
|
||||
const newValue = currentInputValue + key;
|
||||
currentInputValue = newValue;
|
||||
return {
|
||||
kind: 'constructor',
|
||||
name: (focusedInput as any).name,
|
||||
args: [{ kind: 'string', value: newValue }]
|
||||
};
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue