27 lines
680 B
TypeScript
27 lines
680 B
TypeScript
import { MacOSScrollAccel, type ScrollAcceleration } from "@opentui/core"
|
|
|
|
export type ScrollConfig = {
|
|
scroll_acceleration?: { enabled?: boolean }
|
|
scroll_speed?: number
|
|
}
|
|
|
|
export class CustomSpeedScroll implements ScrollAcceleration {
|
|
constructor(private speed: number) {}
|
|
|
|
tick(_now?: number): number {
|
|
return this.speed
|
|
}
|
|
|
|
reset(): void {}
|
|
}
|
|
|
|
export function getScrollAcceleration(tuiConfig?: ScrollConfig): ScrollAcceleration {
|
|
if (tuiConfig?.scroll_acceleration?.enabled) {
|
|
return new MacOSScrollAccel()
|
|
}
|
|
if (tuiConfig?.scroll_speed !== undefined) {
|
|
return new CustomSpeedScroll(tuiConfig.scroll_speed)
|
|
}
|
|
|
|
return new CustomSpeedScroll(3)
|
|
}
|