Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compact view feature Dev #165

Open
wants to merge 17 commits into
base: compact-view-feature
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions src/Components/RangeSlider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

import ExcaliBrain from "src/excalibrain-main";

export class RangeSlider {
private slider: HTMLInputElement
constructor({ plugin, setVal, range, wrapper, updateIndex }:
{
plugin: ExcaliBrain,
setVal: (val: number) => boolean,
isEnabled?: () => boolean,
wrapper: HTMLElement,
range: {
min: number,
max: number,
step: number,
defalutValue?: number,
},
updateIndex: boolean,
}) {

this.slider = wrapper.createEl('input', { type: 'range', cls: "excalibrain-slider" });
this.SetRange(range);
this.slider.oninput = (ev) => {
const value = (ev.target as HTMLInputElement).value;
const shouldSaveSettings = setVal(parseFloat(value));
if (shouldSaveSettings) plugin.saveSettings();
plugin.scene?.reRender(updateIndex);
}
}

private SetRange(range: {
min: number,
max: number,
step: number,
defalutValue?: number,
}) {
this.slider.min = `${range.min}`;
this.slider.max = `${range.max}`;
this.slider.step = `${range.step}`;
this.slider.value = `${range.defalutValue ?? 1.6}`;
}

}
46 changes: 45 additions & 1 deletion src/Components/ToolsPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import { PageSuggest } from "../Suggesters/PageSuggester";
import { LinkTagFilter } from "./LinkTagFilter";
import { EditableFileView, getIcon, TextFileView, WorkspaceLeaf } from "obsidian";
import { addVerticalDivider } from "./VerticalDivider";
import { RangeSlider } from "./RangeSlider";

export class ToolsPanel {
private wrapperDiv: HTMLDivElement;
private buttons: (ToggleButton|HTMLElement)[] = [];
private buttons: (ToggleButton|RangeSlider|HTMLElement)[] = [];
public linkTagFilter: LinkTagFilter;
public searchElement: HTMLInputElement;

Expand Down Expand Up @@ -449,6 +450,49 @@ export class ToolsPanel {
})
);

addVerticalDivider(buttonsWrapperDiv);

// ------------
// Display Compact Button
// ------------
this.buttons.push(
new ToggleButton({
plugin: this.plugin,
getVal: () => this.plugin.settings.compactView,
setVal: (val: boolean) => {
this.plugin.settings.compactView = val;
return true;
},
wrapper: buttonsWrapperDiv,
options: {
display: "🗃️",
icon: getIcon("lucide-minimize-2").outerHTML,
tooltip: t("COMPACT_VIEW_NAME"),
},
updateIndex: false,
})
);
// ------------
// Display Compact factor
// ------------
this.buttons.push(
new RangeSlider({
plugin: this.plugin,
setVal: (val) => {
this.plugin.settings.compactingFactor = val;
return true;
},
wrapper: buttonsWrapperDiv,
range: {
min: 1,
max: 2,
step: 0.1,
defalutValue: this.plugin.settings.compactingFactor
},
updateIndex: false,
})
)

this.contentEl.appendChild(this.wrapperDiv);
}

Expand Down
Loading