Skip to content

Commit

Permalink
Add scrollbar
Browse files Browse the repository at this point in the history
  • Loading branch information
tekkub committed Oct 14, 2008
1 parent 0df51b5 commit 5ea22dd
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 4 deletions.
20 changes: 16 additions & 4 deletions Ampere.lua
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ frame:SetScript("OnShow", function(frame)
if not anchor then row:SetPoint("TOP", subtitle, "BOTTOM", 0, -16)
else row:SetPoint("TOP", anchor, "BOTTOM", 0, -ROWGAP) end
row:SetPoint("LEFT", EDGEGAP, 0)
row:SetPoint("RIGHT", -EDGEGAP, 0)
row:SetPoint("RIGHT", -EDGEGAP*2-8, 0)
row:SetHeight(ROWHEIGHT)
anchor = row
rows[i] = row
Expand Down Expand Up @@ -211,12 +211,24 @@ frame:SetScript("OnShow", function(frame)
Refresh()


frame:EnableMouseWheel()
frame:SetScript("OnMouseWheel", function(self, val)
offset = math.max(math.min(offset - math.floor(val*#rows/2), NUMADDONS-#rows), 0)
local scrollbar = LibStub("tekKonfig-Scroll").new(frame, nil, #rows/2)
scrollbar:ClearAllPoints()
scrollbar:SetPoint("TOP", rows[1], 0, -16)
scrollbar:SetPoint("BOTTOM", rows[#rows], 0, 16)
scrollbar:SetPoint("RIGHT", -16, 0)
scrollbar:SetMinMaxValues(0, NUMADDONS-#rows)
scrollbar:SetValue(0)

local f = scrollbar:GetScript("OnValueChanged")
scrollbar:SetScript("OnValueChanged", function(self, value, ...)
offset = value
Refresh()
return f(self, value, ...)
end)

frame:EnableMouseWheel()
frame:SetScript("OnMouseWheel", function(self, val) scrollbar:SetValue(scrollbar:GetValue() - val*#rows/2) end)


local enableall = MakeButton()
enableall:SetPoint("BOTTOMLEFT", 16, 16)
Expand Down
1 change: 1 addition & 0 deletions Ampere.toc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
## X-LoadOn-Always: delayed

LibStub.lua
tekKonfigScroll.lua
tekKonfigAboutPanel.lua
CallbackHandler-1.0.lua
LibDataBroker-1.1\LibDataBroker-1.1.lua
Expand Down
80 changes: 80 additions & 0 deletions tekKonfigScroll.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@

local lib, oldminor = LibStub:NewLibrary("tekKonfig-Scroll", 2)
if not lib then return end

lib.bg = {
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tile = true,
tileSize = 16,
edgeSize = 12,
insets = { left = 0, right = 0, top = 5, bottom = 5 }
}

-- Creates a scrollbar
-- Parent is required, offset and step are optional
function lib.new(parent, offset, step)
local f = CreateFrame("Slider", nil, parent)
f:SetWidth(16)

f:SetPoint("TOPRIGHT", 0 - (offset or 0), -16 - (offset or 0))
f:SetPoint("BOTTOMRIGHT", 0 - (offset or 0), 16 + (offset or 0))

local up = CreateFrame("Button", nil, f)
up:SetPoint("BOTTOM", f, "TOP")
up:SetWidth(16) up:SetHeight(16)
up:SetNormalTexture("Interface\\Buttons\\UI-ScrollBar-ScrollUpButton-Up")
up:SetPushedTexture("Interface\\Buttons\\UI-ScrollBar-ScrollUpButton-Down")
up:SetDisabledTexture("Interface\\Buttons\\UI-ScrollBar-ScrollUpButton-Disabled")
up:SetHighlightTexture("Interface\\Buttons\\UI-ScrollBar-ScrollUpButton-Highlight")

up:GetNormalTexture():SetTexCoord(1/4, 3/4, 1/4, 3/4)
up:GetPushedTexture():SetTexCoord(1/4, 3/4, 1/4, 3/4)
up:GetDisabledTexture():SetTexCoord(1/4, 3/4, 1/4, 3/4)
up:GetHighlightTexture():SetTexCoord(1/4, 3/4, 1/4, 3/4)
up:GetHighlightTexture():SetBlendMode("ADD")

up:SetScript("OnClick", function(self)
local parent = self:GetParent()
parent:SetValue(parent:GetValue() - (step or parent:GetHeight()/2))
PlaySound("UChatScrollButton")
end)

local down = CreateFrame("Button", nil, f)
down:SetPoint("TOP", f, "BOTTOM")
down:SetWidth(16) down:SetHeight(16)
down:SetNormalTexture("Interface\\Buttons\\UI-ScrollBar-ScrollDownButton-Up")
down:SetPushedTexture("Interface\\Buttons\\UI-ScrollBar-ScrollDownButton-Down")
down:SetDisabledTexture("Interface\\Buttons\\UI-ScrollBar-ScrollDownButton-Disabled")
down:SetHighlightTexture("Interface\\Buttons\\UI-ScrollBar-ScrollDownButton-Highlight")

down:GetNormalTexture():SetTexCoord(1/4, 3/4, 1/4, 3/4)
down:GetPushedTexture():SetTexCoord(1/4, 3/4, 1/4, 3/4)
down:GetDisabledTexture():SetTexCoord(1/4, 3/4, 1/4, 3/4)
down:GetHighlightTexture():SetTexCoord(1/4, 3/4, 1/4, 3/4)
down:GetHighlightTexture():SetBlendMode("ADD")

down:SetScript("OnClick", function(self)
local parent = self:GetParent()
parent:SetValue(parent:GetValue() + (step or parent:GetHeight()/2))
PlaySound("UChatScrollButton")
end)

f:SetThumbTexture("Interface\\Buttons\\UI-ScrollBar-Knob")
local thumb = f:GetThumbTexture()
thumb:SetWidth(16) thumb:SetHeight(24)
thumb:SetTexCoord(1/4, 3/4, 1/8, 7/8)

f:SetScript("OnValueChanged", function(self, value)
local min, max = self:GetMinMaxValues()
if value == min then up:Disable() else up:Enable() end
if value == max then down:Disable() else down:Enable() end
end)

local border = CreateFrame("Frame", nil, f)
border:SetPoint("TOPLEFT", up, -5, 5)
border:SetPoint("BOTTOMRIGHT", down, 5, -3)
border:SetBackdrop(lib.bg)
border:SetBackdropBorderColor(TOOLTIP_DEFAULT_COLOR.r, TOOLTIP_DEFAULT_COLOR.g, TOOLTIP_DEFAULT_COLOR.b, 0.5)

return f, up, down, border
end

0 comments on commit 5ea22dd

Please sign in to comment.