Thread Tools Display Modes
Prev Previous Post   Next Post Next
01-04-17, 06:43 PM   #1
gmarco
An Onyxian Warder
 
gmarco's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 362
OnLeave & Frame

Hi,

I was rewriting one of my addons trying to implement a custom frame instead of the standard LDB.

Everything works just fine but I was wondering if it is possible to use an onLeave codition to close it.

The skeleton code is something like this (shorter than the full code):

Lua Code:
  1. local ADDON = ...
  2.  
  3. local Menu = CreateFrame('Frame', nil, UIParent)
  4. Menu:SetClampedToScreen(true)
  5. Menu:SetSize(100,100)
  6. Menu:Hide()
  7. -- Menu:SetScript('OnLeave', OnLeave)
  8. Menu:SetBackdrop({
  9.     bgFile = "Interface/DialogFrame/UI-DialogBox-Background",
  10.     edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
  11.     tile = true, tileSize = 32, edgeSize = 16,
  12.     insets = { left = 5, right = 5, top = 5, bottom = 5 }
  13. })
  14.  
  15. local ldb = LibStub:GetLibrary("LibDataBroker-1.1")
  16. local dataobj = ldb:NewDataObject(ADDON , {
  17.     type = "data source",
  18.     icon = "Interface\\Addons\\"..ADDON.."\\icon.tga",
  19.     text = "Test Only"
  20. })
  21.  
  22. dataobj.OnClick = function(self, button)  
  23.  
  24.     if button == "LeftButton" then
  25.  
  26.         if(Menu:IsShown()) then        
  27.    
  28.             Menu:Hide()
  29.  
  30.         else
  31.            
  32.             -- position code taken from Broker_Equipment by p3lim
  33.             Menu:ClearAllPoints()
  34.             Menu:SetPoint('TOP', self, 'BOTTOM') -- temporary anchor
  35.  
  36.             local sideAnchor = ''
  37.             if(Menu:GetRight() > GetScreenWidth()) then
  38.                 sideAnchor = 'RIGHT'
  39.             elseif(Menu:GetLeft() <= 0) then
  40.                 sideAnchor = 'LEFT'
  41.             end
  42.  
  43.             Menu:ClearAllPoints()
  44.             if(Menu:GetBottom() <= 0) then
  45.                 Menu:SetPoint('BOTTOM' .. sideAnchor, self, 'TOP' .. sideAnchor)
  46.             else
  47.                 Menu:SetPoint('TOP' .. sideAnchor, self, 'BOTTOM' .. sideAnchor)
  48.             end                    
  49.             Menu:Show()
  50.            
  51.         end
  52.        
  53.     end
  54. end

I thought a simple:

Lua Code:
  1. Menu:SetScript('OnLeave', Menu:Hide())

was ok to hide the frame when not hovering on it, but I was wrong

So now I ask:
Is there a simple way to accomplish this and prevent the fact the frame remains open until someone clicks the bar again ?

Thanks very much for your input.

P.s.
Actually the Tooltip is this:

__________________
This is Unix-Land. In quiet nights, you can hear the Windows machines reboot.
  Reply With Quote
 

WoWInterface » Developer Discussions » Lua/XML Help » OnLeave & Frame


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