From f62fa6912202a3b4278d2be5ada20af7cde8e08f Mon Sep 17 00:00:00 2001 From: space-nuko <24979496+space-nuko@users.noreply.github.com> Date: Sat, 29 Apr 2023 11:42:16 -0700 Subject: [PATCH] Autogenerate layout from graph --- src/lib/components/ComfyUIPane.svelte | 51 ++---- src/lib/components/WidgetContainer.svelte | 168 ++++++++++++-------- src/lib/stores/layoutState.ts | 179 ++++++++++++++++++++-- src/lib/stores/uiState.ts | 2 +- src/lib/widgets/ComboWidget.svelte | 2 +- 5 files changed, 290 insertions(+), 112 deletions(-) diff --git a/src/lib/components/ComfyUIPane.svelte b/src/lib/components/ComfyUIPane.svelte index 29df71d..c06972d 100644 --- a/src/lib/components/ComfyUIPane.svelte +++ b/src/lib/components/ComfyUIPane.svelte @@ -10,9 +10,6 @@ export let app: ComfyApp; let dragConfigured: boolean = false; - export let dragItems: DragItem[][] = [] - - export let totalId = 0; // // function addUIForNewNode(node: LGraphNode, paneIndex?: number) { // if (!paneIndex) @@ -32,48 +29,32 @@ } export function restore(panels: SerializedPanes) { - const a: ContainerLayout = { - type: "container", - id: "0", - attrs: { - title: "root!", - direction: "horizontal" - } + const id = 0; + $layoutState.root = layoutState.addContainer(null, { direction: "horizontal", showTitle: false }); + const left = layoutState.addContainer($layoutState.root.id, { direction: "vertical", showTitle: false }); + const right = layoutState.addContainer($layoutState.root.id, { direction: "vertical", showTitle: false }); + + for (const node of app.lGraph.computeExecutionOrder(false, null)) { + layoutState.nodeAdded(node) } - $layoutState.root = a; - $layoutState.children[0] = [ - { - type: "widget", - id: "1", - nodeId: 7, - widgetName: "text", - attrs: { - - } - }, - { - type: "widget", - id: "2", - nodeId: 6, - widgetName: "text", - attrs: { - - } - }, - ] - $layoutState.children[1] = [] - $layoutState.children[2] = [] + console.warn($layoutState) }
- +
- diff --git a/src/lib/components/WidgetContainer.svelte b/src/lib/components/WidgetContainer.svelte index 6c70a56..ce554a1 100644 --- a/src/lib/components/WidgetContainer.svelte +++ b/src/lib/components/WidgetContainer.svelte @@ -1,8 +1,5 @@ -{#if container} - {@const node = container.node} +{#if container && children} {@const id = container.id} - - -
- {#each children.filter(item => item.id !== SHADOW_PLACEHOLDER_ITEM_ID) as item(item.id)} -
- - {#if item[SHADOW_ITEM_MARKER_PROPERTY_NAME]} -
- {/if} -
- {/each} -
- +
+ + {#if container.attrs.showTitle} + + {/if} +
+ {#each children.filter(item => item.id !== SHADOW_PLACEHOLDER_ITEM_ID) as item(item.id)} +
+ + {#if item[SHADOW_ITEM_MARKER_PROPERTY_NAME]} +
+ {/if} +
+ {/each} +
+ {#if $uiState.unlocked} +
+ {/if} + +
{:else if widget} - + {#if $uiState.unlocked} -
+
{/if} {/if} -