fixed sliders/text settings to update in real time when adjusting, same as reset functionality
This commit is contained in:
parent
1f1b43e0f5
commit
a6dc16370c
81
main.ts
81
main.ts
|
@ -52,12 +52,6 @@ export default class GridBackgroundPlugin extends Plugin {
|
||||||
this.onunload();
|
this.onunload();
|
||||||
this.injectGridCSS();
|
this.injectGridCSS();
|
||||||
}
|
}
|
||||||
|
|
||||||
public updateGridColourAlpha(alpha: number): void {
|
|
||||||
const match = this.settings.gridColour.match(/\d+/g);
|
|
||||||
const [r, g, b] = match ? match.slice(0, 3) : [255, 255, 255]; // Default to white if RGB values are missing
|
|
||||||
this.settings.gridColour = `rgba(${r}, ${g}, ${b}, ${alpha.toFixed(2)})`;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class GridBackgroundSettingTab extends PluginSettingTab {
|
class GridBackgroundSettingTab extends PluginSettingTab {
|
||||||
|
@ -74,27 +68,31 @@ class GridBackgroundSettingTab extends PluginSettingTab {
|
||||||
containerEl.empty();
|
containerEl.empty();
|
||||||
containerEl.createEl('h2', { text: 'Grid Background Settings' });
|
containerEl.createEl('h2', { text: 'Grid Background Settings' });
|
||||||
|
|
||||||
let sliderComponent: SliderComponent;
|
let gridSizeSliderComponent: SliderComponent;
|
||||||
let textComponent: TextComponent;
|
let gridSizeTextComponent: TextComponent;
|
||||||
|
|
||||||
|
let gridTransparencySliderComponent: SliderComponent;
|
||||||
|
let gridTransparencyTextComponent: TextComponent;
|
||||||
|
|
||||||
let gridColour: ColorComponent;
|
let gridColour: ColorComponent;
|
||||||
|
|
||||||
const gridSizeSetting = new Setting(containerEl)
|
const gridSizeSetting = new Setting(containerEl)
|
||||||
.setName('Grid Size')
|
.setName('Grid Size')
|
||||||
.setDesc('Spacing between grid lines (in px) - min value is 20px, max is 100px')
|
.setDesc('Spacing between grid lines (in px) - min value is 20px, max is 100px')
|
||||||
.addSlider(sliderValue => {
|
.addSlider(sliderValue => {
|
||||||
sliderComponent = sliderValue;
|
gridSizeSliderComponent = sliderValue;
|
||||||
sliderValue
|
sliderValue
|
||||||
.setInstant(true)
|
.setInstant(true)
|
||||||
.setValue(this.plugin.settings.gridSize)
|
.setValue(this.plugin.settings.gridSize)
|
||||||
.setLimits(20, 100, 1)
|
.setLimits(20, 100, 1)
|
||||||
.onChange(async (value) => {
|
.onChange(async (value) => {
|
||||||
this.plugin.settings.gridSize = value || 20;
|
this.plugin.settings.gridSize = value || 20;
|
||||||
|
gridSizeTextComponent.setValue(value.toString()); // Update the text field when slider changes
|
||||||
await this.plugin.saveSettings();
|
await this.plugin.saveSettings();
|
||||||
textComponent.setValue(value.toString()); // Update the text field when slider changes
|
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.addText(text => {
|
.addText(text => {
|
||||||
textComponent = text;
|
gridSizeTextComponent = text;
|
||||||
text
|
text
|
||||||
.setPlaceholder('e.g. 20')
|
.setPlaceholder('e.g. 20')
|
||||||
.setValue(this.plugin.settings.gridSize.toString())
|
.setValue(this.plugin.settings.gridSize.toString())
|
||||||
|
@ -108,13 +106,13 @@ class GridBackgroundSettingTab extends PluginSettingTab {
|
||||||
parsedValue = 100
|
parsedValue = 100
|
||||||
}
|
}
|
||||||
|
|
||||||
textComponent.setValue(value.toString());
|
|
||||||
|
|
||||||
this.plugin.settings.gridSize = parsedValue;
|
this.plugin.settings.gridSize = parsedValue;
|
||||||
|
|
||||||
|
gridSizeTextComponent.setValue(parsedValue.toString());
|
||||||
|
gridSizeSliderComponent.setValue(parsedValue); // Update the slider when text changes
|
||||||
await this.plugin.saveSettings();
|
await this.plugin.saveSettings();
|
||||||
sliderComponent.setValue(parsedValue); // Update the slider when text changes
|
|
||||||
})
|
})
|
||||||
.inputEl.style.width = '40px'
|
.inputEl.style.width = '50px'
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.addExtraButton(button =>
|
.addExtraButton(button =>
|
||||||
|
@ -123,10 +121,13 @@ class GridBackgroundSettingTab extends PluginSettingTab {
|
||||||
.setTooltip('Restore default')
|
.setTooltip('Restore default')
|
||||||
.onClick(async () => {
|
.onClick(async () => {
|
||||||
this.plugin.settings.gridSize = DEFAULT_SETTINGS.gridSize;
|
this.plugin.settings.gridSize = DEFAULT_SETTINGS.gridSize;
|
||||||
|
gridSizeSliderComponent.setValue(50);
|
||||||
|
gridSizeTextComponent.setValue('50');
|
||||||
await this.plugin.saveSettings();
|
await this.plugin.saveSettings();
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// TODO: Need to add a reset thing here
|
||||||
new Setting(containerEl)
|
new Setting(containerEl)
|
||||||
.setName('Grid Colour')
|
.setName('Grid Colour')
|
||||||
.setDesc('Colour of the grid lines')
|
.setDesc('Colour of the grid lines')
|
||||||
|
@ -147,17 +148,59 @@ class GridBackgroundSettingTab extends PluginSettingTab {
|
||||||
|
|
||||||
new Setting(containerEl)
|
new Setting(containerEl)
|
||||||
.setName('Grid Transparency')
|
.setName('Grid Transparency')
|
||||||
.setDesc('Transparency of the grid lines')
|
.setDesc('Transparency of the grid lines on a scale of 0 (transparent) to 1 (opaque)')
|
||||||
.addSlider(sliderValue => {
|
.addSlider(sliderValue => {
|
||||||
sliderComponent = sliderValue;
|
gridTransparencySliderComponent = sliderValue;
|
||||||
sliderValue
|
sliderValue
|
||||||
.setInstant(true)
|
.setInstant(true)
|
||||||
.setValue(this.plugin.settings.gridTransparency * 100)
|
.setValue(this.plugin.settings.gridTransparency * 100)
|
||||||
.setLimits(0, 100, 1)
|
.setLimits(0, 100, 1)
|
||||||
.onChange(async (value) => {
|
.onChange(async (value) => {
|
||||||
this.plugin.settings.gridTransparency = value / 100;
|
const realValue = value / 100;
|
||||||
|
|
||||||
|
this.plugin.settings.gridTransparency = realValue;
|
||||||
|
gridTransparencyTextComponent.setValue(realValue.toString());
|
||||||
|
gridTransparencySliderComponent.setValue(value);
|
||||||
|
|
||||||
await this.plugin.saveSettings();
|
await this.plugin.saveSettings();
|
||||||
});
|
});
|
||||||
});
|
})
|
||||||
|
.addText(text => {
|
||||||
|
gridTransparencyTextComponent = text;
|
||||||
|
text
|
||||||
|
.setPlaceholder('e.g. 0.05')
|
||||||
|
.setValue(this.plugin.settings.gridTransparency.toString())
|
||||||
|
.onChange(async (value) => {
|
||||||
|
let parsedValue = parseInt(value) || 0.05;
|
||||||
|
|
||||||
|
if (parsedValue < 0) {
|
||||||
|
parsedValue = 0
|
||||||
|
|
||||||
|
} else if (parsedValue > 1) {
|
||||||
|
parsedValue = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
this.plugin.settings.gridTransparency = parsedValue;
|
||||||
|
|
||||||
|
gridTransparencyTextComponent.setValue(parsedValue.toString());
|
||||||
|
gridTransparencySliderComponent.setValue(parsedValue);
|
||||||
|
await this.plugin.saveSettings();
|
||||||
|
})
|
||||||
|
.inputEl.style.width = '50px'
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.addExtraButton(button =>
|
||||||
|
button
|
||||||
|
.setIcon('rotate-ccw')
|
||||||
|
.setTooltip('Restore default')
|
||||||
|
.onClick(async () => {
|
||||||
|
|
||||||
|
this.plugin.settings.gridTransparency = DEFAULT_SETTINGS.gridTransparency;
|
||||||
|
gridTransparencyTextComponent.setValue('0.05');
|
||||||
|
gridTransparencySliderComponent.setValue(5);
|
||||||
|
|
||||||
|
await this.plugin.saveSettings();
|
||||||
|
})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue