Added preview size sliders to settings

This commit is contained in:
EtSL33py
2024-09-23 15:42:33 +03:00
parent 67fcfa015b
commit b0913a73e4
3 changed files with 61 additions and 6 deletions

View File

@@ -183,6 +183,8 @@ def ui_rules():
Rule("model-preview-thumbnail-type", "AUTO", str), Rule("model-preview-thumbnail-type", "AUTO", str),
Rule("model-preview-fallback-search-safetensors-thumbnail", False, bool), Rule("model-preview-fallback-search-safetensors-thumbnail", False, bool),
Rule("model-preview-thumbnail-width", 240, int, 150, 480),
Rule("model-preview-thumbnail-height", 360, int, 185, 480),
Rule("model-show-label-extensions", False, bool), Rule("model-show-label-extensions", False, bool),
Rule("model-show-add-button", True, bool), Rule("model-show-add-button", True, bool),
Rule("model-show-copy-button", True, bool), Rule("model-show-copy-button", True, bool),

View File

@@ -51,6 +51,9 @@
--model-manager-sidebar-height-top: 50vh; --model-manager-sidebar-height-top: 50vh;
--model-manager-sidebar-height-bottom: 50vh; --model-manager-sidebar-height-bottom: 50vh;
--model-manager-thumbnail-width: 240px;
--model-manager-thumbnail-height: 360px;
--model-manager-left: 0; --model-manager-left: 0;
--model-manager-right: 0; --model-manager-right: 0;
--model-manager-top: 0; --model-manager-top: 0;
@@ -399,8 +402,8 @@
/* preview image */ /* preview image */
.model-manager .item { .model-manager .item {
position: relative; position: relative;
width: 240px; width: var(--model-manager-thumbnail-width);;
height: 360px; height: var(--model-manager-thumbnail-height);;
text-align: center; text-align: center;
overflow: hidden; overflow: hidden;
border-radius: 8px; border-radius: 8px;

View File

@@ -250,8 +250,6 @@ function imageUri(
return uri; return uri;
} }
const PREVIEW_NONE_URI = imageUri(); const PREVIEW_NONE_URI = imageUri();
const PREVIEW_THUMBNAIL_WIDTH = 320;
const PREVIEW_THUMBNAIL_HEIGHT = 480;
/** /**
* *
@@ -2042,6 +2040,10 @@ class ModelGrid {
!settingsElements['model-add-embedding-extension'].checked; !settingsElements['model-add-embedding-extension'].checked;
const previewThumbnailFormat = const previewThumbnailFormat =
settingsElements['model-preview-thumbnail-type'].value; settingsElements['model-preview-thumbnail-type'].value;
const previewThumbnailWidth =
Math.round(settingsElements['model-preview-thumbnail-width'].value / 0.75);
const previewThumbnailHeight =
Math.round(settingsElements['model-preview-thumbnail-height'].value / 0.75);
if (models.length > 0) { if (models.length > 0) {
const $overlay = IS_FIREFOX const $overlay = IS_FIREFOX
@@ -2092,8 +2094,8 @@ class ModelGrid {
src: imageUri( src: imageUri(
previewInfo?.path, previewInfo?.path,
previewInfo?.dateModified, previewInfo?.dateModified,
PREVIEW_THUMBNAIL_WIDTH, previewThumbnailWidth,
PREVIEW_THUMBNAIL_HEIGHT, previewThumbnailHeight,
previewThumbnailFormat, previewThumbnailFormat,
), ),
draggable: false, draggable: false,
@@ -4361,6 +4363,8 @@ class SettingsView {
/** @type {HTMLInputElement} */ 'model-persistent-search': null, /** @type {HTMLInputElement} */ 'model-persistent-search': null,
/** @type {HTMLInputElement} */ 'model-preview-thumbnail-type': null, /** @type {HTMLInputElement} */ 'model-preview-thumbnail-type': null,
/** @type {HTMLInputElement} */ 'model-preview-thumbnail-width': null,
/** @type {HTMLInputElement} */ 'model-preview-thumbnail-height': null,
/** @type {HTMLInputElement} */ 'model-preview-fallback-search-safetensors-thumbnail': /** @type {HTMLInputElement} */ 'model-preview-fallback-search-safetensors-thumbnail':
null, null,
/** @type {HTMLInputElement} */ 'model-show-label-extensions': null, /** @type {HTMLInputElement} */ 'model-show-label-extensions': null,
@@ -4632,6 +4636,34 @@ class SettingsView {
textContent: 'Preview thumbnail type', textContent: 'Preview thumbnail type',
options: ['AUTO', 'JPEG'], // should use AUTO to avoid artifacts from changing between formats; use JPEG for backward compatibility options: ['AUTO', 'JPEG'], // should use AUTO to avoid artifacts from changing between formats; use JPEG for backward compatibility
}), }),
$el('label', [
'Preview thumbnail width',
$el('input', {
$: (el) => (settings['model-preview-thumbnail-width'] = el),
type: 'range',
name: 'default thumbnail width',
value: 240,
min: 150,
max: 480,
step: 5,
oninput: function(){ this.nextElementSibling.textContent = this.value + 'px'},
}),
$el('span'),
]),
$el('label', [
'Preview thumbnail height',
$el('input', {
$: (el) => (settings['model-preview-thumbnail-height'] = el),
type: 'range',
name: 'default thumbnail height',
value: 360,
min: 185,
max: 480,
step: 5,
oninput: function(){ this.nextElementSibling.textContent = this.value + 'px'},
}),
$el('span'),
]),
$checkbox({ $checkbox({
$: (el) => $: (el) =>
(settings['model-preview-fallback-search-safetensors-thumbnail'] = (settings['model-preview-fallback-search-safetensors-thumbnail'] =
@@ -5448,6 +5480,24 @@ class ModelManager extends ComfyDialog {
this.#downloadView.elements.clearSearchButton.style.display = this.#downloadView.elements.clearSearchButton.style.display =
hideClearSearchButtons ? 'none' : ''; hideClearSearchButtons ? 'none' : '';
} }
{
// update thumbnail widths & heights
const thumbnailWidthEl = settings['model-preview-thumbnail-width'];
const thumbnailHeightEl = settings['model-preview-thumbnail-height'];
this.element.style.setProperty(
'--model-manager-thumbnail-width',
thumbnailWidthEl.value.toString() + 'px',
);
thumbnailWidthEl.dispatchEvent(new Event('input'));
this.element.style.setProperty(
'--model-manager-thumbnail-height',
thumbnailHeightEl.value.toString() + 'px',
);
thumbnailHeightEl.dispatchEvent(new Event('input'));
}
} }
#resetManagerContentsScroll = () => { #resetManagerContentsScroll = () => {