OptionHouse/Widgets

This page is dedicated to example widgets for OptionHouse. There will also be code for easily making the code work with your options.

This code block provides RegisterCheckOption and RegisterSliderOption which take a get, set, and help function. The get function just returns what the value should be for the widget (checked or SetValue status), set is called whenever the value of the widget changes. Finally the option help function is called when the widget is moused-over. The mouse-over action is actually delayed to behave more like other UI elements outside of WoW. The code doesn't do any error checking so as such it is only provided as is. It has been pointed out that the behavior for the tooltips when using the help function is not the default in wow. As such, you can just set the tooltipText and not provide a help function to Register*Option, this will force the default behavior of the widgets os defined in the CreateCheckButton and CreateSlider. local RegisterCheckOption, RegisterSliderOption do -- put everything in a do..end block to make it private -- this could be any frame you want it to be you don't need the OnUpdate function for -- and will be shown with your options. local visFrame = CreateFrame("Frame") local helps = {} -- for storing help stuff -- timeout is how long before we forget we were showing, timeToShow is how -- long before we actually show, these values seem fairly sane local timeOut, timeToShow = 2.0, 0.5 local totalElapsed, showTooltip, state = 0 local onUpdate = function(frame, elapsed) totalElapsed = totalElapsed + elapsed if showTooltip then if totalElapsed > timeToShow and state == 1 then -- actually show stuff helps[showTooltip](showTooltip) state = 2 totalElapsed = 0 end -- we need to reshow the tooltip quickly if totalElapsed < timeOut and state == 2 then helps[showTooltip](showTooltip) state = 2 totalElapsed = 0 end else if totalElapsed > timeOut then -- reset our timeout state = 1 visFrame:SetScript("OnUpdate", nil) end end end local registerHelp = function(frame, helpFunc) helps[frame] = helpFunc end local showHelp = function(frame) showTooltip = frame totalElapsed = 0 if state ~= 2 then state = 1 end if visFrame then visFrame:SetScript("OnUpdate", onUpdate) end end local hideHelp = function totalElapsed = 0 showTooltip = nil state = 2 GameTooltip:Hide end RegisterCheckOption = function(frame, get, set, help) frame:SetScript("OnClick", function(self) set(self:GetChecked or false) end ) frame:SetScript("OnShow", function(self) self:SetChecked(get) end ) if help then registerHelp(frame, help) frame:SetScript("OnEnter", showHelp) frame:SetScript("OnLeave", hideHelp) end end RegisterSliderOption = function(frame, get, set, help) frame:SetScript("OnValueChanged", function(self) set(self:GetValue) end ) frame:SetScript("OnShow", function(self) self:SetValue(get) end ) if help then registerHelp(frame, help) frame:SetScript("OnEnter", showHelp) frame:SetScript("OnLeave", hideHelp) end end end

CheckBox
This checkbox is a nameless replica of the OptionsCheckBoxTemplate as seen here. local function CreateCheckButton(par) local f = CreateFrame('CheckButton', nil, par) f:SetHeight(32) f:SetWidth(32) f.text = f:CreateFontString(nil, nil, "GameFontNormalSmall") f.text:SetPoint("LEFT", f, "RIGHT", -2, 0) local t = f:CreateTexture f:SetNormalTexture("Interface\\Buttons\\UI-CheckBox-Up") f:SetPushedTexture("Interface\\Buttons\\UI-CheckBox-Down") f:SetHighlightTexture("Interface\\Buttons\\UI-CheckBox-Highlight") f:GetHighlightTexture:SetBlendMode("ADD") f:SetCheckedTexture("Interface\\Buttons\\UI-CheckBox-Check") f:SetDisabledCheckedTexture("Interface\\Buttons\\UI-CheckBox-Check-Disable") f:SetHitRectInsets(0, -100, 0, 0) f:SetScript("OnEnter", function(self)		if self.tooltipText then			GameTooltip:SetOwner(this, "ANCHOR_RIGHT")			GameTooltip:SetText(this.tooltipText, nil, nil, nil, nil, 1)		end		if self.tooltipRequirement then			GameTooltip:AddLine(this.tooltipRequirement, "", 1.0, 1.0, 1.0)			GameTooltip:Show		end	end ) f:SetScript("OnLeave", function(self) GameTooltip:Hide end) return f end

Slider
This function returns a frame that is a nameless replica of the OptionsSliderTemplate provided by Blizzard. local bg = { bgFile = "Interface\\Buttons\\UI-SliderBar-Background", edgeFile = "Interface\\Buttons\\UI-SliderBar-Border", tile = true, tileSize = 8, edgeSize = 8, insets = { left = 3, right = 3, top = 6, bottom = 6 } } local function CreateSlider(par) local f = CreateFrame('Slider', nil, par) f:SetBackdrop(bg) f:SetWidth(128) f:SetHeight(17) f:SetOrientation("HORIZONTAL") f:SetHitRectInsets(0, 0, -10, -10) local fs = f:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall") fs:SetPoint('BOTTOM', f, "TOP", 0, 2) f.text = fs	fs = f:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall") fs:SetPoint("TOPLEFT", f, "BOTTOMLEFT", 2, 3) f.low = fs	fs = f:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall") fs:SetPoint("TOPRIGHT", f, "BOTTOMRIGHT", -2, 3) f.high = fs	local text = f:CreateTexture text:SetTexture("Interface\\Buttons\\UI-SliderBar-Button-Horizontal") text:SetHeight(32) text:SetWidth(32) f:SetThumbTexture(text) f.thumb = text f:SetScript("OnEnter", function(self)		if self.tooltipText then			GameTooltip:SetOwner(this, "ANCHOR_RIGHT")			GameTooltip:SetText(this.tooltipText, nil, nil, nil, nil, 1)		end		if self.tooltipRequirement then			GameTooltip:AddLine(this.tooltipRequirement, "", 1.0, 1.0, 1.0)			GameTooltip:Show		end	end ) f:SetScript("OnLeave", function(self) GameTooltip:Hide end) return f end