Skip to content

Commit

Permalink
keep the slider value in sync with the weight of each tool
Browse files Browse the repository at this point in the history
this is going to need a refactor, but I want it to be usable for now
  • Loading branch information
hiddenist committed Dec 16, 2023
1 parent a611fe3 commit 3ab2966
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions apps/web/src/components/SliderInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ interface SliderInputProps {
min: number
max: number
className?: string
controlRef: { setValue?: (weight: number) => void }
}

export function SliderInput(props: SliderInputProps) {
Expand Down Expand Up @@ -45,6 +46,7 @@ export function SliderInput(props: SliderInputProps) {
props.onChange(value)
data.currentValue = value
}
props.controlRef.setValue = setValue

const labelElem = (
<span>
Expand Down
10 changes: 8 additions & 2 deletions apps/web/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,14 @@ function makeToolbar<T extends string>(
}
toolSelect.append(option)
})

let setWeightRef: { setValue?: (weight: number | string) => void } = {}
toolSelect.addEventListener("change", () => {
options.onSetTool(toolSelect.value as T)
// todo: set current line weight when switching tools
options.getLineWeight()
const weight = options.getLineWeight()
if (weight) {
setWeightRef.setValue?.(weight)
}
})
inputTray.append(toolSelect)

Expand Down Expand Up @@ -244,6 +248,7 @@ function makeToolbar<T extends string>(
labelAppend: "%",
min: 0,
max: 100,
controlRef: setWeightRef,
getDisplayValue: (value) => value.toFixed(0),
onChange(value) {
options.onSetOpacity(value)
Expand All @@ -264,6 +269,7 @@ function makeToolbar<T extends string>(
})(),
min: 1,
max: 256,
controlRef: setWeightRef,
getDisplayValue: (value) => value.toString(),
onChange(value) {
options.onSetLineWeight(value)
Expand Down

0 comments on commit 3ab2966

Please sign in to comment.