Skip to content

combine "show-all" and "hide-all" buttons #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 48 additions & 1 deletion gligen_gui/static/js/extra.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,51 @@ function getPort() {
return split[2];
}
console.log(currentUrl.pathname);
}
}

// Toggle boxes
function toggleBoxes(button) {
let icon_button_eye;
let buttonText;

let allHidden = false;

if (State.boxMap.size === 0) {
console.error("Box map is empty.");
return;
}

// Intialize button text based on the current state
buttonText = allHidden ? "Show All" : "Hide All";
button.textContent = buttonText;

State.boxMap.forEach((box) => {
if (!box.hide) {
allHidden = true;
return;
}
});

// Toggle the hide property of each box
State.boxMap.forEach((box, box_id) => {
box.hide = !box.hide;

icon_button_eye = document.getElementById(`eye-button-${box_id}`);
if (box.hide) {
icon_button_eye.src = "/static/images/eye-off.svg";
icon_button_eye.style.opacity = "0.5";
} else {
icon_button_eye.src = "/static/images/eye-on.svg";
icon_button_eye.style.opacity = "1";
}
});

clearCanvas("canvas_main");

// Redraw the boxes to reflect the updated visibility state
drawBoxes();

// Update button text based on the current state
buttonText = allHidden ? "Show All" : "Hide All";
button.textContent = buttonText;
}
23 changes: 2 additions & 21 deletions gligen_gui/static/js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -735,27 +735,8 @@ window.addEventListener("load", () => {

document.getElementById("add-lora").addEventListener("click", addLora);

document.getElementById("show-all").addEventListener("click", (event) => {
let icon_button_eye;
State.boxMap.forEach((box, box_id, map) => {
box.hide = false;
icon_button_eye = document.getElementById(`eye-button-${box_id}`);
icon_button_eye.src = "/static/images/eye-on.svg";
icon_button_eye.style.opacity = "1";
});
clearCanvas("canvas_main");
drawBoxes();
});

document.getElementById("hide-all").addEventListener("click", (event) => {
let icon_button_eye;
State.boxMap.forEach((box, box_id, map) => {
box.hide = true;
icon_button_eye = document.getElementById(`eye-button-${box_id}`);
icon_button_eye.src = "/static/images/eye-off.svg";
icon_button_eye.style.opacity = "0.5";
});
clearCanvas("canvas_main");
document.getElementById("toggle-all").addEventListener("click", (event) => {
toggleBoxes(document.getElementById("toggle-all"));
});

document.getElementById("delete-all").addEventListener("click", (event) => {
Expand Down
3 changes: 1 addition & 2 deletions gligen_gui/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,7 @@
></div> -->
</div>
<div class="row button-row button-row--left">
<button id="show-all">SHOW ALL</button>
<button id="hide-all">HIDE ALL</button>
<button id="toggle-all">HIDE ALL</button>
<button id="delete-all">DELETE ALL</button>
</div>
<div class="vertical-spacer-1_5"></div>
Expand Down