diff --git a/modules/Element.lua b/modules/Element.lua index 2a256df..01fbdb9 100644 --- a/modules/Element.lua +++ b/modules/Element.lua @@ -133,6 +133,7 @@ ---@field scrollbarRadius number? -- Scrollbar corner radius ---@field scrollbarPadding number? -- Scrollbar padding from edges ---@field scrollSpeed number? -- Scroll speed multiplier +---@field invertScroll boolean? -- Invert mouse wheel scroll direction (default: false) ---@field scrollBarStyle string? -- Scrollbar style name from theme (selects from theme.scrollbars) ---@field scrollbarKnobOffset number|table? -- Scrollbar knob/handle offset (number or {x, y} or {horizontal, vertical}) ---@field _overflowX boolean? -- Internal: whether content overflows horizontally @@ -1845,6 +1846,7 @@ function Element.new(props) scrollbarRadius = props.scrollbarRadius, scrollbarPadding = props.scrollbarPadding, scrollSpeed = props.scrollSpeed, + invertScroll = props.invertScroll, smoothScrollEnabled = props.smoothScrollEnabled, scrollBarStyle = props.scrollBarStyle, scrollbarKnobOffset = props.scrollbarKnobOffset, @@ -1863,6 +1865,7 @@ function Element.new(props) self.scrollbarRadius = self._scrollManager.scrollbarRadius self.scrollbarPadding = self._scrollManager.scrollbarPadding self.scrollSpeed = self._scrollManager.scrollSpeed + self.invertScroll = self._scrollManager.invertScroll self.scrollBarStyle = self._scrollManager.scrollBarStyle self.scrollbarKnobOffset = self._scrollManager.scrollbarKnobOffset self.hideScrollbars = self._scrollManager.hideScrollbars diff --git a/modules/ScrollManager.lua b/modules/ScrollManager.lua index f1322af..b834f09 100644 --- a/modules/ScrollManager.lua +++ b/modules/ScrollManager.lua @@ -8,6 +8,7 @@ ---@field scrollbarRadius number -- Border radius for scrollbars ---@field scrollbarPadding number -- Padding around scrollbar ---@field scrollSpeed number -- Scroll speed for wheel events (pixels per wheel unit) +---@field invertScroll boolean -- Invert mouse wheel scroll direction (default: false) ---@field scrollBarStyle string? -- Scrollbar style name from theme (selects from theme.scrollbars) ---@field scrollbarKnobOffset table -- {x: number, y: number, horizontal: number, vertical: number} -- Offset for scrollbar knob/handle position ---@field hideScrollbars table -- {vertical: boolean, horizontal: boolean} @@ -83,6 +84,7 @@ function ScrollManager.new(config, deps) self.scrollbarRadius = config.scrollbarRadius or 6 self.scrollbarPadding = config.scrollbarPadding or 2 self.scrollSpeed = config.scrollSpeed or 20 + self.invertScroll = config.invertScroll or false self.scrollBarStyle = config.scrollBarStyle -- Theme scrollbar style name (nil = use default) -- scrollbarKnobOffset can be number or table {x, y} or {horizontal, vertical} @@ -582,6 +584,9 @@ function ScrollManager:handleWheel(x, y) -- Vertical scrolling if y ~= 0 and hasVerticalOverflow then local delta = -y * self.scrollSpeed -- Negative because wheel up = scroll up + if self.invertScroll then + delta = -delta -- Invert scroll direction if enabled + end if self.smoothScrollEnabled then -- Set target for smooth scrolling instead of instant jump self._targetScrollY = self._utils.clamp((self._targetScrollY or self._scrollY) + delta, 0, self._maxScrollY) @@ -596,6 +601,9 @@ function ScrollManager:handleWheel(x, y) -- Horizontal scrolling if x ~= 0 and hasHorizontalOverflow then local delta = -x * self.scrollSpeed + if self.invertScroll then + delta = -delta -- Invert scroll direction if enabled + end if self.smoothScrollEnabled then -- Set target for smooth scrolling instead of instant jump self._targetScrollX = self._utils.clamp((self._targetScrollX or self._scrollX) + delta, 0, self._maxScrollX) diff --git a/modules/types.lua b/modules/types.lua index 7672548..559e1bc 100644 --- a/modules/types.lua +++ b/modules/types.lua @@ -122,6 +122,7 @@ local AnimationProps = {} ---@field scrollbarRadius number? -- Corner radius for scrollbar (default: 6) ---@field scrollbarPadding number? -- Padding between scrollbar and edge (default: 2) ---@field scrollSpeed number? -- Pixels per wheel notch (default: 20) +---@field invertScroll boolean? -- Invert mouse wheel scroll direction (default: false) ---@field smoothScrollEnabled boolean? -- Enable smooth scrolling animation for wheel events (default: false) ---@field scrollBarStyle string? -- Scrollbar style name from theme (selects from theme.scrollbars, default: uses first scrollbar or fallback rendering) ---@field scrollbarKnobOffset number|{x:number, y:number}|{horizontal:number, vertical:number}? -- Offset for scrollbar knob/handle position in pixels (number for both axes, or table for per-axis control, default: 0, adds to theme offset)