mirror of
https://git.datalinker.icu/comfyanonymous/ComfyUI
synced 2026-11-21 22:07:07 +08:00
Support dynamic size breakpoints based on content
This commit is contained in:
parent
71725566ac
commit
37def7e40b
@ -16,7 +16,7 @@ const collapseOnMobile = (t) => {
|
|||||||
return t;
|
return t;
|
||||||
};
|
};
|
||||||
const showOnMobile = (t) => {
|
const showOnMobile = (t) => {
|
||||||
(t.element ?? t).classList.add("sm-show");
|
(t.element ?? t).classList.add("lt-lg-show");
|
||||||
return t;
|
return t;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -36,11 +36,8 @@ export class ComfyAppMenu {
|
|||||||
content: t,
|
content: t,
|
||||||
});
|
});
|
||||||
|
|
||||||
this.logo = $el("h1.comfyui-logo.sm-hide", { title: "ComfyUI" }, "ComfyUI");
|
this.logo = $el("h1.comfyui-logo.nlg-hide", { title: "ComfyUI" }, "ComfyUI");
|
||||||
this.element = $el("nav.comfyui-menu", { style: { display: "none" } }, [
|
this.saveButton = new ComfySplitButton(
|
||||||
this.logo,
|
|
||||||
this.workflows.element,
|
|
||||||
new ComfySplitButton(
|
|
||||||
{
|
{
|
||||||
primary: getSaveButton(),
|
primary: getSaveButton(),
|
||||||
mode: "hover",
|
mode: "hover",
|
||||||
@ -66,9 +63,8 @@ export class ComfyAppMenu {
|
|||||||
visibilitySetting: { id: "Comfy.DevMode", showValue: true },
|
visibilitySetting: { id: "Comfy.DevMode", showValue: true },
|
||||||
app,
|
app,
|
||||||
})
|
})
|
||||||
).element,
|
);
|
||||||
collapseOnMobile(
|
this.actionsGroup = new ComfyButtonGroup(
|
||||||
new ComfyButtonGroup(
|
|
||||||
new ComfyButton({
|
new ComfyButton({
|
||||||
icon: "refresh",
|
icon: "refresh",
|
||||||
content: "Refresh",
|
content: "Refresh",
|
||||||
@ -92,10 +88,8 @@ export class ComfyAppMenu {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
)
|
);
|
||||||
).element,
|
this.settingsGroup = new ComfyButtonGroup(
|
||||||
$el("section.comfyui-menu-push"),
|
|
||||||
collapseOnMobile(
|
|
||||||
new ComfyButton({
|
new ComfyButton({
|
||||||
icon: "cog",
|
icon: "cog",
|
||||||
content: "Settings",
|
content: "Settings",
|
||||||
@ -104,26 +98,33 @@ export class ComfyAppMenu {
|
|||||||
app.ui.settings.show();
|
app.ui.settings.show();
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
).element,
|
);
|
||||||
collapseOnMobile(
|
this.viewGroup = new ComfyButtonGroup(
|
||||||
new ComfyButtonGroup(
|
|
||||||
new ComfyViewHistoryButton(app).element,
|
new ComfyViewHistoryButton(app).element,
|
||||||
new ComfyViewQueueButton(app).element,
|
new ComfyViewQueueButton(app).element,
|
||||||
getInteruptButton("sm-hide").element
|
getInteruptButton("nlg-hide").element
|
||||||
)
|
);
|
||||||
).element,
|
this.mobileMenuButton = new ComfyButton({
|
||||||
|
|
||||||
getInteruptButton("sm-show").element,
|
|
||||||
new ComfyQueueButton(app).element,
|
|
||||||
showOnMobile(
|
|
||||||
new ComfyButton({
|
|
||||||
icon: "menu",
|
icon: "menu",
|
||||||
action: (_, btn) => {
|
action: (_, btn) => {
|
||||||
btn.icon = this.element.classList.toggle("expanded") ? "menu-open" : "menu";
|
btn.icon = this.element.classList.toggle("expanded") ? "menu-open" : "menu";
|
||||||
|
window.dispatchEvent(new Event("resize"));
|
||||||
},
|
},
|
||||||
classList: "comfyui-button comfyui-menu-button",
|
classList: "comfyui-button comfyui-menu-button",
|
||||||
})
|
});
|
||||||
).element,
|
|
||||||
|
this.element = $el("nav.comfyui-menu.lg", { style: { display: "none" } }, [
|
||||||
|
this.logo,
|
||||||
|
this.workflows.element,
|
||||||
|
this.saveButton.element,
|
||||||
|
collapseOnMobile(this.actionsGroup).element,
|
||||||
|
$el("section.comfyui-menu-push"),
|
||||||
|
collapseOnMobile(this.settingsGroup).element,
|
||||||
|
collapseOnMobile(this.viewGroup).element,
|
||||||
|
|
||||||
|
getInteruptButton("lt-lg-show").element,
|
||||||
|
new ComfyQueueButton(app).element,
|
||||||
|
showOnMobile(this.mobileMenuButton).element,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
document.body.prepend(this.element);
|
document.body.prepend(this.element);
|
||||||
@ -137,12 +138,100 @@ export class ComfyAppMenu {
|
|||||||
if (v) {
|
if (v) {
|
||||||
app.ui.menuContainer.style.display = "none";
|
app.ui.menuContainer.style.display = "none";
|
||||||
this.element.style.removeProperty("display");
|
this.element.style.removeProperty("display");
|
||||||
|
|
||||||
|
this.calculateSizeBreak();
|
||||||
} else {
|
} else {
|
||||||
app.ui.menuContainer.style.removeProperty("display");
|
app.ui.menuContainer.style.removeProperty("display");
|
||||||
this.element.style.display = "none";
|
this.element.style.display = "none";
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
window.addEventListener("resize", () => {
|
||||||
|
this.calculateSizeBreak();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#sizeBreak = "lg";
|
||||||
|
#lastSizeBreaks = {
|
||||||
|
lg: null,
|
||||||
|
md: null,
|
||||||
|
sm: null,
|
||||||
|
xs: null,
|
||||||
|
};
|
||||||
|
#sizeBreaks = Object.keys(this.#lastSizeBreaks);
|
||||||
|
#cachedInnerSize = null;
|
||||||
|
#cacheTimeout = null;
|
||||||
|
|
||||||
|
updateSizeBreak(idx, prevIdx, direction) {
|
||||||
|
const newSize = this.#sizeBreaks[idx];
|
||||||
|
if (newSize === this.#sizeBreak) return;
|
||||||
|
this.#cachedInnerSize = null;
|
||||||
|
clearTimeout(this.#cacheTimeout);
|
||||||
|
|
||||||
|
this.#sizeBreak = this.#sizeBreaks[idx];
|
||||||
|
for (let i = 0; i < this.#sizeBreaks.length; i++) {
|
||||||
|
const sz = this.#sizeBreaks[i];
|
||||||
|
if (sz === this.#sizeBreak) {
|
||||||
|
this.element.classList.add(sz);
|
||||||
|
} else {
|
||||||
|
this.element.classList.remove(sz);
|
||||||
|
}
|
||||||
|
if (i < idx) {
|
||||||
|
this.element.classList.add("lt-" + sz);
|
||||||
|
} else {
|
||||||
|
this.element.classList.remove("lt-" + sz);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Allow multiple updates, but prevent bouncing
|
||||||
|
if (!direction) {
|
||||||
|
direction = prevIdx - idx;
|
||||||
|
} else if (direction != prevIdx - idx) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.calculateSizeBreak(direction);
|
||||||
|
}
|
||||||
|
|
||||||
|
calculateSizeBreak(direction = 0) {
|
||||||
|
let idx = this.#sizeBreaks.indexOf(this.#sizeBreak);
|
||||||
|
const currIdx = idx;
|
||||||
|
const innerSize = this.calculateInnerSize(idx);
|
||||||
|
if (window.innerWidth >= this.#lastSizeBreaks[this.#sizeBreaks[idx - 1]]) {
|
||||||
|
if (idx > 0) {
|
||||||
|
idx--;
|
||||||
|
}
|
||||||
|
} else if (innerSize > this.element.clientWidth) {
|
||||||
|
this.#lastSizeBreaks[this.#sizeBreak] = Math.max(window.innerWidth, innerSize);
|
||||||
|
// We need to shrink
|
||||||
|
if (idx < this.#sizeBreaks.length - 1) {
|
||||||
|
idx++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.updateSizeBreak(idx, currIdx, direction);
|
||||||
|
}
|
||||||
|
|
||||||
|
calculateInnerSize(idx) {
|
||||||
|
// Cache the inner size to prevent too much calculation when resizing the window
|
||||||
|
clearTimeout(this.#cacheTimeout);
|
||||||
|
if (this.#cachedInnerSize) {
|
||||||
|
// Extend cache time
|
||||||
|
this.#cacheTimeout = setTimeout(() => (this.#cachedInnerSize = null), 100);
|
||||||
|
} else {
|
||||||
|
let innerSize = 0;
|
||||||
|
let count = 1;
|
||||||
|
for (const c of this.element.children) {
|
||||||
|
if (c.classList.contains("comfyui-menu-push")) continue; // ignore right push
|
||||||
|
if (idx && c.classList.contains("comfyui-menu-mobile-collapse")) continue; // ignore collapse items
|
||||||
|
innerSize += c.clientWidth;
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
innerSize += 8 * count;
|
||||||
|
this.#cachedInnerSize = innerSize;
|
||||||
|
this.#cacheTimeout = setTimeout(() => (this.#cachedInnerSize = null), 100);
|
||||||
|
}
|
||||||
|
return this.#cachedInnerSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -1,16 +1,3 @@
|
|||||||
/* Utilities */
|
|
||||||
@media only screen and (max-width: 779px) {
|
|
||||||
.sm-hide {
|
|
||||||
display: none !important;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@media only screen and (min-width: 780px) {
|
|
||||||
.sm-show {
|
|
||||||
display: none !important;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.relative {
|
.relative {
|
||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
@ -136,11 +123,14 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
padding: 4px 8px;
|
padding: 4px 8px;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: 0.8em;
|
gap: 8px;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
z-index: 1000;
|
z-index: 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.comfyui-menu>* {
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
.comfyui-menu .mdi::before {
|
.comfyui-menu .mdi::before {
|
||||||
font-size: 18px;
|
font-size: 18px;
|
||||||
}
|
}
|
||||||
@ -173,6 +163,7 @@
|
|||||||
.comfyui-menu .comfyui-button.popup-open {
|
.comfyui-menu .comfyui-button.popup-open {
|
||||||
background-color: var(--border-color);
|
background-color: var(--border-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
.comfyui-menu-push {
|
.comfyui-menu-push {
|
||||||
margin-left: -0.8em;
|
margin-left: -0.8em;
|
||||||
flex: auto;
|
flex: auto;
|
||||||
@ -185,92 +176,6 @@
|
|||||||
cursor: default;
|
cursor: default;
|
||||||
}
|
}
|
||||||
|
|
||||||
@media only screen and (min-width: 780px) {
|
|
||||||
.comfyui-menu > .comfyui-menu-mobile-collapse .comfyui-button span,
|
|
||||||
.comfyui-menu > .comfyui-menu-mobile-collapse.comfyui-button span {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
.comfyui-menu > .comfyui-menu-mobile-collapse .comfyui-popup .comfyui-button span {
|
|
||||||
display: unset;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@media only screen and (max-width: 779px) {
|
|
||||||
.comfyui-menu {
|
|
||||||
flex-wrap: wrap;
|
|
||||||
}
|
|
||||||
|
|
||||||
.comfyui-menu > *:not(.comfyui-menu-mobile-collapse) {
|
|
||||||
order: 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
.comfyui-menu > .comfyui-menu-mobile-collapse {
|
|
||||||
order: 9999;
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.comfyui-menu > .comfyui-menu-mobile-collapse.comfyui-button-group {
|
|
||||||
flex-wrap: wrap;
|
|
||||||
}
|
|
||||||
|
|
||||||
.comfyui-menu > .comfyui-menu-mobile-collapse .comfyui-button,
|
|
||||||
.comfyui-menu > .comfyui-menu-mobile-collapse.comfyui-button {
|
|
||||||
padding: 10px;
|
|
||||||
}
|
|
||||||
.comfyui-menu > .comfyui-menu-mobile-collapse .comfyui-button,
|
|
||||||
.comfyui-menu > .comfyui-menu-mobile-collapse .comfyui-button-wrapper {
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.comfyui-menu > .comfyui-menu-mobile-collapse .comfyui-popup {
|
|
||||||
position: static;
|
|
||||||
background-color: var(--comfy-input-bg);
|
|
||||||
max-width: unset;
|
|
||||||
max-height: 50vh;
|
|
||||||
overflow: auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
.comfyui-menu:not(.expanded) > .comfyui-menu-mobile-collapse {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.comfyui-queue-button {
|
|
||||||
margin-right: 44px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.comfyui-menu-button {
|
|
||||||
position: absolute;
|
|
||||||
top: 4px;
|
|
||||||
right: 8px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.comfyui-menu > .comfyui-menu-mobile-collapse .comfyui-view-list-popup {
|
|
||||||
border-radius: 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@media only screen and (max-width: 520px) {
|
|
||||||
.comfyui-workflows-button-inner {
|
|
||||||
width: unset !important;
|
|
||||||
}
|
|
||||||
.comfyui-workflows-label {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@media only screen and (max-width: 370px) {
|
|
||||||
.comfyui-queue-button {
|
|
||||||
margin-right: 0;
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
.comfyui-queue-button .comfyui-button {
|
|
||||||
justify-content: center;
|
|
||||||
}
|
|
||||||
.comfyui-interrupt-button {
|
|
||||||
margin-right: 45px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Workflows */
|
/* Workflows */
|
||||||
.comfyui-workflows-button {
|
.comfyui-workflows-button {
|
||||||
flex-direction: row-reverse;
|
flex-direction: row-reverse;
|
||||||
@ -638,3 +543,92 @@
|
|||||||
.comfy-modal .comfy-widget-selection-item button {
|
.comfy-modal .comfy-widget-selection-item button {
|
||||||
font-size: 1em;
|
font-size: 1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/***** Responsive *****/
|
||||||
|
.lg.comfyui-menu .lt-lg-show {
|
||||||
|
display: none !important;
|
||||||
|
}
|
||||||
|
.comfyui-menu:not(.lg) .nlg-hide {
|
||||||
|
display: none !important;
|
||||||
|
}
|
||||||
|
/** Large screen */
|
||||||
|
.lg.comfyui-menu>.comfyui-menu-mobile-collapse .comfyui-button span,
|
||||||
|
.lg.comfyui-menu>.comfyui-menu-mobile-collapse.comfyui-button span {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
.lg.comfyui-menu>.comfyui-menu-mobile-collapse .comfyui-popup .comfyui-button span {
|
||||||
|
display: unset;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Non large screen */
|
||||||
|
.lt-lg.comfyui-menu {
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lt-lg.comfyui-menu > *:not(.comfyui-menu-mobile-collapse) {
|
||||||
|
order: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lt-lg.comfyui-menu > .comfyui-menu-mobile-collapse {
|
||||||
|
order: 9999;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lt-lg.comfyui-menu > .comfyui-menu-mobile-collapse.comfyui-button-group {
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lt-lg.comfyui-menu > .comfyui-menu-mobile-collapse .comfyui-button,
|
||||||
|
.lt-lg.comfyui-menu > .comfyui-menu-mobile-collapse.comfyui-button {
|
||||||
|
padding: 10px;
|
||||||
|
}
|
||||||
|
.lt-lg.comfyui-menu > .comfyui-menu-mobile-collapse .comfyui-button,
|
||||||
|
.lt-lg.comfyui-menu > .comfyui-menu-mobile-collapse .comfyui-button-wrapper {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lt-lg.comfyui-menu > .comfyui-menu-mobile-collapse .comfyui-popup {
|
||||||
|
position: static;
|
||||||
|
background-color: var(--comfy-input-bg);
|
||||||
|
max-width: unset;
|
||||||
|
max-height: 50vh;
|
||||||
|
overflow: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lt-lg.comfyui-menu:not(.expanded) > .comfyui-menu-mobile-collapse {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lt-lg .comfyui-queue-button {
|
||||||
|
margin-right: 44px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lt-lg .comfyui-menu-button {
|
||||||
|
position: absolute;
|
||||||
|
top: 4px;
|
||||||
|
right: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lt-lg.comfyui-menu > .comfyui-menu-mobile-collapse .comfyui-view-list-popup {
|
||||||
|
border-radius: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Small */
|
||||||
|
.lt-md .comfyui-workflows-button-inner {
|
||||||
|
width: unset !important;
|
||||||
|
}
|
||||||
|
.lt-md .comfyui-workflows-label {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Extra small */
|
||||||
|
.lt-sm .comfyui-queue-button {
|
||||||
|
margin-right: 0;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
.lt-sm .comfyui-queue-button .comfyui-button {
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
.lt-sm .comfyui-interrupt-button {
|
||||||
|
margin-right: 45px;
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user