Thread Tools Display Modes
03/10/15, 01:53 PM   #1
Dero
 
Dero's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2014
Posts: 14
OnMouseEnter problem

Hey there.
I've got a small problem with a piece of code.

Ive got a MainObject (MainObj) and on MouseEnter a ChildObject (ChildObj) with a Button in it (ChildButton) should show up. -Works fine so far
Now on MouseExit the ChildObject should get hidden again. - Works fine too

Now The Problem:
If i MouseEnter the ChildButton to click it, the MainObj registeres a MouseExit. This leads to a spamming of Hide/Show of the ChildObject. Is there anything i can do about this, so that the ChildObject keeps being open and only hides if i MouseExit the MainObj?


Lua Code:
  1. local MainObj = WINDOW_MANAGER:CreateControl("MainObj",TLW,CT_CONTROL)
  2. MainObj:SetDimensions(200,100)
  3. MainObj:SetAnchor(TOPLEFT,GuiRoot,TOPLEFT,0,0)
  4. MainObj:SetMouseEnabled(true)
  5. MainObj:SetHandler("OnMouseEnter",function()
  6.     ChildObj:SetHidden(true)
  7. end)
  8. MainObj:SetHandler("OnMouseExit",function()
  9.     ChildObj:SetHidden(true)
  10. end)
  11.            
  12. local ChildObj = WINDOW_MANAGER:CreateControl("ChildObj",MainObj,CT_TEXTURE)
  13. ChildObj:SetDimensions(ChildObj:GetParent():GetWidth(),ChildObj:GetParent():GetHeight()/2)
  14. ChildObj:SetAnchor(BOTTOMLEFT,MainObj,BOTTOMLEFT,0,0)
  15. ChildObj:SetTexture("")
  16. ChildObj:SetDrawLayer(4)
  17. ChildObj:SetColor(0,0,0,0.8)
  18. ChildObj:SetHidden(true)
  19.            
  20. local ChildButton = WINDOW_MANAGER:CreateControl("ChildButton",ChildObj,CT_BUTTON)
  21. ChildButton:SetDimensions(ChildButton:GetParent():GetHeight()-5,ChildButton:GetParent():GetHeight()-5)
  22. ChildButton:SetAnchor(LEFT,ChildObj,LEFT,5,0)
  23. ChildButton:SetNormalTexture("")
  24. ChildButton:SetDrawLayer(4)
  25. ChildButton:SetHandler("OnClicked",function()
  26.     d("Clicked")
  27. end)
  Reply With Quote
03/10/15, 02:47 PM   #2
merlight
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 671
There's an undocumented function IsMouseOver(control). I did a quick test and it seems it sees through control hierarchy, so it should return true as long as you move over controls inside the main one:
Lua Code:
  1. MainObj:SetHandler("OnMouseExit",function()
  2.     if not IsMouseOver(MainObj) then
  3.         ChildObj:SetHidden(true)
  4.     end
  5. end)
  Reply With Quote
03/10/15, 04:08 PM   #3
Dero
 
Dero's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2014
Posts: 14
This function does not seem to work. When i use it, i get the following Error:
Code:
function expected instead of nil
stack traceback:
user:/X/X/Test.lua:25 in function '(anonymous)'
so this function seems to be unknown
  Reply With Quote
03/10/15, 04:19 PM   #4
merlight
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 671
Oops, MouseIsOver
  Reply With Quote
03/10/15, 05:26 PM   #5
Dero
 
Dero's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2014
Posts: 14
Yep. found it just a few minutes ago .
Thx a lot! That helped and is working fine!
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » OnMouseEnter problem


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off