Skip to content

The most powerful and modular diffusion model GUI, api and backend with a graph/nodes interface. The fastest local inference engine in the world.

Ability to hide menu Responsive setting screen Touch events for zooming/context menu

pythongosssss8a92ac212010
diff --git a/web/extensions/core/simpleTouchSupport.js b/web/extensions/core/simpleTouchSupport.js
new file mode 100644
index 000000000..041fc2c4c
--- /dev/null
+++ b/web/extensions/core/simpleTouchSupport.js
@@ -0,0 +1,102 @@
+import { app } from "../../scripts/app.js";
+
+let touchZooming;
+let touchCount = 0;
+
+app.registerExtension({
+ name: "Comfy.SimpleTouchSupport",
+ setup() {
+ let zoomPos;
+ let touchTime;
+ let lastTouch;
+
+ function getMultiTouchPos(e) {
+ return Math.hypot(e.touches[0].clientX - e.touches[1].clientX, e.touches[0].clientY - e.touches[1].clientY);
+ }
+
+ app.canvasEl.addEventListener(
+ "touchstart",
+ (e) => {
+ touchCount++;
+ lastTouch = null;
+ if (e.touches?.length === 1) {
+ // Store start time for press+hold for context menu
+ touchTime = new Date();
+ lastTouch = e.touches[0];
+ } else {
+ touchTime = null;
+ if (e.touches?.length === 2) {
+ // Store center pos for zoom
+ zoomPos = getMultiTouchPos(e);
+ app.canvas.pointer_is_down = false;
+ }
+ }
+ },
+ true
+ );
+
+ app.canvasEl.addEventListener("touchend", (e) => {
+ touchZooming = false;
+ touchCount = e.touches?.length ?? touchCount - 1;
+ if (touchTime && !e.touches?.length) {
+ if (new Date() - touchTime > 600) {
+ try {
+ // hack to get litegraph to use this event
+ e.constructor = CustomEvent;
+ } catch (error) {}
+ e.clientX = lastTouch.clientX;
+ e.clientY = lastTouch.clientY;
+
+ app.canvas.pointer_is_down = true;
+ app.canvas._mousedown_callback(e);
+ }
+ touchTime = null;
+ }
+ });
+
+ app.canvasEl.addEventListener(
+ "touchmove",
+ (e) => {
+ touchTime = null;
+ if (e.touches?.length === 2) {
+ app.canvas.pointer_is_down = false;
+ touchZooming = true;
+ LiteGraph.closeAllContextMenus();
+ app.canvas.search_box?.close();
+ const newZoomPos = getMultiTouchPos(e);
+
+ const midX = (e.touches[0].clientX + e.touches[1].clientX) / 2;
+ const midY = (e.touches[0].clientY + e.touches[1].clientY) / 2;
+
+ let scale = app.canvas.ds.scale;
+ const diff = zoomPos - newZoomPos;
+ if (diff > 0.5) {
+ scale *= 1 / 1.07;
+ } else if (diff < -0.5) {
+ scale *= 1.07;
+ }
+ app.canvas.ds.changeScale(scale, [midX, midY]);
+ app.canvas.setDirty(true, true);
+ zoomPos = newZoomPos;
+ }
+ },
+ true
+ );
+ },
+});
+
+const processMouseDown = LGraphCanvas.prototype.processMouseDown;
+LGraphCanvas.prototype.processMouseDown = function (e) {
+ if (touchZooming || touchCount) {
+ return;
+ }
+ return processMouseDown.apply(this, arguments);
+};
+
+const processMouseMove = LGraphCanvas.prototype.processMouseMove;
+LGraphCanvas.prototype.processMouseMove = function (e) {
+ if (touchZooming || touchCount > 1) {
+ return;
+ }
+ return processMouseMove.apply(this, arguments);
+};
diff --git a/web/scripts/ui.js b/web/scripts/ui.js
index d4835c6e4..5ca6214eb 100644
--- a/web/scripts/ui.js
+++ b/web/scripts/ui.js
@@ -394,18 +394,42 @@ export class ComfyUI {
}
});
- this.menuContainer = $el("div.comfy-menu", {parent: document.body}, [
- $el("div.drag-handle", {
+ this.menuHamburger = $el(
+ "div.comfy-menu-hamburger",
+ {
+ parent: document.body,
+ onclick: () => {
+ this.menuContainer.style.display = "block";
+ this.menuHamburger.style.display = "none";
+ },
+ },
+ [$el("div"), $el("div"), $el("div")]
+ );
+
+ this.menuContainer = $el("div.comfy-menu", { parent: document.body }, [
+ $el("div.drag-handle.comfy-menu-header", {
style: {
overflow: "hidden",
position: "relative",
width: "100%",
cursor: "default"
}
- }, [
+ }, [
$el("span.drag-handle"),
- $el("span", {$: (q) => (this.queueSize = q)}),
- $el("button.comfy-settings-btn", {textContent: "⚙️", onclick: () => this.settings.show()}),
+ $el("span.comfy-menu-queue-size", { $: (q) => (this.queueSize = q) }),
+ $el("div.comfy-menu-actions", [
+ $el("button.comfy-settings-btn", {
+ textContent: "⚙️",
+ onclick: () => this.settings.show(),
+ }),
+ $el("button.comfy-close-menu-btn", {
+ textContent: "\u00d7",
+ onclick: () => {
+ this.menuContainer.style.display = "none";
+ this.menuHamburger.style.display = "flex";
+ },
+ }),
+ ]),
]),
$el("button.comfy-queue-btn", {
id: "queue-button",
diff --git a/web/scripts/ui/settings.js b/web/scripts/ui/settings.js
index 1cdba5cfe..9e9d13af0 100644
--- a/web/scripts/ui/settings.js
+++ b/web/scripts/ui/settings.js
@@ -16,7 +16,17 @@ export class ComfySettingsDialog extends ComfyDialog {
},
[
$el("table.comfy-modal-content.comfy-table", [
- $el("caption", { textContent: "Settings" }),
+ $el(
+ "caption",
+ { textContent: "Settings" },
+ $el("button.comfy-btn", {
+ type: "button",
+ textContent: "\u00d7",
+ onclick: () => {
+ this.element.close();
+ },
+ })
+ ),
$el("tbody", { $: (tbody) => (this.textElement = tbody) }),
$el("button", {
type: "button",
diff --git a/web/style.css b/web/style.css
index 44ee60198..863840b28 100644
--- a/web/style.css
+++ b/web/style.css
@@ -82,6 +82,24 @@ body {
margin: 3px 3px 3px 4px;
}
+.comfy-menu-hamburger {
+ position: fixed;
+ top: 10px;
+ z-index: 9999;
+ right: 10px;
+ width: 30px;
+ display: none;
+ gap: 8px;
+ flex-direction: column;
+ cursor: pointer;
+}
+.comfy-menu-hamburger div {
+ height: 3px;
+ width: 100%;
+ border-radius: 20px;
+ background-color: white;
+}
+
.comfy-menu {
font-size: 15px;
position: absolute;
@@ -101,6 +119,44 @@ body {
box-shadow: 3px 3px 8px rgba(0, 0, 0, 0.4);
}
+.comfy-menu-header {
+ display: flex;
+}
+
+.comfy-menu-actions {
+ display: flex;
+ gap: 3px;
+ align-items: center;
+ height: 20px;
+ position: relative;
+ top: -1px;
+ font-size: 22px;
+}
+
+.comfy-menu .comfy-menu-actions button {
+ background-color: rgba(0, 0, 0, 0);
+ padding: 0;
+ border: none;
+ cursor: pointer;
+ font-size: inherit;
+}
+
+.comfy-menu .comfy-menu-actions .comfy-settings-btn {
+ font-size: 0.6em;
+}
+
+button.comfy-close-menu-btn {
+ font-size: 1em;
+ line-height: 12px;
+ color: #ccc;
+ position: relative;
+ top: -1px;
+}
+
+.comfy-menu-queue-size {
+ flex: auto;
+}
+
.comfy-menu button,
.comfy-modal button {
font-size: 20px;
@@ -121,7 +177,6 @@ body {
width: 100%;
}
-.comfy-toggle-switch,
.comfy-btn,
.comfy-menu > button,
.comfy-menu-btns button,
@@ -140,17 +195,11 @@ body {
.comfy-menu-btns button:hover,
.comfy-menu .comfy-list button:hover,
.comfy-modal button:hover,
-.comfy-settings-btn:hover {
+.comfy-menu-actions button:hover {
filter: brightness(1.2);
cursor: pointer;
}
-.comfy-menu span.drag-handle {
- position: absolute;
- top: 0;
- left: 0;
-}
-
span.drag-handle {
width: 10px;
height: 20px;
@@ -215,15 +264,6 @@ span.drag-handle::after {
font-size: 12px;
}
-button.comfy-settings-btn {
- background-color: rgba(0, 0, 0, 0);
- font-size: 12px;
- padding: 0;
- position: absolute;
- right: 0;
- border: none;
-}
-
button.comfy-queue-btn {
margin: 6px 0 !important;
}
@@ -269,7 +309,19 @@ button.comfy-queue-btn {
}
.comfy-menu span.drag-handle {
- visibility: hidden
+ display: none;
+ }
+
+ .comfy-menu-queue-size {
+ flex: unset;
+ }
+
+ .comfy-menu-header {
+ justify-content: space-between;
+ }
+ .comfy-menu-actions {
+ gap: 10px;
+ font-size: 28px;
}
}
@@ -320,7 +372,7 @@ dialog::backdrop {
text-align: right;
}
-#comfy-settings-dialog button {
+#comfy-settings-dialog tbody button, #comfy-settings-dialog table > button {
background-color: var(--bg-color);
border: 1px var(--border-color) solid;
border-radius: 0;
@@ -343,12 +395,33 @@ dialog::backdrop {
}
.comfy-table caption {
+ position: sticky;
+ top: 0;
background-color: var(--bg-color);
color: var(--input-text);
font-size: 1rem;
font-weight: bold;
padding: 8px;
text-align: center;
+ border-bottom: 1px solid var(--border-color);
+}
+
+.comfy-table caption .comfy-btn {
+ position: absolute;
+ top: -2px;
+ right: 0;
+ bottom: 0;
+ cursor: pointer;
+ border: none;
+ height: 100%;
+ border-radius: 0;
+ aspect-ratio: 1/1;
+ user-select: none;
+ font-size: 20px;
+}
+
+.comfy-table caption .comfy-btn:focus {
+ outline: none;
}
.comfy-table tr:nth-child(even) {
@@ -435,43 +508,6 @@ dialog::backdrop {
margin-left: 5px;
}
-.comfy-toggle-switch {
- border-width: 2px;
- display: flex;
- background-color: var(--comfy-input-bg);
- margin: 2px 0;
- white-space: nowrap;
-}
-
-.comfy-toggle-switch label {
- padding: 2px 0px 3px 6px;
- flex: auto;
- border-radius: 8px;
- align-items: center;
- display: flex;
- justify-content: center;
-}
-
-.comfy-toggle-switch label:first-child {
- border-top-left-radius: 8px;
- border-bottom-left-radius: 8px;
-}
-.comfy-toggle-switch label:last-child {
- border-top-right-radius: 8px;
- border-bottom-right-radius: 8px;
-}
-
-.comfy-toggle-switch .comfy-toggle-selected {
- background-color: var(--comfy-menu-bg);
-}
-
-#extraOptions {
- padding: 4px;
- background-color: var(--bg-color);
- margin-bottom: 4px;
- border-radius: 4px;
-}
-
/* Search box */
.litegraph.litesearchbox {
@@ -498,3 +534,21 @@ dialog::backdrop {
color: var(--input-text);
filter: brightness(50%);
}
+
+@media only screen and (max-width: 450px) {
+ #comfy-settings-dialog .comfy-table tbody {
+ display: grid;
+ }
+ #comfy-settings-dialog .comfy-table tr {
+ display: grid;
+ }
+ #comfy-settings-dialog tr > td:first-child {
+ text-align: center;
+ border-bottom: none;
+ padding-bottom: 0;
+ }
+ #comfy-settings-dialog tr > td:not(:first-child) {
+ text-align: center;
+ border-top: none;
+ }
+}
\ No newline at end of file