Thread Tools Display Modes
10/03/14, 05:23 PM   #1
Argusus
AddOn Author - Click to view addons
Join Date: Sep 2014
Posts: 120
Clickable Item Link in Window

Hello,

i'm outputting some item links as the "text" of a label GUI object, the text is showing but its clickable like a link is. I would like to display as a clickable item so I get the default "popup" window that item links have. is there a special syntax i have to use in order to get the text to be clickable in my labels text?
  Reply With Quote
10/03/14, 06:59 PM   #2
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
I believe that it's not possible to make part of the text on the label clickable. However you can add event handlers to the label, so whole label can show tooltip or handle clicks the same way as links in the chat window. If you want just a part of the text clickable, you will need to use text buffer control instead of the label control.

How to make your label clickable (in Lua):
Lua Code:
  1. --get some link to work with
  2. local itemLink = GetItemLink(BAG_WORN, EQUIP_SLOT_MAIN_HAND, LINK_STYLE_DEFAULT)
  3. --create top level window (label must have some top level window as a parent, otherwise label won't be visible)
  4. local tlw = WINDOW_MANAGER:CreateTopLevelWindow()
  5. --create label
  6. local label = WINDOW_MANAGER:CreateControl(nil, tlw, CT_LABEL)
  7. --set some big font
  8. label:SetFont("ZoFontAnnounceMedium")
  9. --set label text
  10. label:SetText(itemLink)
  11. --set label dimensions to fit text size
  12. label:SetDimensions(label:GetTextWidth(), label:GetTextHeight())
  13. --set label anchor to the middle of the screen
  14. label:SetAnchor(CENTER, GuiRoot, CENTER, 0, 0)
  15. --make label visible
  16. label:SetHidden(false)
  17.  
  18. --enable mouse events for label:
  19. label:SetMouseEnabled(true)
  20.  
  21. --set handler for mouse enter:
  22. label:SetHandler("OnMouseEnter", function(self)
  23.         InitializeTooltip(ItemTooltip, self, BOTTOMLEFT, 0, 0)
  24.         ItemTooltip:SetLink(self:GetText())
  25.     end)
  26.  
  27. --set handler for mouse exit:
  28. label:SetHandler("OnMouseExit", function(self)
  29.         ClearTooltip(ItemTooltip)
  30.     end)
  31.  
  32. --set handler for mouse click (actually this event is fired when mouse button is released, argument upInside indicated if button was released when cursor is still inside of the control):
  33. label:SetHandler("OnMouseUp", function(self, button, upInside, ctrl, alt, shift, command)
  34.         if upInside then
  35.             ZO_LinkHandler_OnLinkClicked(self:GetText(), button, self)
  36.         end
  37.     end)

The same code in XML:
xml Code:
  1. <GuiXml>
  2.     <Controls>
  3.         <TopLevelControl>
  4.             <Controls>
  5.                 <Label font="ZoFontAnnounceMedium" mouseEnabled="true">
  6.                     <Anchor point="CENTER" relativeTo="GuiRoot" />
  7.                     <OnInitialized>
  8.                         local itemLink = GetItemLink(BAG_WORN, EQUIP_SLOT_MAIN_HAND, LINK_STYLE_DEFAULT)
  9.                         self:SetText(itemLink)
  10.                         self:SetDimensions(self:GetTextWidth(), self:GetTextHeight())
  11.                     </OnInitialized>
  12.  
  13.                     <OnMouseEnter>
  14.                         InitializeTooltip(ItemTooltip, self, BOTTOMLEFT, 0, 0)
  15.                         ItemTooltip:SetLink(self:GetText())
  16.                     </OnMouseEnter>
  17.  
  18.                     <OnMouseExit>
  19.                         ClearTooltip(ItemTooltip)
  20.                     </OnMouseExit>
  21.  
  22.                     <OnMouseUp>
  23.                         if upInside then
  24.                             ZO_LinkHandler_OnLinkClicked(self:GetText(), button, self)
  25.                         end
  26.                     </OnMouseUp>
  27.                 </Label>
  28.             </Controls>
  29.         </TopLevelControl>
  30.     </Controls>
  31. </GuiXml>

Last edited by Garkin : 10/03/14 at 07:33 PM.
  Reply With Quote
10/04/14, 01:41 PM   #3
Argusus
AddOn Author - Click to view addons
Join Date: Sep 2014
Posts: 120
great, thanks again! do you have any example of the text buffer control ?
  Reply With Quote

ESOUI » AddOns » AddOn Help/Support » Clickable Item Link in Window


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