From 9f5eb4b59d82d2427ba62dbbe0253866fcebc634 Mon Sep 17 00:00:00 2001 From: pythongosssss <125205205+pythongosssss@users.noreply.github.com> Date: Thu, 16 May 2024 13:17:29 +0100 Subject: [PATCH] Bottom menu wip --- web/scripts/app.js | 41 +++++++++++++++++------------- web/scripts/ui/components/popup.js | 11 ++++++++ web/scripts/ui/menu/index.js | 12 ++++++--- web/scripts/ui/menu/menu.css | 23 +++++++++++++++-- web/style.css | 1 + 5 files changed, 64 insertions(+), 24 deletions(-) diff --git a/web/scripts/app.js b/web/scripts/app.js index 628876120..4a80bb37f 100644 --- a/web/scripts/app.js +++ b/web/scripts/app.js @@ -55,11 +55,11 @@ export class ComfyApp { this.ui = new ComfyUI(this); this.logging = new ComfyLogging(this); this.workflowManager = new ComfyWorkflowManager(this); - this.menu = new ComfyAppMenu(this); this.bodyTop = $el("div.comfyui-body-top", { parent: document.body }); this.bodyLeft = $el("div.comfyui-body-left", { parent: document.body }); this.bodyRight = $el("div.comfyui-body-right", { parent: document.body }); - this.bodyBottom = $el("div.comfyui-body-bottom", { parent: document.body }); + this.bodyBottom = $el("div.comfyui-body-bottom", { parent: document.body }); + this.menu = new ComfyAppMenu(this); /** * List of extensions that are registered with the app @@ -1560,7 +1560,7 @@ export class ComfyApp { this.#addAfterConfigureHandler(); - const canvas = (this.canvas = new LGraphCanvas(canvasEl, this.graph)); + this.canvas = new LGraphCanvas(canvasEl, this.graph); this.ctx = canvasEl.getContext("2d"); LiteGraph.release_link_on_empty_shows_menu = true; @@ -1568,22 +1568,14 @@ export class ComfyApp { this.graph.start(); - function resizeCanvas() { - // Limit minimal scale to 1, see https://github.com/comfyanonymous/ComfyUI/pull/845 - const scale = Math.max(window.devicePixelRatio, 1); - - // Clear fixed width and height while calculating rect so it uses 100% instead - canvasEl.height = canvasEl.width = ""; - const { width, height } = canvasEl.getBoundingClientRect(); - canvasEl.width = Math.round(width * scale); - canvasEl.height = Math.round(height * scale); - canvasEl.getContext("2d").scale(scale, scale); - canvas.draw(true, true); - } - // Ensure the canvas fills the window - resizeCanvas(); - window.addEventListener("resize", resizeCanvas); + this.resizeCanvas(); + window.addEventListener("resize", () => this.resizeCanvas()); + const ro = new ResizeObserver(() => this.resizeCanvas()); + ro.observe(this.bodyTop); + ro.observe(this.bodyLeft); + ro.observe(this.bodyRight); + ro.observe(this.bodyBottom); await this.#invokeExtensionsAsync("init"); await this.registerNodes(); @@ -1632,6 +1624,19 @@ export class ComfyApp { await this.#invokeExtensionsAsync("setup"); } + resizeCanvas() { + // Limit minimal scale to 1, see https://github.com/comfyanonymous/ComfyUI/pull/845 + const scale = Math.max(window.devicePixelRatio, 1); + + // Clear fixed width and height while calculating rect so it uses 100% instead + this.canvasEl.height = this.canvasEl.width = ""; + const { width, height } = this.canvasEl.getBoundingClientRect(); + this.canvasEl.width = Math.round(width * scale); + this.canvasEl.height = Math.round(height * scale); + this.canvasEl.getContext("2d").scale(scale, scale); + this.canvas.draw(true, true); + } + /** * Registers nodes with the graph */ diff --git a/web/scripts/ui/components/popup.js b/web/scripts/ui/components/popup.js index e3631c200..ee59b35d9 100644 --- a/web/scripts/ui/components/popup.js +++ b/web/scripts/ui/components/popup.js @@ -102,6 +102,7 @@ export class ComfyPopup extends EventTarget { update = () => { const rect = this.target.getBoundingClientRect(); + this.element.style.setProperty("--bottom", "unset"); if (this.position === "absolute") { if (this.horizontal === "left") { this.element.style.setProperty("--left", rect.left + "px"); @@ -109,9 +110,19 @@ export class ComfyPopup extends EventTarget { this.element.style.setProperty("--left", rect.right - this.element.clientWidth + "px"); } this.element.style.setProperty("--top", rect.bottom + "px"); + this.element.style.setProperty("--limit", rect.bottom + "px"); } else { this.element.style.setProperty("--left", 0 + "px"); this.element.style.setProperty("--top", rect.height + "px"); + this.element.style.setProperty("--limit", rect.height + "px"); + } + + const thisRect = this.element.getBoundingClientRect(); + if (thisRect.height < 30) { + // Move up instead + this.element.style.setProperty("--top", "unset"); + this.element.style.setProperty("--bottom", rect.height + 5 + "px"); + this.element.style.setProperty("--limit", rect.height + 5 + "px"); } }; } diff --git a/web/scripts/ui/menu/index.js b/web/scripts/ui/menu/index.js index 5d5264a1a..adc807e6e 100644 --- a/web/scripts/ui/menu/index.js +++ b/web/scripts/ui/menu/index.js @@ -41,6 +41,7 @@ export class ComfyAppMenu { { primary: getSaveButton(), mode: "hover", + position: "absolute" }, getSaveButton("Save"), new ComfyButton({ @@ -133,19 +134,22 @@ export class ComfyAppMenu { showOnMobile(this.mobileMenuButton).element, ]); - document.body.prepend(this.element); - app.ui.settings.addSetting({ id: "Comfy.UseNewMenu", defaultValue: false, name: "[Beta] Use new menu and workflow management", - type: "boolean", + type: "combo", + options: ["Disabled", "Top", "Bottom"], onChange: async (v) => { if (v) { document.body.style.display = "grid"; app.ui.menuContainer.style.display = "none"; this.element.style.removeProperty("display"); - + if (v === "Bottom") { + app.bodyBottom.append(this.element); + } else { + app.bodyTop.prepend(this.element); + } this.calculateSizeBreak(); } else { document.body.style.removeProperty("display"); diff --git a/web/scripts/ui/menu/menu.css b/web/scripts/ui/menu/menu.css index 72db6967e..20eeab2cf 100644 --- a/web/scripts/ui/menu/menu.css +++ b/web/scripts/ui/menu/menu.css @@ -43,8 +43,9 @@ left: var(--left); right: var(--right); top: var(--top); + bottom: var(--bottom); z-index: 2000; - max-height: calc(100vh - var(--top) - 10px); + max-height: calc(100vh - var(--limit) - 10px); box-shadow: 3px 3px 5px 0px rgba(0, 0, 0, 0.3); } @@ -133,6 +134,8 @@ z-index: 1000; order: 0; grid-column: 1/-1; + overflow: auto; + max-height: 90vh; } .comfyui-menu>* { @@ -436,7 +439,7 @@ background-color: var(--content-bg); color: var(--content-fg); min-width: 170px; - min-height: 100px; + min-height: 435px; display: flex; flex-direction: column; align-items: center; @@ -622,6 +625,15 @@ width: 100%; } +.comfyui-body-bottom .lt-lg.comfyui-menu > .comfyui-menu-mobile-collapse { + order: -1; +} + +.comfyui-body-bottom .lt-lg.comfyui-menu > .comfyui-menu-button { + top: unset; + bottom: 4px; +} + .lt-lg.comfyui-menu > .comfyui-menu-mobile-collapse.comfyui-button-group { flex-wrap: wrap; } @@ -661,6 +673,10 @@ border-radius: 0; } +.lt-lg.comfyui-menu .comfyui-workflows-popup { + width: 100vw; +} + /** Small */ .lt-md .comfyui-workflows-button-inner { width: unset !important; @@ -679,4 +695,7 @@ } .lt-sm .comfyui-interrupt-button { margin-right: 45px; +} +.comfyui-body-bottom .lt-sm.comfyui-menu > .comfyui-menu-button{ + bottom: 41px; } \ No newline at end of file diff --git a/web/style.css b/web/style.css index ab6f4eb0e..8091a489f 100644 --- a/web/style.css +++ b/web/style.css @@ -63,6 +63,7 @@ body { width: 100%; height: 100%; order: 2; + grid-column: 1/-1; } .comfyui-body-right {