Thread Tools Display Modes
09-25-16, 08:21 AM   #1
gmarco
An Onyxian Warder
 
gmarco's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 362
Click a line, get reference to the line?

Hi All,

I am trying to figure what to code to permit the click on a single line and get the reference to the line itself.

Lua Code:
  1. local ldb = LibStub:GetLibrary("LibDataBroker-1.1")
  2. local dataobj = ldb:NewDataObject("gmTest", {
  3.     type = "data source",
  4.     icon = "Interface\\Minimap\\Tracking\\Repair",
  5.     text = "test",  
  6. })
  7.  
  8. function dataobj.OnEnter(frame)
  9.  
  10.         GameTooltip:SetOwner(frame, "ANCHOR_BOTTOM")
  11.  
  12.         GameTooltip:AddLine("My Addon")
  13.         GameTooltip:AddLine(" ")
  14.         GameTooltip:AddDoubleLine("foo1",   "bar1")
  15.         GameTooltip:AddDoubleLine("foo2",   "bar2")
  16.         GameTooltip:AddDoubleLine("foo3",   "bar3")
  17.  
  18.         GameTooltip:Show()
  19. end
  20.  
  21. function dataobj.OnLeave(frame)
  22.  
  23.     -- GameTooltip:Hide()
  24.  
  25. end
  26.  
  27. function dataobj.OnClick(frame, button)  
  28.  
  29.     if  button == "RightButton" then  
  30.         GameTooltip:Hide()
  31.     end
  32.    
  33. end

Probably I should change the foo1, foo2, foo3 lines into buttons ?

Thanks to all for attention.
__________________
This is Unix-Land. In quiet nights, you can hear the Windows machines reboot.

Last edited by gmarco : 09-25-16 at 08:25 AM.
  Reply With Quote
09-25-16, 07:05 PM   #2
Torhal
A Pyroguard Emberseer
 
Torhal's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 1,196
You can't (easily) do this with a GameTooltip, which is why most datafeeds that require those capabilities use LibQTip for their tooltips.
__________________
Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Author of NPCScan and many other AddOns.
  Reply With Quote
09-26-16, 12:52 AM   #3
gmarco
An Onyxian Warder
 
gmarco's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 362
LibQTip help

Thanks Thoral for your answer.

I have tried LibQTip some days ago using the sample embedding I found on wowace.

Lua Code:
  1. local LibQTip = LibStub('LibQTip-1.0')
  2. local ldb = LibStub:GetLibrary("LibDataBroker-1.1")
  3.  
  4. local dataobj = ldb:NewDataObject("gmTest", {
  5.     type = "data source",
  6.     icon = "Interface\\Minimap\\Tracking\\Repair",
  7.     text = "test",  
  8. })
  9.  
  10. local function anchor_OnEnter(self)
  11.      
  12.     -- Acquire a tooltip with 3 columns, respectively aligned to left, center and right
  13.     local tooltip = LibQTip:Acquire("FooBarTooltip", 3, "LEFT", "CENTER", "RIGHT")
  14.     self.tooltip = tooltip
  15.  
  16.     -- Add an header filling only the first two columns
  17.     tooltip:AddHeader('Anchor', 'Tooltip')
  18.  
  19.     -- Add an new line, using all columns
  20.     tooltip:AddLine('Hello', 'World', '!')
  21.  
  22.     -- Use smart anchoring code to anchor the tooltip to our frame
  23.     tooltip:SmartAnchorTo(self)
  24.  
  25.     -- Show it, et voilą !
  26.     tooltip:Show()
  27.    
  28. end
  29.  
  30. local function anchor_OnLeave(self)
  31.    
  32.    -- Release the tooltip
  33.    LibQTip:Release(self.tooltip)
  34.    self.tooltip = nil
  35.    
  36. end
  37.  
  38.  
  39. function dataobj.OnClick(frame, button)  
  40.  
  41.      -- empty
  42.  
  43. end
  44.  
  45. function dataobj.OnEnter(frame)
  46.     anchor_OnEnter(frame)
  47. end
  48.  
  49. function dataobj.OnLeave(frame)
  50.     anchor_OnLeave(frame)
  51. end

I use this way of embedding because I don't realize where to put these lines:

Lua Code:
  1. -- Somewhere in the anchor initialization
  2. anchor:SetScript('OnEnter', anchor_OnEnter)
  3. anchor:SetScript('OnLeave', anchor_OnLeave)

Probably I should create a custom frame and adding them ?

Something like ?

Lua Code:
  1. local frame = CreateFrame("Frame")
  2. frame:SetScript('OnEnter', anchor_OnEnter)
  3. frame:SetScript('OnLeave', anchor_OnLeave)

and remove the dataobj.OnEnter and dataobj.OnLeave parts ?

The problem instead is:

If I remove the call anchor_OnLeave when I leave the databroker, I can hover the tooltip (so I can interact and press something on it ... ) but if I trim again the anchor_onEnter it dups the tooltip.

So I tried to use an isShown() to prevent this happening but I can't suceeded.
How I can avoid this ?

Thanks very much to all.
__________________
This is Unix-Land. In quiet nights, you can hear the Windows machines reboot.
  Reply With Quote
09-26-16, 02:25 AM   #4
Torhal
A Pyroguard Emberseer
 
Torhal's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 1,196
In the example, the dataObj is the object returned by LibDataBroker's NewDataObject method. It takes care of all of that. You don't have to use SetScript on anything - literally following the example in the API documentation should get something that works.
__________________
Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Author of NPCScan and many other AddOns.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Click a line, get reference to the line?


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