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-content">
<div id="preview-tools" class="displayNone"> <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 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"> <div class="display-settings">
<button id="undo" class="displayNone primaryButton"> <button id="undo" class="displayNone primaryButton">
Undo <i class="fa-solid fa-rotate-left icon"></i> Undo <i class="fa-solid fa-rotate-left icon"></i>
@ -464,31 +464,37 @@
</div> </div>
</div> </div>
<div class="popup" id="download-images-popup"> <dialog id="download-images-dialog">
<div> <div class="dialog-header">
<i class="close-button fa-solid fa-xmark"></i> <div class="dialog-header-left">
<h1>Download all images</h1> <h4>Download all images</h4>
<div class="parameters-table"> <span></span>
<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>
<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> <button id="save-all-images" class="primaryButton"><i class="fa-solid fa-images"></i> Start download</button>
</div> </div>
</div> </dialog>
<div id="save-settings-config" class="popup"> <div id="save-settings-config" class="popup">
<div> <div>
<i class="close-button fa-solid fa-xmark"></i> <i class="close-button fa-solid fa-xmark"></i>

View File

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

View File

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

View File

@ -565,12 +565,6 @@ modifierSettingsCloseBtn.addEventListener("click", (e) => {
modifierSettingsDialog.close() modifierSettingsDialog.close()
}) })
modifierSettingsDialog.addEventListener('mousedown', function (event) { modalDialogCloseOnBackdropClick(modifierSettingsDialog)
var rect = modifierSettingsDialog.getBoundingClientRect(); makeDialogDraggable(modifierSettingsDialog)
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();
}
});

View File

@ -132,9 +132,10 @@ let initialText = document.querySelector("#initial-text")
let versionText = document.querySelector("#version") let versionText = document.querySelector("#version")
let previewTools = document.querySelector("#preview-tools") let previewTools = document.querySelector("#preview-tools")
let clearAllPreviewsBtn = document.querySelector("#clear-all-previews") let clearAllPreviewsBtn = document.querySelector("#clear-all-previews")
let showDownloadPopupBtn = document.querySelector("#show-download-popup") let showDownloadDialogBtn = document.querySelector("#show-download-dialog")
let saveAllImagesPopup = document.querySelector("#download-images-popup") let saveAllImagesDialog = document.querySelector("#download-images-dialog")
let saveAllImagesBtn = document.querySelector("#save-all-images") let saveAllImagesBtn = document.querySelector("#save-all-images")
let saveAllImagesCloseBtn = document.querySelector("#download-images-close-button")
let saveAllZipToggle = document.querySelector("#zip_toggle") let saveAllZipToggle = document.querySelector("#zip_toggle")
let saveAllTreeToggle = document.querySelector("#tree_toggle") let saveAllTreeToggle = document.querySelector("#tree_toggle")
let saveAllJSONToggle = document.querySelector("#json_toggle") let saveAllJSONToggle = document.querySelector("#json_toggle")
@ -1503,9 +1504,10 @@ clearAllPreviewsBtn.addEventListener("click", (e) => {
}) })
/* Download images popup */ /* Download images popup */
showDownloadPopupBtn.addEventListener("click", (e) => { showDownloadDialogBtn.addEventListener("click", (e) => { saveAllImagesDialog.showModal() })
saveAllImagesPopup.classList.add("active") saveAllImagesCloseBtn.addEventListener("click", (e) => { saveAllImagesDialog.close() })
}) modalDialogCloseOnBackdropClick(saveAllImagesDialog)
makeDialogDraggable(saveAllImagesDialog)
saveAllZipToggle.addEventListener("change", (e) => { saveAllZipToggle.addEventListener("change", (e) => {
if (saveAllZipToggle.checked) { 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> <h4>Download tiled image</h4>
<span>Generate a larger image from this tile</span> <span>Generate a larger image from this tile</span>
</div> </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> <i id="downnload-tiled-close-button" class="fa-solid fa-xmark fa-lg"></i>
</div> </div>
</div> </div>
@ -139,14 +139,8 @@
// ---- Close popup // ---- Close popup
document.getElementById("dti-cancel").addEventListener("click", (e) => downloadTiledImageDialog.close()) document.getElementById("dti-cancel").addEventListener("click", (e) => downloadTiledImageDialog.close())
document.getElementById("downnload-tiled-close-button").addEventListener("click", (e) => downloadTiledImageDialog.close()) document.getElementById("downnload-tiled-close-button").addEventListener("click", (e) => downloadTiledImageDialog.close())
downloadTiledImageDialog.addEventListener('click', function (event) { modalDialogCloseOnBackdropClick(downloadTiledImageDialog)
var rect = downloadTiledImageDialog.getBoundingClientRect(); makeDialogDraggable(downloadTiledImageDialog)
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();
}
});
// ---- Stylesheet // ---- Stylesheet
const styleSheet = document.createElement("style") const styleSheet = document.createElement("style")