finer sliders
Now sliders can have a better precision when editing text than when dragging. Signed-off-by: Victor Seiji Hariki <victorseijih@gmail.com>
This commit is contained in:
parent
514c498391
commit
4681113f81
6 changed files with 71 additions and 39 deletions
|
@ -494,6 +494,7 @@ const makeSlider = (
|
||||||
max,
|
max,
|
||||||
step,
|
step,
|
||||||
defaultValue,
|
defaultValue,
|
||||||
|
textStep = null,
|
||||||
valuecb = null
|
valuecb = null
|
||||||
) => {
|
) => {
|
||||||
const local = localStorage.getItem(lsKey);
|
const local = localStorage.getItem(lsKey);
|
||||||
|
@ -509,6 +510,7 @@ const makeSlider = (
|
||||||
max,
|
max,
|
||||||
step,
|
step,
|
||||||
defaultValue: def,
|
defaultValue: def,
|
||||||
|
textStep,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -519,7 +521,8 @@ makeSlider(
|
||||||
-1,
|
-1,
|
||||||
25,
|
25,
|
||||||
0.5,
|
0.5,
|
||||||
7.0
|
7.0,
|
||||||
|
0.1
|
||||||
);
|
);
|
||||||
makeSlider(
|
makeSlider(
|
||||||
"Batch Size",
|
"Batch Size",
|
||||||
|
@ -547,12 +550,13 @@ makeSlider(
|
||||||
16,
|
16,
|
||||||
1,
|
1,
|
||||||
8,
|
8,
|
||||||
|
null,
|
||||||
(v) => {
|
(v) => {
|
||||||
scaleFactor = v;
|
scaleFactor = v;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
makeSlider("Steps", document.getElementById("steps"), "steps", 1, 70, 1, 30);
|
makeSlider("Steps", document.getElementById("steps"), "steps", 1, 70, 5, 30, 1);
|
||||||
|
|
||||||
function changeSnapMode() {
|
function changeSnapMode() {
|
||||||
snapToGrid = document.getElementById("cbxSnap").checked;
|
snapToGrid = document.getElementById("cbxSnap").checked;
|
||||||
|
|
|
@ -150,18 +150,20 @@ const _toolbar_input = {
|
||||||
return {checkbox, label};
|
return {checkbox, label};
|
||||||
},
|
},
|
||||||
|
|
||||||
slider: (state, dataKey, text, min = 0, max = 1, step = 0.1, cb = null) => {
|
slider: (state, dataKey, text, options = {}) => {
|
||||||
|
defaultOpt(options, {min: 0, max: 1, step: 0.1, textStep: null, cb: null});
|
||||||
const slider = document.createElement("div");
|
const slider = document.createElement("div");
|
||||||
|
|
||||||
const value = createSlider(text, slider, {
|
const value = createSlider(text, slider, {
|
||||||
min,
|
min: options.min,
|
||||||
max,
|
max: options.max,
|
||||||
step,
|
step: options.step,
|
||||||
valuecb: (v) => {
|
valuecb: (v) => {
|
||||||
state[dataKey] = v;
|
state[dataKey] = v;
|
||||||
cb && cb(v);
|
options.cb && options.cb(v);
|
||||||
},
|
},
|
||||||
defaultValue: state[dataKey],
|
defaultValue: state[dataKey],
|
||||||
|
textStep: options.textStep,
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
24
js/lib/ui.js
24
js/lib/ui.js
|
@ -72,6 +72,8 @@ function makeDraggable(element) {
|
||||||
* @param {number} options.max The maximum value of the slider
|
* @param {number} options.max The maximum value of the slider
|
||||||
* @param {number} options.step The step size for the slider
|
* @param {number} options.step The step size for the slider
|
||||||
* @param {number} option.defaultValue The default value of the slider
|
* @param {number} option.defaultValue The default value of the slider
|
||||||
|
* @param {number} [options.textStep=step] The step size for the slider text and setvalue \
|
||||||
|
* (usually finer, and an integer divisor of step size)
|
||||||
* @returns {{value: number}} A reference to the value of the slider
|
* @returns {{value: number}} A reference to the value of the slider
|
||||||
*/
|
*/
|
||||||
function createSlider(name, wrapper, options = {}) {
|
function createSlider(name, wrapper, options = {}) {
|
||||||
|
@ -81,6 +83,7 @@ function createSlider(name, wrapper, options = {}) {
|
||||||
max: 1,
|
max: 1,
|
||||||
step: 0.1,
|
step: 0.1,
|
||||||
defaultValue: 0.7,
|
defaultValue: 0.7,
|
||||||
|
textStep: null,
|
||||||
});
|
});
|
||||||
|
|
||||||
let value = options.defaultValue;
|
let value = options.defaultValue;
|
||||||
|
@ -92,6 +95,15 @@ function createSlider(name, wrapper, options = {}) {
|
||||||
phantomRange.max = options.max;
|
phantomRange.max = options.max;
|
||||||
phantomRange.step = options.step;
|
phantomRange.step = options.step;
|
||||||
|
|
||||||
|
let phantomTextRange = phantomRange;
|
||||||
|
if (options.textStep) {
|
||||||
|
phantomTextRange = document.createElement("input");
|
||||||
|
phantomTextRange.type = "range";
|
||||||
|
phantomTextRange.min = options.min;
|
||||||
|
phantomTextRange.max = options.max;
|
||||||
|
phantomTextRange.step = options.textStep;
|
||||||
|
}
|
||||||
|
|
||||||
// Build slider element
|
// Build slider element
|
||||||
const underEl = document.createElement("div");
|
const underEl = document.createElement("div");
|
||||||
underEl.classList.add("under");
|
underEl.classList.add("under");
|
||||||
|
@ -114,8 +126,8 @@ function createSlider(name, wrapper, options = {}) {
|
||||||
|
|
||||||
// Set value
|
// Set value
|
||||||
const setValue = (val) => {
|
const setValue = (val) => {
|
||||||
phantomRange.value = val;
|
phantomTextRange.value = val;
|
||||||
value = parseFloat(phantomRange.value);
|
value = parseFloat(phantomTextRange.value);
|
||||||
bar.style.width = `${
|
bar.style.width = `${
|
||||||
100 * ((value - options.min) / (options.max - options.min))
|
100 * ((value - options.min) / (options.max - options.min))
|
||||||
}%`;
|
}%`;
|
||||||
|
@ -156,17 +168,15 @@ function createSlider(name, wrapper, options = {}) {
|
||||||
|
|
||||||
mouse.listen.window.btn.left.ondrag.on((evn) => {
|
mouse.listen.window.btn.left.ondrag.on((evn) => {
|
||||||
if (evn.initialTarget === overEl) {
|
if (evn.initialTarget === overEl) {
|
||||||
setValue(
|
phantomRange.value = Math.max(
|
||||||
Math.max(
|
|
||||||
options.min,
|
options.min,
|
||||||
Math.min(
|
Math.min(
|
||||||
options.max,
|
options.max,
|
||||||
(evn.evn.layerX / wrapper.offsetWidth) *
|
(evn.evn.layerX / wrapper.offsetWidth) * (options.max - options.min) +
|
||||||
(options.max - options.min) +
|
|
||||||
options.min
|
options.min
|
||||||
)
|
)
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
setValue(parseFloat(phantomRange.value));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -207,9 +207,12 @@ const colorBrushTool = () =>
|
||||||
state,
|
state,
|
||||||
"brushSize",
|
"brushSize",
|
||||||
"Brush Size",
|
"Brush Size",
|
||||||
state.config.minBrushSize,
|
{
|
||||||
state.config.maxBrushSize,
|
min: state.config.minBrushSize,
|
||||||
1
|
max: state.config.maxBrushSize,
|
||||||
|
step: 5,
|
||||||
|
textStep: 1,
|
||||||
|
}
|
||||||
);
|
);
|
||||||
state.ctxmenu.brushSizeSlider = brushSizeSlider.slider;
|
state.ctxmenu.brushSizeSlider = brushSizeSlider.slider;
|
||||||
state.setBrushSize = brushSizeSlider.setValue;
|
state.setBrushSize = brushSizeSlider.setValue;
|
||||||
|
@ -219,9 +222,11 @@ const colorBrushTool = () =>
|
||||||
state,
|
state,
|
||||||
"brushBlur",
|
"brushBlur",
|
||||||
"Brush Blur",
|
"Brush Blur",
|
||||||
state.config.minBlur,
|
{
|
||||||
state.config.maxBlur,
|
min: state.config.minBlur,
|
||||||
1
|
max: state.config.maxBlur,
|
||||||
|
step: 1,
|
||||||
|
}
|
||||||
);
|
);
|
||||||
state.ctxmenu.brushBlurSlider = brushBlurSlider.slider;
|
state.ctxmenu.brushBlurSlider = brushBlurSlider.slider;
|
||||||
|
|
||||||
|
|
|
@ -641,9 +641,11 @@ const dreamTool = () =>
|
||||||
state,
|
state,
|
||||||
"overMaskPx",
|
"overMaskPx",
|
||||||
"Overmask px",
|
"Overmask px",
|
||||||
0,
|
{
|
||||||
128,
|
min: 0,
|
||||||
1
|
max: 128,
|
||||||
|
step: 1,
|
||||||
|
}
|
||||||
).slider;
|
).slider;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -771,9 +773,12 @@ const img2imgTool = () =>
|
||||||
state,
|
state,
|
||||||
"denoisingStrength",
|
"denoisingStrength",
|
||||||
"Denoising Strength",
|
"Denoising Strength",
|
||||||
0,
|
{
|
||||||
1,
|
min: 0,
|
||||||
0.05
|
max: 1,
|
||||||
|
step: 0.05,
|
||||||
|
textStep: 0.01,
|
||||||
|
}
|
||||||
).slider;
|
).slider;
|
||||||
|
|
||||||
// Border Mask Size Slider
|
// Border Mask Size Slider
|
||||||
|
@ -781,9 +786,12 @@ const img2imgTool = () =>
|
||||||
state,
|
state,
|
||||||
"keepBorderSize",
|
"keepBorderSize",
|
||||||
"Keep Border Size",
|
"Keep Border Size",
|
||||||
0,
|
{
|
||||||
128,
|
min: 0,
|
||||||
1
|
max: 128,
|
||||||
|
step: 8,
|
||||||
|
textStep: 1,
|
||||||
|
}
|
||||||
).slider;
|
).slider;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -182,12 +182,15 @@ const maskBrushTool = () =>
|
||||||
state,
|
state,
|
||||||
"brushSize",
|
"brushSize",
|
||||||
"Brush Size",
|
"Brush Size",
|
||||||
state.config.minBrushSize,
|
{
|
||||||
state.config.maxBrushSize,
|
min: state.config.minBrushSize,
|
||||||
1,
|
max: state.config.maxBrushSize,
|
||||||
(v) => {
|
step: 5,
|
||||||
|
textStep: 1,
|
||||||
|
cb: (v) => {
|
||||||
if (!state.cursorLayer) return;
|
if (!state.cursorLayer) return;
|
||||||
_paint_mb_cursor(state);
|
_paint_mb_cursor(state);
|
||||||
|
},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
state.ctxmenu.brushSizeSlider = brushSizeSlider.slider;
|
state.ctxmenu.brushSizeSlider = brushSizeSlider.slider;
|
||||||
|
|
Loading…
Reference in a new issue