restore-chat: fix mouse-scroll
scrolling down with mouse while window too small was not working
This commit is contained in:
+41
-14
@@ -13282,23 +13282,50 @@ function LeaPlusLC:Player()
|
|||||||
currentEdit:SetHeight(math.max(needed, scroll:GetHeight())) -- scroll is LeaPlusLC.RecentChatScroll
|
currentEdit:SetHeight(math.max(needed, scroll:GetHeight())) -- scroll is LeaPlusLC.RecentChatScroll
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- scroll with mouse-wheel
|
||||||
-- scroll with mouse-wheel
|
-- scroll with mouse-wheel
|
||||||
scroll:SetScript("OnMouseWheel", function(self, delta)
|
scroll:SetScript("OnMouseWheel", function(self, delta)
|
||||||
local cur = self:GetVerticalScroll()
|
local currentEdit = LeaPlusLC.RecentChatEdit -- self is the scroll frame
|
||||||
local max = self:GetVerticalScrollRange()
|
|
||||||
local h = self:GetHeight()
|
local maxScrollRange = self:GetVerticalScrollRange()
|
||||||
local step= 20
|
|
||||||
if delta > 0 then
|
-- If there's nothing to scroll (content fits within view), do nothing.
|
||||||
cur = IsShiftKeyDown() and 0
|
if not maxScrollRange or maxScrollRange <= 0 then
|
||||||
or IsAltKeyDown() and cur - h
|
return
|
||||||
or cur - step
|
|
||||||
else
|
|
||||||
cur = IsShiftKeyDown() and max
|
|
||||||
or IsAltKeyDown() and cur + h
|
|
||||||
or cur + step
|
|
||||||
end
|
end
|
||||||
if cur < 0 then cur = 0 elseif cur > max then cur = max end
|
|
||||||
self:SetVerticalScroll(cur)
|
local currentScroll = self:GetVerticalScroll()
|
||||||
|
local viewHeight = self:GetHeight() -- The visible height of the scroll area
|
||||||
|
|
||||||
|
local stepAmount
|
||||||
|
if IsAltKeyDown() then
|
||||||
|
-- Alt + Wheel: Page up/down
|
||||||
|
stepAmount = viewHeight
|
||||||
|
else
|
||||||
|
-- Normal Wheel: Scroll by a few lines
|
||||||
|
local fontHeight = 14 -- Default reasonable font height
|
||||||
|
if currentEdit and currentEdit:IsShown() then
|
||||||
|
local _, fh = currentEdit:GetFont()
|
||||||
|
if fh and fh > 0 then
|
||||||
|
fontHeight = fh
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local linesToScroll = 3 -- Scroll 3 lines per tick
|
||||||
|
stepAmount = fontHeight * linesToScroll
|
||||||
|
end
|
||||||
|
|
||||||
|
local newScrollPosition
|
||||||
|
if delta > 0 then -- Scrolling up (wheel moved away from user)
|
||||||
|
newScrollPosition = IsShiftKeyDown() and 0 or (currentScroll - stepAmount)
|
||||||
|
else -- Scrolling down (wheel moved towards user)
|
||||||
|
newScrollPosition = IsShiftKeyDown() and maxScrollRange or (currentScroll + stepAmount)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Clamp the new scroll position to be within the valid range [0, maxScrollRange]
|
||||||
|
newScrollPosition = math.max(0, newScrollPosition)
|
||||||
|
newScrollPosition = math.min(newScrollPosition, maxScrollRange)
|
||||||
|
|
||||||
|
self:SetVerticalScroll(newScrollPosition)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
----------------------------------------
|
----------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user