WoW:UIOBJECT CheckButton: Difference between revisions

No edit summary
Line 1: Line 1:
{{wikify}}
{{wikify}}
== Making Checkboxes ==


You can make a checkbox in WoW via the following commands:
You can make a checkbox in WoW via the following commands:
Line 23: Line 25:




Set up what happens when you click the checkbox. You can add other scripts similarly to how I have this one, you just need to change the "OnClick" to whatever else. http://www.wowwiki.com/Category:Widget_event_handlers
Set up what happens when you click the checkbox. You can add other scripts similarly to how I have this one, you just need to change the "OnClick" to whatever else. http://www.wowwiki.com/Category:Widget_event_handlers Note that you cannot pass arguments to the "OnClick" script's function, but you can do other things as in a normal function
  myCheckButton:SetScript("OnClick",  
  myCheckButton:SetScript("OnClick",  
   function()
   function()
     --do stuff
     --do stuff
   end);
   end);
== Example entirely in Lua ==
myCheckButton = CreateFrame("CheckButton", "myCheckButton_GlobalName", UIParent, "ChatConfigCheckButtonTemplate");
myCheckButton:SetPoint("TOPLEFT", 200, -65);
myCheckButton_GlobalNameText:SetText("CheckBox Name");
myCheckButton.tooltip = "This is where you place MouseOver Text.";
myCheckButton:SetScript("OnClick",
  function()
    --do stuff
  end
);
== Recommendation ==
However, I recommend creating a generic "checkbox-factory function", like this:
local uniquealyzer = 1;
function createCheckbutton(parent, x_loc, y_loc, displayname)
uniquealyzer = uniquealyzer + 1;
local checkbutton = CreateFrame("CheckButton", "my_addon_checkbutton_0" .. uniquealyzer, parent, "ChatConfigCheckButtonTemplate");
checkbutton:SetPoint("TOPLEFT", x_loc, y_loc);
getglobal(checkbutton:GetName() .. 'Text'):SetText(displayname);
return checkbutton;
end
-- this is how you'd use it
myCheckButton = bw_addon.createCheckbutton(UIParent, 400, -600 "A Checkbox");
myCheckButton.tooltip = "If this is checked, nothing will happen, because this is a demo checkbox.";
myCheckButton:SetScript("OnClick",
    function()
      -- do stuff
    end
);
My reason for recommending this is that it is easy to port the checkbox code into a new addon, and it is also a lot more compact (3 lines per checkbox, instead of 6). Also, it is harder to make copy/pasta mistakes with a checkbox-factory.
Anonymous user