Collapsible tree view working. separating out ClickOnly events for non-focusable stateful components
This commit is contained in:
parent
fec18486d8
commit
69407cd25b
3 changed files with 43 additions and 20 deletions
|
|
@ -32,7 +32,7 @@ inspector = config \
|
||||||
# totalHeight = (len sourceLines) * lineHeight,
|
# totalHeight = (len sourceLines) * lineHeight,
|
||||||
totalHeight = 1000,
|
totalHeight = 1000,
|
||||||
onScroll = _ \ noOp,
|
onScroll = _ \ noOp,
|
||||||
child = tree { value = reflected, depth = 0 },
|
child = tree { value = reflected, depth = 0, path = config.name },
|
||||||
# child = ui.column {
|
# child = ui.column {
|
||||||
# gap = 0,
|
# gap = 0,
|
||||||
# children = map (line \
|
# children = map (line \
|
||||||
|
|
|
||||||
|
|
@ -20,16 +20,34 @@ tree = config \
|
||||||
| ConstructorValue { tag = tag } \ simple tag "#fc6"
|
| ConstructorValue { tag = tag } \ simple tag "#fc6"
|
||||||
| FunctionValue _ \ simple "<fn>" "#888"
|
| FunctionValue _ \ simple "<fn>" "#888"
|
||||||
| RecordValue entries \
|
| RecordValue entries \
|
||||||
|
ui.stateful {
|
||||||
|
key = "tree-" & config.path,
|
||||||
|
init = { collapsed = True },
|
||||||
|
|
||||||
|
update = state event \ event
|
||||||
|
| Clicked _ \ (
|
||||||
|
_ = debug "clicked on node" [];
|
||||||
|
{ state = state.{ collapsed = (not state.collapsed) }, emit = [] }
|
||||||
|
)
|
||||||
|
| _ \ { state = state, emit = [] },
|
||||||
|
|
||||||
|
view = state \
|
||||||
ui.column {
|
ui.column {
|
||||||
gap = 0,
|
gap = 0,
|
||||||
children = map (entry \
|
children = [
|
||||||
|
simple ((state.collapsed | True \ "▶ " | False \ "▼ ") & (show (len entries)) & " fields") "#888",
|
||||||
|
...(state.collapsed
|
||||||
|
| True \ []
|
||||||
|
| False \ map (entry \
|
||||||
(valueLabel entry.value)
|
(valueLabel entry.value)
|
||||||
| Some label \ simple (entry.key & " = " & label) "#aaa"
|
| Some label \ simple (entry.key & " = " & label) "#aaa"
|
||||||
| None \ ui.column { gap = 0, children = [
|
| None \ ui.column { gap = 0, children = [
|
||||||
simple entry.key "#aaa",
|
simple entry.key "#aaa",
|
||||||
tree { value = entry.value, depth = depth + 1 }
|
tree { value = entry.value, depth = depth + 1, path = config.path & "." & entry.key }
|
||||||
]}
|
]}
|
||||||
) entries
|
) entries)
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
| ListValue items \
|
| ListValue items \
|
||||||
ui.column {
|
ui.column {
|
||||||
|
|
|
||||||
|
|
@ -93,15 +93,13 @@ export function runAppCompiled(canvas: HTMLCanvasElement, store: any) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const viewResult = instance.view(instance.state);
|
const viewResult = instance.view(instance.state);
|
||||||
let viewUI = viewResult;
|
const viewUI = {
|
||||||
|
|
||||||
if (ui.focusable) {
|
|
||||||
viewUI = {
|
|
||||||
kind: 'clickable',
|
kind: 'clickable',
|
||||||
child: viewUI,
|
child: viewResult,
|
||||||
onClick: (coords: any) => ({ _tag: 'FocusAndClick', _0: fullKey, _1: coords })
|
onClick: ui.focusable
|
||||||
|
? (coords: any) => ({ _tag: 'FocusAndClick', _0: fullKey, _1: coords })
|
||||||
|
: (coords: any) => ({ _tag: 'ClickOnly', _0: fullKey, _1: coords })
|
||||||
};
|
};
|
||||||
}
|
|
||||||
return expandStateful(viewUI, [...path, ui.key], renderedKeys);
|
return expandStateful(viewUI, [...path, ui.key], renderedKeys);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -191,6 +189,13 @@ export function runAppCompiled(canvas: HTMLCanvasElement, store: any) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (event._tag === 'ClickOnly') {
|
||||||
|
const componentKey = event._0;
|
||||||
|
const coords = event._1;
|
||||||
|
handleComponentEvent(componentKey, { _tag: 'Clicked', _0: coords });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (event._tag === 'Rebind') {
|
if (event._tag === 'Rebind') {
|
||||||
store.rebind(event._0, event._1, event._2);
|
store.rebind(event._0, event._1, event._2);
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue