Thread Tools Display Modes
04/25/14, 08:00 AM   #1
meaghs
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 5
Set colour of font

Hiya all

In my addon I am pushing a string to my label like so:
STAddonLabelHTD:SetText(string.format("%s for %d", someString, someNumber))

and then label ends up something like this:

<Controls>
<Label name="$(parent)LabelHTD" font="ZoFontGameMedium" wrapMode="ELLIPSIS" verticalAlignment="CENTER" text="HTD">
<Anchor point="LEFT" offsetX="5" offsetY="-20" />
</Label>
</Controls>

I would like to change the colour of my label or text based on the someNumber. For example, if someNumber is lt 20 then the text would display green, if it is more than twenty it would be red. What is the most efficient (and easiest as i'm a lazy programmer) way to go about this?

thanks! - M.
  Reply With Quote
04/25/14, 08:23 AM   #2
Ak0
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 20
I might as well give it a try

Code:
if someNumber <= 20 then -- If someNumber is less than or equal to 20
    STAddonLabelHTD:SetColor(0,1,0,1) -- Set the color to green
else -- If someNumber is anything else (e.g 21 and up)
    STAddonLabelHTD:SetColor(1,0,0,1) -- Set the color to red
end
Without checking I believe that should do it.

Last edited by Ak0 : 04/26/14 at 05:13 AM. Reason: Changed 255 to 1 because I'm dumb :)
  Reply With Quote
04/25/14, 10:04 AM   #3
Stormknight
 
Stormknight's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 128
Also not at my PC, but from memory, the SetColor method takes values from zero to one, so:

:SetColor(0,1,0,1)
  Reply With Quote
04/25/14, 02:01 PM   #4
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 648
That would be 255/255 to == 1. If a number is higher than 1, it just changes it to 1. If a number is lower than 0, it just changes it to 0.

Otherwise, how would the client know the difference between 1 (for out of 255) and just 1 (for out of 0-1)?
  Reply With Quote
04/25/14, 05:11 PM   #5
meaghs
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 5
tyvm all

You saved me alot of time looking through the API... i'm loling at how close my title is to the solution.
  Reply With Quote

ESOUI » Developer Discussions » General Authoring Discussion » Set colour of font


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