local function CreateSlider(parent)
local frame = CreateFrame("Slider", nil, parent)
frame:SetSize(200, 17)
frame:EnableMouseWheel(true)
frame:SetHitRectInsets(0, 0, -14, -15)
frame:SetMinMaxValues(0, 100)
frame:SetValue(50)
frame:SetValueStep(1)
frame:SetHitRectInsets(0, 0, 0, 0)
frame:SetObeyStepOnDrag(true)
frame:EnableMouseWheel(true)
frame:SetOrientation("Horizontal")
frame:SetBackdrop({
bgFile = "Interface\\Buttons\\UI-SliderBar-Background",
edgeFile = "Interface\\Buttons\\UI-SliderBar-Border",
tile = true,
edgeSize = 8,
tileSize = 8,
insets = {left = 3, right = 3, top = 6, bottom = 6}
})
frame:SetBackdropBorderColor(0.7, 0.7, 0.7, 1.0)
frame:SetScript("OnEnter", function(self)
self:SetBackdropBorderColor(1, 1, 1, 1)
end)
frame:SetScript("OnLeave", function(self)
self:SetBackdropBorderColor(0.7, 0.7, 0.7, 1.0)
end)
frame:SetScript("OnMouseWheel", function(self, delta)
if delta > 0 then
self:SetValue(self:GetValue() + self:GetValueStep())
else
self:SetValue(self:GetValue() - self:GetValueStep())
end
end)
frame:SetScript("OnValueChanged", function(self, value)
frame.EditBox:SetText(value)
end)
frame.MinLabel = frame:CreateFontString(nil, "Overlay")
frame.MinLabel:SetFontObject(GameFontHighlightSmall)
frame.MinLabel:SetSize(0, 14)
frame.MinLabel:SetWordWrap(false)
frame.MinLabel:SetPoint("TopLeft", frame, "BottomLeft", 0, -1)
local min, max = frame:GetMinMaxValues()
frame.MinLabel:SetText(min)
frame.MaxLabel = frame:CreateFontString(nil, "Overlay")
frame.MaxLabel:SetFontObject(GameFontHighlightSmall)
frame.MaxLabel:SetSize(0, 14)
frame.MaxLabel:SetWordWrap(false)
frame.MaxLabel:SetPoint("TopRight", frame, "BottomRight", 0, -1)
frame.MaxLabel:SetText(max)
frame.Title = frame:CreateFontString(nil, "Overlay")
frame.Title:SetFontObject(GameFontNormal)
frame.Title:SetSize(0, 14)
frame.Title:SetWordWrap(false)
frame.Title:SetPoint("Bottom", frame, "Top")
frame.Title:SetText("Slider")
frame.Thumb = frame:CreateTexture(nil, "Artwork")
frame.Thumb:SetSize(32, 32)
frame.Thumb:SetTexture("Interface\\Buttons\\UI-SliderBar-Button-Horizontal")
frame:SetThumbTexture(frame.Thumb)
frame.EditBox = CreateFrame("EditBox", nil, frame)
frame.EditBox:EnableMouseWheel(true)
frame.EditBox:SetAutoFocus(false)
frame.EditBox:SetNumeric(false)
frame.EditBox:SetJustifyH("Center")
frame.EditBox:SetFontObject(GameFontHighlightSmall)
frame.EditBox:SetSize(50, 14)
frame.EditBox:SetPoint("Top", frame, "Bottom", 0, -1)
frame.EditBox:SetTextInsets(4, 4, 0, 0)
frame.EditBox:SetBackdrop({
bgFile = "Interface\\ChatFrame\\ChatFrameBackground",
edgeFile = "Interface\\ChatFrame\\ChatFrameBackground",
tile = true,
edgeSize = 1,
tileSize = 5
})
frame.EditBox:SetBackdropColor(0, 0, 0, 1)
frame.EditBox:SetBackdropBorderColor(0.2, 0.2, 0.2, 1.0)
frame.EditBox:SetText(frame:GetValue())
--[[frame.EditBox:SetScript("OnShow", function(self)
self:SetText("")
self:SetText(frame:GetValue())
end)]]
if InterfaceOptionsFrame then
InterfaceOptionsFrame:HookScript("OnShow", function(self)
frame.EditBox:SetText("")
frame.EditBox:SetText(frame:GetValue())
end)
end
frame.EditBox:SetScript("OnEnter", function(self)
self:SetBackdropBorderColor(0.4, 0.4, 0.4, 1.0)
end)
frame.EditBox:SetScript("OnLeave", function(self)
self:SetBackdropBorderColor(0.2, 0.2, 0.2, 1.0)
end)
frame.EditBox:SetScript("OnMouseWheel", function(self, delta)
if delta > 0 then
frame:SetValue(frame:GetValue() + frame:GetValueStep())
else
frame:SetValue(frame:GetValue() - frame:GetValueStep())
end
end)
frame.EditBox:SetScript("OnEscapePressed", function(self)
self:ClearFocus()
end)
frame.EditBox:SetScript("OnEnterPressed", function(self)
local value = tonumber(self:GetText())
if value then
local min, max = frame:GetMinMaxValues()
if value >= min and value <= max then
frame:SetValue(value)
elseif value < min then
frame:SetValue(min)
elseif value > max then
frame:SetValue(max)
end
frame.EditBox:SetText(frame:GetValue())
else
frame:SetValue(frame:GetValue())
end
self:ClearFocus()
end)
frame.EditBox:SetScript("OnEditFocusLost", function(self)
self:HighlightText(0, 0)
end)
frame.EditBox:SetScript("OnEditFocusGained", function(self)
self:HighlightText(0, -1)
end)
frame.Plus = CreateFrame("Button", nil, frame)
frame.Plus:SetSize(18, 18)
frame.Plus:RegisterForClicks("AnyUp")
frame.Plus:SetPoint("Left", frame.EditBox, "Right", 0, 0)
frame.Plus:SetNormalTexture("Interface\\Buttons\\UI-SpellbookIcon-NextPage-Up")
frame.Plus:SetPushedTexture("Interface\\Buttons\\UI-SpellbookIcon-NextPage-Down")
frame.Plus:SetHighlightTexture("Interface\\ChatFrame\\UI-ChatIcon-BlinkHilight")
frame.Plus:SetScript("OnClick", function(self)
frame:SetValue(frame:GetValue() + frame:GetValueStep())
end)
frame.Minus = CreateFrame("Button", nil, frame)
frame.Minus:SetSize(18, 18)
frame.Minus:RegisterForClicks("AnyUp")
frame.Minus:SetPoint("Right", frame.EditBox, "Left", 0, 0)
frame.Minus:SetNormalTexture("Interface\\Buttons\\UI-SpellbookIcon-PrevPage-Up")
frame.Minus:SetPushedTexture("Interface\\Buttons\\UI-SpellbookIcon-PrevPage-Down")
frame.Minus:SetHighlightTexture("Interface\\ChatFrame\\UI-ChatIcon-BlinkHilight")
frame.Minus:SetScript("OnClick", function(self)
frame:SetValue(frame:GetValue() - frame:GetValueStep())
end)
return frame
end