pass spacing to parsePresetWidths
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
type PresetWidth = ((screenWidth: number, spacing: number) => number);
|
||||
type PresetWidth = (maxWidth: number) => number;
|
||||
|
||||
function parsePresetWidths(presetWidths: string): PresetWidth[] {
|
||||
function parsePresetWidths(presetWidths: string, spacing: number): PresetWidth[] {
|
||||
function parseNumberSafe(str: string) {
|
||||
const num = Number(str);
|
||||
if (isNaN(num) || num <= 0) {
|
||||
@@ -17,7 +17,7 @@ function parsePresetWidths(presetWidths: string): PresetWidth[] {
|
||||
}
|
||||
|
||||
function getRatioFunction(ratio: number) {
|
||||
return (screenWidth: number, spacing: number) => Math.floor((screenWidth + spacing) * ratio - spacing);
|
||||
return (maxWidth: number) => Math.floor((maxWidth + spacing) * ratio - spacing);
|
||||
}
|
||||
|
||||
return presetWidths.split(",").map((widthStr: string) => {
|
||||
|
||||
@@ -11,7 +11,7 @@ class World {
|
||||
|
||||
let presetWidths: PresetWidth[] = [];
|
||||
try {
|
||||
presetWidths = parsePresetWidths(config.presetWidths);
|
||||
presetWidths = parsePresetWidths(config.presetWidths, config.gapsInnerHorizontal);
|
||||
} catch (error: any) {
|
||||
notificationInvalidPresetWidths.sendEvent();
|
||||
log("failed to parse presetWidths:", error);
|
||||
|
||||
@@ -17,12 +17,12 @@ tests.register("parsePresetWidths", 1, () => {
|
||||
];
|
||||
|
||||
function applyPresetWidths(presetWidths: PresetWidth[]) {
|
||||
return presetWidths.map(f => f(screenWidth, spacing));
|
||||
return presetWidths.map(f => f(screenWidth));
|
||||
}
|
||||
|
||||
for (const testCase of testCases) {
|
||||
try {
|
||||
const result = parsePresetWidths(testCase.str);
|
||||
const result = parsePresetWidths(testCase.str, spacing);
|
||||
assert(!testCase.error);
|
||||
assertArrayEqual(applyPresetWidths(result), testCase.result!);
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user