From eccc14a71454fa474a3e9edd18c74e21b130a494 Mon Sep 17 00:00:00 2001 From: Dustin Swan Date: Sat, 21 Feb 2026 22:40:40 -0700 Subject: [PATCH] Cleaning up os 'app' launching, apps always return a function that takes a size for their window --- src/cg/06-inspector.cg | 6 +++--- src/cg/06-pixelEditor.cg | 11 ++++++++--- src/cg/10-os.cg | 18 ++++++++++-------- src/runtime-js.ts | 5 ++--- 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/cg/06-inspector.cg b/src/cg/06-inspector.cg index c88b2a1..6220e54 100644 --- a/src/cg/06-inspector.cg +++ b/src/cg/06-inspector.cg @@ -1,4 +1,4 @@ -inspector = config \ +inspector = config \ size \ val = eval! config.name; reflected = val @@ -10,6 +10,6 @@ inspector = config \ tree { value = reflected, path = config.name, - w = config.w, - h = config.h - textInputHeight + w = size.w, + h = size.h - textInputHeight }; diff --git a/src/cg/06-pixelEditor.cg b/src/cg/06-pixelEditor.cg index bfaf7ca..8d14550 100644 --- a/src/cg/06-pixelEditor.cg +++ b/src/cg/06-pixelEditor.cg @@ -1,4 +1,7 @@ pixelEditor = config \ + c = config; + _ = debug! "pixEd config" c; + upArrow = state \ ( newRow = max 0 (state.selectedRow - 1); { state = state.{ selectedRow = newRow }, emit = [] }); @@ -24,7 +27,7 @@ pixelEditor = config \ | False \ [...state.map, { x = col, y = row }]; { state = state.{ map = newMap }, emit = [] }); - ui.stateful { + size \ ui.stateful { focusable = True, autoFocus = True, @@ -61,7 +64,7 @@ pixelEditor = config \ cellWidth = state.pixelWidth * state.zoomMultiplier; cellHeight = state.pixelHeight * state.zoomMultiplier; - ui.column { + grid = ui.column { children = map (rIdx \ ui.row { children = map (cIdx \ @@ -75,5 +78,7 @@ pixelEditor = config \ ) (range 0 state.pixelWidth) } ) (range 0 state.pixelHeight) - } + }; + + center size.w size.h grid }; diff --git a/src/cg/10-os.cg b/src/cg/10-os.cg index c7c5ca9..0ab1fcb 100644 --- a/src/cg/10-os.cg +++ b/src/cg/10-os.cg @@ -179,14 +179,16 @@ os = onSelect = input \ result = eval! input; result - | Defined name \ openOrFocus name (size \ inspector { name = name, w = size.w, h = size.h }) - - | Value v \ (isUI v - | True \ openOrFocus input (_ \ v) - | False \ (getSource input == "" - | True \ openOrFocus input (_ \ ui.text { content = show v, color = "white" }) - | False \ openOrFocus input (size \ inspector { name = input, w = size.w, h = size.h }))) - | Err msg \ (_ = debug! "Error" msg; noOp); + | Defined name \ openOrFocus name (inspector { name = name }) + + | Value v \ (isFunction v + | True \ openOrFocus input v + | False \ (isUI v + | True \ openOrFocus input (size \ v) + | False \ (getSource input == "" + | True \ openOrFocus input (_ \ ui.text { content = show v, color = "white" }) + | False \ openOrFocus input (inspector { name = input })))) + | Err msg \ (_ = debug! "Error" msg; noOp); handleFocusLeftEvent = state \ newIndex = max 0 (osState.wm.focusedIndex - 1); diff --git a/src/runtime-js.ts b/src/runtime-js.ts index 9b3c782..6f8ef3b 100644 --- a/src/runtime-js.ts +++ b/src/runtime-js.ts @@ -41,7 +41,7 @@ export const _rt = { clip: (config: any) => ({ kind: 'clip', ...config }), opacity: (config: any) => ({ kind: 'opacity', ...config }), stateful: (config: any) => ({ kind: 'stateful', ...config }), - measure: (config: any) => ({ kind: 'measure', ...config }), + measure: measure, measureText: (text: string) => { const canvas = document.createElement('canvas'); const ctx = canvas.getContext('2d'); @@ -53,8 +53,6 @@ export const _rt = { }, }, - measure: measure, - batch: (events: any[]) => ({ _tag: 'Batch', _0: events }), noOp: { _tag: 'NoOp' }, focus: (key: string) => ({ _tag: 'Focus', _0: key }), @@ -95,6 +93,7 @@ export const _rt = { hasField: (field: string) => (obj: any) => ({ _tag: (typeof obj === 'object' && obj !== null && field in obj) ? 'True' : 'False' }), + isFunction: (v: any) => ({ _tag: typeof v === 'function' ? 'True' : 'False' }), storeSearch: (query: string) => { return Object.keys(store) .filter(name => _rt.fuzzyMatch(query)(name)._tag === 'True')