tweaked with some settings
This commit is contained in:
parent
c61aea83a2
commit
7c6293fa41
50
main.ts
50
main.ts
|
@ -1,4 +1,4 @@
|
||||||
import { App, Editor, MarkdownView, Modal, Notice, Plugin, PluginSettingTab, Setting } from 'obsidian';
|
import { App, Editor, MarkdownView, Modal, Notice, ColorComponent, TextComponent, SliderComponent, Plugin, PluginSettingTab, Setting } from 'obsidian';
|
||||||
|
|
||||||
interface GridBackgroundSettings {
|
interface GridBackgroundSettings {
|
||||||
gridSize: number;
|
gridSize: number;
|
||||||
|
@ -54,6 +54,7 @@ export default class GridBackgroundPlugin extends Plugin {
|
||||||
|
|
||||||
class GridBackgroundSettingTab extends PluginSettingTab {
|
class GridBackgroundSettingTab extends PluginSettingTab {
|
||||||
plugin: GridBackgroundPlugin;
|
plugin: GridBackgroundPlugin;
|
||||||
|
sliderGridSize: SliderComponent;
|
||||||
|
|
||||||
constructor(app: App, plugin: GridBackgroundPlugin) {
|
constructor(app: App, plugin: GridBackgroundPlugin) {
|
||||||
super(app, plugin);
|
super(app, plugin);
|
||||||
|
@ -65,17 +66,44 @@ class GridBackgroundSettingTab extends PluginSettingTab {
|
||||||
containerEl.empty();
|
containerEl.empty();
|
||||||
containerEl.createEl('h2', { text: 'Grid Background Settings' });
|
containerEl.createEl('h2', { text: 'Grid Background Settings' });
|
||||||
|
|
||||||
new Setting(containerEl)
|
const gridSizeSetting = new Setting(containerEl)
|
||||||
.setName('Grid Size')
|
.setName('Grid Size')
|
||||||
.setDesc('Spacing between grid lines (in px)')
|
.setDesc('Spacing between grid lines (in px)');
|
||||||
.addText(text =>
|
|
||||||
text
|
const gridSizeSlider = gridSizeSetting.addSlider(sliderValue =>
|
||||||
.setPlaceholder('e.g. 20')
|
sliderValue
|
||||||
.setValue(this.plugin.settings.gridSize.toString())
|
.setInstant(true)
|
||||||
.onChange(async (value) => {
|
.setValue(this.plugin.settings.gridSize)
|
||||||
this.plugin.settings.gridSize = parseInt(value) || 20;
|
.setLimits(20, 100, 1)
|
||||||
await this.plugin.saveSettings();
|
.onChange(async (value) => {
|
||||||
}));
|
this.plugin.settings.gridSize = value || 20;
|
||||||
|
(gridSizeText.components[0] as TextComponent).setValue(value.toString());
|
||||||
|
await this.plugin.saveSettings();
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
const gridSizeText = gridSizeSetting.addText(text =>
|
||||||
|
text
|
||||||
|
.setPlaceholder('e.g. 20')
|
||||||
|
.setValue(this.plugin.settings.gridSize.toString())
|
||||||
|
.onChange(async (value) => {
|
||||||
|
this.plugin.settings.gridSize = parseInt(value) || 20;
|
||||||
|
(gridSizeText.components[0] as TextComponent).setValue(value.toString());
|
||||||
|
await this.plugin.saveSettings();
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
gridSizeSetting.addButton(button =>
|
||||||
|
button
|
||||||
|
.setButtonText('Reset')
|
||||||
|
.setCta()
|
||||||
|
.onClick(async () => {
|
||||||
|
this.plugin.settings.gridSize = DEFAULT_SETTINGS.gridSize;
|
||||||
|
(gridSizeText.components[0] as TextComponent).setValue(this.plugin.settings.gridSize.toString());
|
||||||
|
(gridSizeSlider.components[0] as SliderComponent).setValue(this.plugin.settings.gridSize);
|
||||||
|
await this.plugin.saveSettings();
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
new Setting(containerEl)
|
new Setting(containerEl)
|
||||||
.setName('Grid Colour')
|
.setName('Grid Colour')
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
{
|
{
|
||||||
"id": "sample-plugin",
|
"id": "grid-background",
|
||||||
"name": "Sample Plugin",
|
"name": "Grid Background",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"minAppVersion": "0.15.0",
|
"minAppVersion": "0.15.0",
|
||||||
"description": "Adds a customizable grid background to note views.",
|
"description": "Adds a customisable grid background to note views.",
|
||||||
"author": "Nathan Nguyen",
|
"author": "Nathan Nguyen",
|
||||||
"isDesktopOnly": false
|
"isDesktopOnly": false
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue