Merge pull request #1376 from JeLuF/dlg2

Download dialog redesign, moveable dialogs, code cleanup
This commit is contained in:
cmdr2 2023-06-30 16:02:25 +05:30 committed by GitHub
commit 311ade1281
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 107 additions and 48 deletions

View File

@ -313,7 +313,7 @@
<div id="preview-content">
<div id="preview-tools" class="displayNone">
<button id="clear-all-previews" class="secondaryButton"><i class="fa-solid fa-trash-can icon"></i> Clear All</button>
<button class="tertiaryButton" id="show-download-popup"><i class="fa-solid fa-download"></i> Download images</button>
<button class="tertiaryButton" id="show-download-dialog"><i class="fa-solid fa-download"></i> Download images</button>
<div class="display-settings">
<button id="undo" class="displayNone primaryButton">
Undo <i class="fa-solid fa-rotate-left icon"></i>
@ -464,31 +464,37 @@
</div>
</div>
<div class="popup" id="download-images-popup">
<div>
<i class="close-button fa-solid fa-xmark"></i>
<h1>Download all images</h1>
<div class="parameters-table">
<div>
<div><i class="fa fa-file-zipper"></i></div>
<div><label for="theme">Download as a ZIP file</label><small>Instead of downloading individual files, generate one zip file with all images</small></div>
<div><div class="input-toggle"><input id="zip_toggle" name="zip_toggle" checked="" type="checkbox"><label for="zip_toggle"></label></div></div>
</div>
<div id="download-add-folders">
<div><i class="fa fa-folder-tree"></i></div>
<div><label for="theme">Add per-job folders</label><small>Place images into job folders</small></div>
<div><div class="input-toggle"><input id="tree_toggle" name="tree_toggle" checked="" type="checkbox"><label for="tree_toggle"></label></div></div>
</div>
<div>
<div><i class="fa fa-sliders"></i></div>
<div><label for="theme">Add metadata files</label><small>For each image, also download a JSON file with all the settings used to generate the image</small></div>
<div><div class="input-toggle"><input id="json_toggle" name="json_toggle" checked="" type="checkbox"><label for="json_toggle"></label></div></div>
</div>
<dialog id="download-images-dialog">
<div class="dialog-header">
<div class="dialog-header-left">
<h4>Download all images</h4>
<span></span>
</div>
<br/>
<div>
<i id="download-images-close-button" class="fa-solid fa-xmark fa-lg"></i>
</div>
</div>
<div class="parameters-table">
<div>
<div><i class="fa fa-file-zipper"></i></div>
<div><label for="theme">Download as a ZIP file</label><small>Instead of downloading individual files, generate one zip file with all images</small></div>
<div><div class="input-toggle"><input id="zip_toggle" name="zip_toggle" checked="" type="checkbox"><label for="zip_toggle"></label></div></div>
</div>
<div id="download-add-folders">
<div><i class="fa fa-folder-tree"></i></div>
<div><label for="theme">Add per-job folders</label><small>Place images into job folders</small></div>
<div><div class="input-toggle"><input id="tree_toggle" name="tree_toggle" checked="" type="checkbox"><label for="tree_toggle"></label></div></div>
</div>
<div>
<div><i class="fa fa-sliders"></i></div>
<div><label for="theme">Add metadata files</label><small>For each image, also download a JSON file with all the settings used to generate the image</small></div>
<div><div class="input-toggle"><input id="json_toggle" name="json_toggle" checked="" type="checkbox"><label for="json_toggle"></label></div></div>
</div>
</div>
<div class="center">
<button id="save-all-images" class="primaryButton"><i class="fa-solid fa-images"></i> Start download</button>
</div>
</div>
</dialog>
<div id="save-settings-config" class="popup">
<div>
<i class="close-button fa-solid fa-xmark"></i>

View File

@ -485,7 +485,7 @@ dialog {
}
dialog::backdrop {
background: rgba(0, 0, 0, 0.5);
background: var(--backdrop-color);
}
dialog > div {
@ -1448,10 +1448,18 @@ button#save-system-settings-btn {
line-height: 200%;
}
#download-images-popup .parameters-table > div {
#download-images-dialog .parameters-table > div {
background: var(--background-color1);
}
.center {
text-align: center;
}
.fa-xmark {
cursor: pointer;;
}
/* SCROLLBARS */
:root {
--scrollbar-width: 14px;

View File

@ -1,4 +1,4 @@
:root {
:root, ::backdrop {
--main-hue: 222;
--main-saturation: 4%;
--value-base: 13%;

View File

@ -565,12 +565,6 @@ modifierSettingsCloseBtn.addEventListener("click", (e) => {
modifierSettingsDialog.close()
})
modifierSettingsDialog.addEventListener('mousedown', function (event) {
var rect = modifierSettingsDialog.getBoundingClientRect();
var isInDialog=(rect.top <= event.clientY && event.clientY <= rect.top + rect.height
&& rect.left <= event.clientX && event.clientX <= rect.left + rect.width);
if (!isInDialog) {
modifierSettingsDialog.close();
}
});
modalDialogCloseOnBackdropClick(modifierSettingsDialog)
makeDialogDraggable(modifierSettingsDialog)

View File

@ -132,9 +132,10 @@ let initialText = document.querySelector("#initial-text")
let versionText = document.querySelector("#version")
let previewTools = document.querySelector("#preview-tools")
let clearAllPreviewsBtn = document.querySelector("#clear-all-previews")
let showDownloadPopupBtn = document.querySelector("#show-download-popup")
let saveAllImagesPopup = document.querySelector("#download-images-popup")
let showDownloadDialogBtn = document.querySelector("#show-download-dialog")
let saveAllImagesDialog = document.querySelector("#download-images-dialog")
let saveAllImagesBtn = document.querySelector("#save-all-images")
let saveAllImagesCloseBtn = document.querySelector("#download-images-close-button")
let saveAllZipToggle = document.querySelector("#zip_toggle")
let saveAllTreeToggle = document.querySelector("#tree_toggle")
let saveAllJSONToggle = document.querySelector("#json_toggle")
@ -1503,9 +1504,10 @@ clearAllPreviewsBtn.addEventListener("click", (e) => {
})
/* Download images popup */
showDownloadPopupBtn.addEventListener("click", (e) => {
saveAllImagesPopup.classList.add("active")
})
showDownloadDialogBtn.addEventListener("click", (e) => { saveAllImagesDialog.showModal() })
saveAllImagesCloseBtn.addEventListener("click", (e) => { saveAllImagesDialog.close() })
modalDialogCloseOnBackdropClick(saveAllImagesDialog)
makeDialogDraggable(saveAllImagesDialog)
saveAllZipToggle.addEventListener("change", (e) => {
if (saveAllZipToggle.checked) {

View File

@ -1055,3 +1055,58 @@ async function deleteKeys(keyToDelete) {
});
}
}
function modalDialogCloseOnBackdropClick(dialog) {
dialog.addEventListener('mousedown', function (event) {
var rect = dialog.getBoundingClientRect()
var isInDialog=(rect.top <= event.clientY && event.clientY <= rect.top + rect.height
&& rect.left <= event.clientX && event.clientX <= rect.left + rect.width)
if (!isInDialog) {
dialog.close()
}
})
}
function makeDialogDraggable(element) {
element.querySelector(".dialog-header").addEventListener('mousedown', (function() {
let deltaX=0
let deltaY=0
let dragStartX=0
let dragStartY=0
let oldTop=0
let oldLeft=0
function dlgDragStart(e) {
e = e || window.event;
const d = e.target.closest("dialog")
e.preventDefault();
dragStartX = e.clientX;
dragStartY = e.clientY;
oldTop = parseInt(d.style.top)
oldLeft = parseInt(d.style.left)
if (isNaN(oldTop)) { oldTop=0 }
if (isNaN(oldLeft)) { oldLeft=0 }
document.addEventListener('mouseup', dlgDragClose);
document.addEventListener('mousemove', dlgDrag);
}
function dlgDragClose(e) {
document.removeEventListener('mouseup', dlgDragClose);
document.removeEventListener('mousemove', dlgDrag);
}
function dlgDrag(e) {
e = e || window.event;
const d = e.target.closest("dialog")
e.preventDefault();
deltaX = dragStartX - e.clientX;
deltaY = dragStartY - e.clientY;
d.style.left = `${oldLeft-2*deltaX}px`
d.style.top = `${oldTop-2*deltaY}px`
}
return dlgDragStart
})() )
}

View File

@ -35,7 +35,7 @@
<h4>Download tiled image</h4>
<span>Generate a larger image from this tile</span>
</div>
<div id="modifier-settings-header-right">
<div id="download-header-right">
<i id="downnload-tiled-close-button" class="fa-solid fa-xmark fa-lg"></i>
</div>
</div>
@ -139,14 +139,8 @@
// ---- Close popup
document.getElementById("dti-cancel").addEventListener("click", (e) => downloadTiledImageDialog.close())
document.getElementById("downnload-tiled-close-button").addEventListener("click", (e) => downloadTiledImageDialog.close())
downloadTiledImageDialog.addEventListener('click', function (event) {
var rect = downloadTiledImageDialog.getBoundingClientRect();
var isInDialog=(rect.top <= event.clientY && event.clientY <= rect.top + rect.height
&& rect.left <= event.clientX && event.clientX <= rect.left + rect.width);
if (!isInDialog) {
downloadTiledImageDialog.close();
}
});
modalDialogCloseOnBackdropClick(downloadTiledImageDialog)
makeDialogDraggable(downloadTiledImageDialog)
// ---- Stylesheet
const styleSheet = document.createElement("style")