Thread Tools Display Modes
12/05/16, 05:37 PM   #1
dorrino
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 50
Tooltip text alignment

Hello, this is probably an easy question, but it feels like the solution is a bit over my level of knowledge

I want to add a custom tooltip onMouseEnter for my control (a label, shouldn't matter though).

I sucessfully added the tooltip, now i want to have a vertical list of text strings in it (approx the same length~<=20).

If i use ZO_Tooltips_ShowTextTooltip i'm getting all the text strings with center alignment and i can't figure out how to make them aligned to the left.

ZO_Tooltips_ShowTextTooltip uses AddLine method. I tried to make a custom function and call AddLine as:

Lua Code:
  1. InformationTooltip:AddLine(line, "", 1,1,1, LEFT, MODIFY_TEXT_TYPE_NONE, TEXT_ALIGN_LEFT, true)

It works, but now the tooltip has a fixed width that is way higher that i would like.

Making the last property to false (or nil) makes the tooltip adjust its width to the content, but reverts the alignment to center.

How can i get the tooltip to adjust its width while making the text entries there left-aligned?

ZO_Tooltips_ShowTextTooltip does perfectly what i need besides of the alignment part.

Thank you
  Reply With Quote
12/06/16, 06:15 AM   #2
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,566
ZO_Tooltips_ShowTextTooltip also just calls AddLine:
Lua Code:
  1. function ZO_Tooltips_ShowTextTooltip(control, side, ...)
  2.     if side == nil then
  3.         InitializeTooltip(InformationTooltip)
  4.         ZO_Tooltips_SetupDynamicTooltipAnchors(InformationTooltip, control)
  5.     else
  6.         InitializeTooltip(InformationTooltip, control, SIDE_TO_TOOLTIP_SIDE[side], OFFSETS_X[side], OFFSETS_Y[side])
  7.     end
  8.  
  9.     for i = 1, select("#", ...) do
  10.         local line = select(i, ...)
  11.         InformationTooltip:AddLine(line, "", ZO_TOOLTIP_DEFAULT_COLOR:UnpackRGB())
  12.     end
  13. end

The last parameter of AddLine is called setToFullSize:
AddLine(string text, string font, number r, number g, number b, AnchorPosition lineAnchor, ModifyTextType modifyTextType, TextAlignment textAlignment, bool setToFullSize)
My guess is, that you need to add an element that is wider than your text in order for text alignment to work when you have setToFullSize set to false. Try adding a line of whitespaces.
You could also try to set a width constraint and setToFullSize, but you should only do that if you have created the tooltip control yourself (never on the built in InformationTooltip and others).
  Reply With Quote
06/11/20, 06:33 AM   #3
remosito
AddOn Author - Click to view addons
Join Date: Dec 2019
Posts: 30
Originally Posted by sirinsidiator View Post
You could also try to set a width constraint and setToFullSize, but you should only do that if you have created the tooltip control yourself (never on the built in InformationTooltip and others).
Some serious necro I know.

But somebody else googling around for tooltip text alignment or width might end up here....

So...

Lua Code:
  1. --inside mouseenter function
  2. local minX, minY, maxX, maxY = InformationTooltip:GetDimensionConstraints()
  3. OrigToolTipMaxX = maxX
  4. InformationTooltip:SetDimensionConstraints(minX, minY, 500, maxY)
  5.  
  6. --inside mouseexit function
  7. if OrigToolTipMaxX ~= nil then
  8.     InformationTooltip:SetDimensionConstraints(minX, minY, RDL.OrigToolTipMaxX, maxY)
  9. end

.... is a bad idea?

(Apart from using 500 instead of a constant/variable )

is setting it back to before value even needed?
Or will initialize on the next tooltip just set it to previous defaults anyway?

(better save than sorry, so I just put it in)

Last edited by remosito : 06/11/20 at 06:38 AM.
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Tooltip text alignment

Thread Tools
Display Modes

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