View Single Post
03/29/15, 08:31 PM   #6
circonian
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 613
It looks like you need something like this:

Whenever you update the clock, you could adjust the width of the control:
Lua Code:
  1. -- Grab the text width of the clock label & set the clock controls width with it
  2. -- (since the label autofills to the size of the clock, your also adjusting the
  3. -- size of the label control at the same time)
  4. local clockWidth = NM_SystemBarWinClockLabel:GetTextWidth()
  5. NM_SystemBarWinClock:SetWidth(clockWidth)


Whenever you update the fps, you could adjust the width of the control:
Lua Code:
  1. -- Grab the text width of the fps label & set the fps controls width with it
  2. -- (since the label autofills to the size of the fps control, your also adjusting
  3. -- the size of the label control at the same time)
  4. local fpsWidth = NM_SystemBarWinFpsLabel:GetTextWidth()
  5. NM_SystemBarWinFps:SetWidth(fpsWidth)

Whenever you update the latency, you could adjust the width of the control:
Lua Code:
  1. -- Grab the text width of the latency label & set the latency controls width with it,
  2. -- But you also have to include the width of the icon, since the latency control includes
  3. -- the latency icon and the latency label.
  4. -- In this one since the latency label does NOT autofill to the size of the latency
  5. -- control, so we should also update the latency labels width.
  6. local latencyWidth = NM_SystemBarWinLatencyLabel:GetTextWidth()
  7. NM_SystemBarWinLatencyLabel:SetWidth(latencyWidth)
  8. NM_SystemBarWinLatency:SetWidth(latencyWidth+latencyIconWidth)
Whenever you update the gold amount, you could adjust the width of the control:
Lua Code:
  1. -- Grab the text width of the gold label & set the gold controls width with it,
  2. -- But you also have to include the width of the gold icon, since the gold control includes
  3. -- the gold icon and the gold label.
  4. -- In this one since the gold label does NOT autofill to the size of the gold
  5. -- control, so we should also update the gold labels width.
  6. local goldWidth = NM_SystemBarWinGoldLabel:GetTextWidth()
  7. NM_SystemBarWinGoldLabel:SetWidth(goldWidth)
  8. NM_SystemBarWinGold:SetWidth(goldWidth+goldIconWidth)

Do note that since were resizing the controls to the exact width of the text, this means they wont have any space in between each of the controls. You will probably need to add some padding in between them somehow. We could do it by adding padding to the width of the control (like I wrote in my last reply), but then the labels would not be centered inside of its parent control and we would have to mess with the xml anchors offsetX to center it.

So instead I would just handle the padding in the xml acnhors using offsetX.
Before you had some negative values for your offsetX, but that was because you were keeping a static width for the controls (which was probably to big) so you were using a negative offsetX to overlap the controls to remove some of that gap. Since were resizing our controls to the exact size of its contents that would cause the icons/text to overlap. We need positive values now, probably somewhere between 10-20 for the offsetX value would be my guess.
xml Code:
  1. <Control name="$(parent)Fps" mouseEnabled="true">
  2.     <Dimensions x="80" y="40"/>
  3.     -- Add an offsetX value to create space in between the controls
  4.     <Anchor point="LEFT" relativeTo="$(parent)Clock" relativePoint="RIGHT" offsetX="10"/>
  5. ...
  6.  
  7.  
  8. <Control name="$(parent)Latency" mouseEnabled="true">
  9.     <Dimensions x="80" y="40"/>
  10.     -- Add an offsetX value to create space in between the controls
  11.     <Anchor point="LEFT" relativeTo="$(parent)Fps" relativePoint="RIGHT" offsetX="10"/>
  12. ...
  13.  
  14. <Control name="$(parent)Gold" mouseEnabled="true">
  15.     <Dimensions x="80" y="40"/>
  16.     -- Add an offsetX value to create space in between the controls
  17.     <Anchor point="LEFT" relativeTo="$(parent)Latency" relativePoint="RIGHT" offsetX="10"/>
  18. ...

Lastly....although I said I would handle the padding (space for in between the controls) in the anchors offsetX. From writing my own clock I know that there are some other factors that can affect the width of the text, like the font. I "don't think" that GetTextWidth() takes that into account when calculating the width, because when I wrote my clock, with adjustable fonts/sizes, I had to actually vary the size of the control by adding padding based on what font/sizes I was using. The point is, you may still have to add a small amount of padding to those control widths, but it shouldn't take very much.

Last edited by circonian : 03/29/15 at 08:41 PM.
  Reply With Quote