BriGhtx3 Posted January 19, 2012 Share Posted January 19, 2012 I know there is no way to use color codes in labels. But i want to set colors for different texts. I know I can use dxtext but is there no other way? Like creating a display or something like this for a GUI? Ill freak out when someone says you cant use color codes in labels -.- Link to comment
Xeno Posted January 19, 2012 Share Posted January 19, 2012 You can't use colour codes in labels.... (LOL) On topic: Do you mean like: Label text:"wwqdqwd(< this part is red) 438348234829394 ( < this part is green)" ?? Link to comment
Xeno Posted January 19, 2012 Share Posted January 19, 2012 Create two labels, and move it next to the other label. Link to comment
BriGhtx3 Posted January 19, 2012 Author Share Posted January 19, 2012 Lol I knew that but it is very difficult to create 100 labels -.- And the users add the texts via color codes. Link to comment
Blaawee Posted January 20, 2012 Share Posted January 20, 2012 i don't know mybe this will work : https://wiki.multitheftauto.com/wiki/GuiSetProperty guiSetProperty(label, "labelTextColour", "FFA0A0A0") Link to comment
50p Posted January 20, 2012 Share Posted January 20, 2012 i don't know mybe this will work :https://wiki.multitheftauto.com/wiki/GuiSetProperty guiSetProperty(label, "labelTextColour", "FFA0A0A0") That would change the label colour, same as guiLabelSetColor. Lol I knew that but it is very difficult to create 100 labels -.- And the users add the texts via color codes. Just create a function which will create as many labels as many colours you have in the string. There is a similar function for DX text on the forum somewhere, just search the forum, I'm sure you'll find it easily. Then just modify the function to work GUI labels instead of DX text. Link to comment
UAEpro Posted January 20, 2012 Share Posted January 20, 2012 easy the original code was for dxdrawcolortext and i made this for colored label --- by UAEpro function guiCreateColorLabel(ax, ay, bx, by,str, parent, bool) local pat = "(.-)#(%x%x%x%x%x%x)" local s, e, cap, col = str:find(pat, 1) local last = 1 while s do if cap == "" and col then r,g,b = tonumber("0x"..col:sub(1, 2)), tonumber("0x"..col:sub(3, 4)), tonumber("0x"..col:sub(5, 6)) end if s ~= 1 or cap ~= "" then local w = dxGetTextWidth(cap) avc321 = guiCreateLabel(ax, ay, ax + w, by,cap,parent, bool) if r == nil then r = 255 end if g == nil then g = 255 end if b == nil then b = 255 end guiLabelSetColor(avc321,r,g,b) ax = ax + w r,g,b = tonumber("0x"..col:sub(1, 2)), tonumber("0x"..col:sub(3, 4)), tonumber("0x"..col:sub(5, 6)) end last = e + 1 s, e, cap, col = str:find(pat, last) end if last <= #str then cap = str:sub(last) local w = dxGetTextWidth(cap) avc123 = guiCreateLabel(ax, ay, ax + w, by,cap,parent, bool) guiLabelSetColor(avc123,r,g,b) end end Link to comment
BriGhtx3 Posted January 21, 2012 Author Share Posted January 21, 2012 UAepro very nice Code. But you can't use guiSetText with it oO Link to comment
Kenix Posted January 21, 2012 Share Posted January 21, 2012 Yes,because he not returned gui element in function. Link to comment
BriGhtx3 Posted January 21, 2012 Author Share Posted January 21, 2012 How do you mean this? Link to comment
Kenix Posted January 21, 2012 Share Posted January 21, 2012 We can't use return value in function guiCreateColorLabel because is returned value nil. http://lua-users.org/wiki/FunctionsTutorial Understand? Link to comment
BriGhtx3 Posted January 21, 2012 Author Share Posted January 21, 2012 Oh now I understand this. So I have to destroy it and create it again? Link to comment
Kenix Posted January 21, 2012 Share Posted January 21, 2012 Not understand So I have to destroy it and create it again? Link to comment
UAEpro Posted January 22, 2012 Share Posted January 22, 2012 Oh now I understand this. So I have to destroy it and create it again? yes .. that what i do ^.^ Link to comment
drk Posted February 25, 2012 Share Posted February 25, 2012 function guiCreateColorLabel(ax, ay, bx, by,str, bool, parent) local pat = "(.-)#(%x%x%x%x%x%x)" local s, e, cap, col = str:find(pat, 1) local last = 1 while s do if cap == "" and col then r,g,b = tonumber("0x"..col:sub(1, 2)), tonumber("0x"..col:sub(3, 4)), tonumber("0x"..col:sub(5, 6)) end if s ~= 1 or cap ~= "" then local w = dxGetTextWidth(cap) avc321 = guiCreateLabel(ax, ay, ax + w, by,cap,bool,parent) if r == nil then r = 255 end if g == nil then g = 255 end if b == nil then b = 255 end guiLabelSetColor(avc321,r,g,b) ax = ax + w r,g,b = tonumber("0x"..col:sub(1, 2)), tonumber("0x"..col:sub(3, 4)), tonumber("0x"..col:sub(5, 6)) end last = e + 1 s, e, cap, col = str:find(pat, last) end if last <= #str then cap = str:sub(last) local w = dxGetTextWidth(cap) avc123 = guiCreateLabel(ax, ay, ax + w, by,cap,bool,parent) guiLabelSetColor(avc123,r,g,b) return avc123 end end Can anyone help with this Link to comment
drk Posted February 25, 2012 Share Posted February 25, 2012 Sorry for 2 posts but no one want to help? Link to comment
drk Posted February 25, 2012 Share Posted February 25, 2012 function guiCreateColorLabel(ax, ay, bx, by,str, bool, parent) local pat = "(.-)#(%x%x%x%x%x%x)" local s, e, cap, col = str:find(pat, 1) local last = 1 while s do if cap == "" and col then r,g,b = tonumber("0x"..col:sub(1, 2)), tonumber("0x"..col:sub(3, 4)), tonumber("0x"..col:sub(5, 6)) end if s ~= 1 or cap ~= "" then local w = dxGetTextWidth(cap) avc321 = guiCreateLabel(ax, ay, ax + w, by,cap,bool,parent) if r == nil then r = 255 end if g == nil then g = 255 end if b == nil then b = 255 end guiLabelSetColor(avc321,r,g,b) ax = ax + w r,g,b = tonumber("0x"..col:sub(1, 2)), tonumber("0x"..col:sub(3, 4)), tonumber("0x"..col:sub(5, 6)) end last = e + 1 s, e, cap, col = str:find(pat, last) end if last <= #str then cap = str:sub(last) local w = dxGetTextWidth(cap) avc123 = guiCreateLabel(ax, ay, ax + w, by,cap,bool,parent) guiLabelSetColor(avc123,r,g,b) return avc123 end end I get error on guiLabelSetColor(avc123,r,g,b) I know that its because r,g,b is not defined but I don't remember nothing how to solve this '-' Link to comment
Kenix Posted February 25, 2012 Share Posted February 25, 2012 function guiCreateColorLabel( ax, ay, bx, by,str, bool, parent ) local pat = "(.-)#(%x%x%x%x%x%x)" local s, e, cap, col = str:find( pat, 1 ) local last = 1 local r,g,b while s do if cap == "" and col then r,g,b = tonumber( "0x"..col:sub( 1, 2 ) ), tonumber( "0x"..col:sub( 3, 4 ) ), tonumber( "0x"..col:sub( 5, 6 ) ) end if s ~= 1 or cap ~= "" then local w = dxGetTextWidth( cap ) avc321 = guiCreateLabel( ax, ay, ax + w, by,cap,bool,parent ) if not r then r = 255 end if not g then g = 255 end if not b then b = 255 end guiLabelSetColor( avc321,r,g,b ) ax = ax + w r,g,b = tonumber( "0x"..col:sub( 1, 2 ) ), tonumber( "0x"..col:sub( 3, 4 ) ), tonumber( "0x"..col:sub( 5, 6 ) ) end last = e + 1 s, e, cap, col = str:find( pat, last ) end if last <= #str then local cap = str:sub( last ) local w = dxGetTextWidth( cap ) local avc123 = guiCreateLabel( ax, ay, ax + w, by,cap,bool,parent ) guiLabelSetColor( avc123,r or 255,g or 255,b or 255 ) return avc123 end end Link to comment
drk Posted March 3, 2012 Share Posted March 3, 2012 I get no error but It don't work... It appear with color codes. And no colors I tried with: function guiCreateColorLabel ( ax, ay, bx, by, str, relative, parent ) local pat = "(.-)#(%x%x%x%x%x%x)" local s, e, cap, col = str:find(pat, 1) local last = 1 while s do if cap == "" and col then r, g, b = tonumber( "0x"..col:sub( 1, 2 ) ), tonumber( "0x"..col:sub( 3, 4 ) ), tonumber( "0x"..col:sub( 5, 6 ) ) end last = e + 1 s, e, cap, col = str:find( pat, last ) end if r == nil then r = 255 end if g == nil then g = 255 end if b == nil then b = 255 end if last <= #str then cap = str:sub( last ) label = guiCreateLabel ( ax, ay, bx, by, cap, relative, parent ) guiLabelSetColor ( label, r, g, b ) return label end end But I get error on guiLabelSetColor. I don't know why I get expected number, colors don't have to be numbers? oO Link to comment
Cadu12 Posted March 4, 2012 Share Posted March 4, 2012 Line: 18 guiLabelSetColor (label, r or 255, g or 255, b or 255) Is that hard? Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now