Add ratio shape icons to resolution UI
This commit is contained in:
+16
-6
@@ -71,6 +71,10 @@ style.textContent = `
|
||||
.dumas-res .chips { display:grid; grid-template-columns:repeat(3,minmax(0,1fr)); gap:3px; }
|
||||
.dumas-res button { min-height:25px; padding:2px 4px; border:1px solid #555; border-radius:4px; background:#1d1d1d; color:#ddd; cursor:pointer; font:inherit; }
|
||||
.dumas-res button.active { background:#b9573d; color:white; border-color:#ef8c6d; }
|
||||
.dumas-res .ratio-button { display:flex; align-items:center; justify-content:center; gap:5px; }
|
||||
.dumas-res .ratio-icon { display:inline-block; width:10px; height:10px; border:1px solid currentColor; border-radius:1px; opacity:.9; flex:0 0 auto; }
|
||||
.dumas-res .ratio-icon.tall { height:12px; width:8px; }
|
||||
.dumas-res .ratio-icon.wide { height:8px; width:13px; }
|
||||
.dumas-res .sizes { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:3px; max-height:154px; overflow:auto; }
|
||||
.dumas-res .size { min-height:31px; text-align:left; font-family:ui-monospace,monospace; line-height:1.15; }
|
||||
.dumas-res .size small { display:block; color:#999; font-size:9px; }
|
||||
@@ -93,8 +97,14 @@ function render(node, root) {
|
||||
const chips = document.createElement("div"); chips.className = "chips";
|
||||
[...RATIOS, "custom_ratio", "custom"].forEach((id) => {
|
||||
const button = document.createElement("button");
|
||||
button.textContent = id === "custom_ratio" ? "Custom Ratio" : id === "custom" ? "Custom Resolution" : id;
|
||||
button.className = (s.mode === "preset" && id === ratio) || (s.mode === id) ? "active" : "";
|
||||
button.className = `ratio-button ${(s.mode === "preset" && id === ratio) || (s.mode === id) ? "active" : ""}`;
|
||||
if (RATIOS.includes(id)) {
|
||||
const icon = document.createElement("span"); icon.className = "ratio-icon";
|
||||
const [rw, rh] = id.split(":").map(Number);
|
||||
if (rw / rh > 1.25) icon.classList.add("wide");
|
||||
else if (rw / rh < 0.8) icon.classList.add("tall");
|
||||
button.append(icon, document.createTextNode(id));
|
||||
} else button.textContent = id === "custom_ratio" ? "Custom Ratio" : "Custom Resolution";
|
||||
button.dataset.id = id; chips.append(button);
|
||||
});
|
||||
ratioSection.append(chips); root.append(ratioSection);
|
||||
@@ -133,11 +143,11 @@ function render(node, root) {
|
||||
function setup(node) {
|
||||
node.resizable = false;
|
||||
const root=document.createElement("div"); root.className="dumas-res";
|
||||
const widget=node.addDOMWidget("dumas_resolution_ui", "custom", root, {serialize:false, getValue:()=>read(node), setValue:()=>{}, getMinHeight:()=>430});
|
||||
const widget=node.addDOMWidget("dumas_resolution_ui", "custom", root, {serialize:false, getValue:()=>read(node), setValue:()=>{}, getMinHeight:()=>500});
|
||||
// Keep the LiteGraph frame at least as tall as the rendered controls.
|
||||
// The DOM widget otherwise keeps its old compact minimum and overhangs
|
||||
// the node even when the node itself is marked non-resizable.
|
||||
widget.computeLayoutSize=()=>({minHeight:430,minWidth:1});
|
||||
widget.computeLayoutSize=()=>({minHeight:500,minWidth:1});
|
||||
root.addEventListener("click", (event) => {
|
||||
const button=event.target.closest("button"); if (!button) return;
|
||||
const s=read(node), id=button.dataset.id;
|
||||
@@ -150,7 +160,7 @@ function setup(node) {
|
||||
render(node,root);
|
||||
});
|
||||
root.addEventListener("change", (event) => { const key=event.target.dataset.key; if(!key)return; const s=read(node), value=key==="batch" ? Math.max(1,Math.min(64,Number(event.target.value)||1)) : Math.max(1,Math.min(16384,Number(event.target.value)||1)); s[key]=value; if(s.mode==="custom") { s.w=snap(clamp(s.custom_w),s.snap); s.h=snap(clamp(s.custom_h),s.snap); } else if(s.mode==="custom_ratio") { [s.w,s.h]=ratioPair(s.w,s.custom_ratio_w,s.custom_ratio_h,s.snap); } write(node,s); render(node,root); });
|
||||
node._dumasResolutionRoot=root; node.size=[300,470]; queueMicrotask(()=>render(node,root));
|
||||
node._dumasResolutionRoot=root; node.size=[300,540]; queueMicrotask(()=>render(node,root));
|
||||
}
|
||||
|
||||
const originalGraphToPrompt=app.graphToPrompt?.bind(app);
|
||||
@@ -164,7 +174,7 @@ app.registerExtension({
|
||||
if(nodeData?.name!==CLASS)return;
|
||||
const oldConfigure=nodeType.prototype.onConfigure;
|
||||
nodeType.prototype.onConfigure=function(...args){const result=oldConfigure?.apply(this,args); if(this._dumasResolutionRoot)render(this,this._dumasResolutionRoot); return result;};
|
||||
nodeType.prototype.onResize=function(){this.size=[300,470];};
|
||||
nodeType.prototype.onResize=function(){this.size=[300,540];};
|
||||
},
|
||||
nodeCreated(node){if(node.comfyClass===CLASS)setup(node);},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user