Update NumberStepper

This commit is contained in:
redphx 2024-10-22 16:52:23 +07:00
parent 95881dd241
commit 33c3b2810a
4 changed files with 26 additions and 17 deletions

View File

@ -789,10 +789,12 @@ class SettingElement {
}), $wrapper.appendChild($range), options.ticks || options.exactTicks) { }), $wrapper.appendChild($range), options.ticks || options.exactTicks) {
let markersId = `markers-${key}`, $markers = CE("datalist", { id: markersId }); let markersId = `markers-${key}`, $markers = CE("datalist", { id: markersId });
if ($range.setAttribute("list", markersId), options.exactTicks) { if ($range.setAttribute("list", markersId), options.exactTicks) {
let start = Math.max(Math.floor(MIN / options.exactTicks), 1) * options.exactTicks; let start = Math.max(Math.floor(setting.min / options.exactTicks), 1) * options.exactTicks;
if (start === MIN) start += options.exactTicks; if (start === setting.min) start += options.exactTicks;
for (let i = start;i < MAX; i += options.exactTicks) for (let i = start;i < setting.max; i += options.exactTicks)
$markers.appendChild(CE("option", { value: i })); $markers.appendChild(CE("option", {
value: options.reverse ? -i : i
}));
} else for (let i = MIN + options.ticks;i < MAX; i += options.ticks) } else for (let i = MIN + options.ticks;i < MAX; i += options.ticks)
$markers.appendChild(CE("option", { value: i })); $markers.appendChild(CE("option", { value: i }));
$wrapper.appendChild($markers); $wrapper.appendChild($markers);
@ -1383,9 +1385,10 @@ class GlobalSettingsStorage extends BaseSettingsStore {
type: "number-stepper", type: "number-stepper",
default: 4, default: 4,
min: 4, min: 4,
max: 40, max: 60,
steps: 4, steps: 4,
params: { params: {
exactTicks: 20,
reverse: !0, reverse: !0,
customTextValue(value) { customTextValue(value) {
value = parseInt(value); value = parseInt(value);

View File

@ -812,10 +812,12 @@ class SettingElement {
}), $wrapper.appendChild($range), options.ticks || options.exactTicks) { }), $wrapper.appendChild($range), options.ticks || options.exactTicks) {
let markersId = `markers-${key}`, $markers = CE("datalist", { id: markersId }); let markersId = `markers-${key}`, $markers = CE("datalist", { id: markersId });
if ($range.setAttribute("list", markersId), options.exactTicks) { if ($range.setAttribute("list", markersId), options.exactTicks) {
let start = Math.max(Math.floor(MIN / options.exactTicks), 1) * options.exactTicks; let start = Math.max(Math.floor(setting.min / options.exactTicks), 1) * options.exactTicks;
if (start === MIN) start += options.exactTicks; if (start === setting.min) start += options.exactTicks;
for (let i = start;i < MAX; i += options.exactTicks) for (let i = start;i < setting.max; i += options.exactTicks)
$markers.appendChild(CE("option", { value: i })); $markers.appendChild(CE("option", {
value: options.reverse ? -i : i
}));
} else for (let i = MIN + options.ticks;i < MAX; i += options.ticks) } else for (let i = MIN + options.ticks;i < MAX; i += options.ticks)
$markers.appendChild(CE("option", { value: i })); $markers.appendChild(CE("option", { value: i }));
$wrapper.appendChild($markers); $wrapper.appendChild($markers);
@ -1406,9 +1408,10 @@ class GlobalSettingsStorage extends BaseSettingsStore {
type: "number-stepper", type: "number-stepper",
default: 4, default: 4,
min: 4, min: 4,
max: 40, max: 60,
steps: 4, steps: 4,
params: { params: {
exactTicks: 20,
reverse: !0, reverse: !0,
customTextValue(value) { customTextValue(value) {
value = parseInt(value); value = parseInt(value);

View File

@ -248,22 +248,24 @@ export class SettingElement {
if (options.ticks || options.exactTicks) { if (options.ticks || options.exactTicks) {
const markersId = `markers-${key}`; const markersId = `markers-${key}`;
const $markers = CE('datalist', {'id': markersId}); const $markers = CE('datalist', {id: markersId});
$range.setAttribute('list', markersId); $range.setAttribute('list', markersId);
if (options.exactTicks) { if (options.exactTicks) {
let start = Math.max(Math.floor(MIN / options.exactTicks), 1) * options.exactTicks; let start = Math.max(Math.floor(setting.min! / options.exactTicks), 1) * options.exactTicks;
if (start === MIN) { if (start === setting.min!) {
start += options.exactTicks; start += options.exactTicks;
} }
for (let i = start; i < MAX; i += options.exactTicks) { for (let i = start; i < setting.max!; i += options.exactTicks) {
$markers.appendChild(CE<HTMLOptionElement>('option', {'value': i})); $markers.appendChild(CE<HTMLOptionElement>('option', {
value: options.reverse ? -i : i,
}));
} }
} else { } else {
for (let i = MIN + options.ticks!; i < MAX; i += options.ticks!) { for (let i = MIN + options.ticks!; i < MAX; i += options.ticks!) {
$markers.appendChild(CE<HTMLOptionElement>('option', {'value': i})); $markers.appendChild(CE<HTMLOptionElement>('option', {value: i}));
} }
} }
$wrapper.appendChild($markers); $wrapper.appendChild($markers);

View File

@ -394,9 +394,10 @@ export class GlobalSettingsStorage extends BaseSettingsStorage {
type: SettingElementType.NUMBER_STEPPER, type: SettingElementType.NUMBER_STEPPER,
default: 4, default: 4,
min: 4, min: 4,
max: 40, max: 60,
steps: 4, steps: 4,
params: { params: {
exactTicks: 20,
reverse: true, reverse: true,
customTextValue(value: any) { customTextValue(value: any) {
value = parseInt(value); value = parseInt(value);