Custom Scripts
I'm not very experience in callbacks, but is it possible to create a custom scripts for a frame which will get triggered just like the "OnShow"/"OnHide" ones but i manage what will trigger them?
|
If I understand you correctly, you're looking to create custom events?
|
Well. The only events you can rely on are the events provided by the API.
If there is no event in the API that is triggering whatever you need to ask for you can fall back to an OnUpdate script checking stuff every now and then. And there is :HookScript. http://www.wowwiki.com/API_Frame_HookScript |
You can fire custom events using AceEvent-3.0 or even simpler with Callbackhandler-1.0
|
I have a total custom dropdown, each time the user changes it's value, i would like to update it's propesions, however there are more dropdowns created by the same template, so i need something like the OnValueChanged script for sliders.
The only workaround i managed to pull out, is to hide/show a totally irrelevant invisible frame and listen it's OnShow/OnHide. But it's sounds like a pretty dumb solution. |
Well, if you only need one event handler for one frame's event, it's simple to do it , just add one method to your frame, like :
Lua Code:
|
Quote:
|
@Resike
Here is what I do on my dropdowns. Lua Code:
https://code.google.com/p/rothui/sou.../panel.lua#292 A dropdown item has the "func" attribute. It is called oncllick. I set that to my click handler. So basically what I do in my template function is this. Lua Code:
|
Quote:
|
My code looks like this, and i would like to replace the "OnHide" part:
Lua Code:
|
So what do you guys thing about it? It easy to use, no taints, very compact and goes easy on the resources too.
https://github.com/Resike/MoveAnythi...s/DropDown.lua I need to come up with a better idea about the :RefreshList() tho. |
Well:
Code:
function DropDown:CreateDropDown(frame, parent, list) Code:
function DropDown:CreateDropDown(parent, list) 1) You're creating a lot of duplicate copies of all your script handler functions. If you have 5 dropdowns that each have 10 list items, you've created 200 functions, plus another 30 functions every time you call your RefreshList function, where you only needed to create 16 total functions regardless of the number of dropdowns or items. Define each of those functions once, outside of the CreateDropDown function, and then refer to them inside, just like you did with your Fire function. 2) If you have a dropdown with 10 list items, then you're creating 10 frames when you create the dropdown, then another 10 frames every time you call RefreshList. You should be reusing those frames instead. Also, there is absolutely no benefit to upvaluing any of these things: Code:
local table = table ---------- I don't really feel like rewriting your code for you right now, but you may find something useful in here: https://github.com/phanx/PhanxConfig...ngDropdown.lua |
Quote:
Quote:
|
Quote:
Code:
buttons = { |
The sort func should be returning the result of the comparison, though. :D
|
Quote:
|
Quote:
|
All times are GMT -6. The time now is 05:07 PM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI