Page 1 of 1

Adding colors to labels constructor?

Posted: Mon Mar 15, 2010 6:18 pm
by Vadi
I think it would be useful if we could set the default label color at creation - ie, supply the r,g,b and a args to the table.

Re: Adding colors to labels constructor?

Posted: Mon Mar 15, 2010 10:08 pm
by guy
You can.
Code: [show] | [select all] lua
l = Geyser.Label:new({x="50%",y="10px",width="80px",height="20px",backgroundColor={r=90,b=255,g=23}})
does the trick. Any parameter that's specified in the constraints table will be copied over to the new object. So you could have arbitrary values in there that you want the new label/console/whatever to also contain - the power of prototyping! Anyway, specific things like backgroundColor and such that constructors are aware of are (should be) applied by the constructor at creation time.

Re: Adding colors to labels constructor?

Posted: Tue Mar 16, 2010 2:32 am
by Vadi
Hm, that doesn't quite work out -
Code: [show] | [select all] lua
ofn_ui_target = Geyser.Label:new({
  name = "ofn_ui_target",
  x = 0, y = 0,
  width = "100%", height = "100%",
  backgroundColor={r=0, b=0, g=0, a=0}},
  ofn_ui_target_pic))
isn't the same as
Code: [show] | [select all] lua
ofn_ui_target = Geyser.Label:new({
  name = "ofn_ui_target",
  x = 0, y = 0,
  width = "100%", height = "100%",
  backgroundColor={r=0, b=0, g=0, a=0}},
  ofn_ui_target_pic)
ofn_ui_target:setBackgroundColor(0,0,0,0)
Namely, without the explicit call my label stack dissapears so something is going wrong.

Re: Adding colors to labels constructor?

Posted: Tue Mar 16, 2010 3:55 pm
by guy
I think the problem is coming from the fact that currently backgroundColor doesn't contain alpha information - that is stored in backgroundAlpha, so you'd need to add it explicitly like
Code: [show] | [select all] lua
{x=?,y=? ... , backgroundAlpha=0}
As is, you're creating a totally opaque black label because the a=0 in backgroundColor is just being ignored , which causes the underlying image to appear to disappear.

Re: Adding colors to labels constructor?

Posted: Tue Mar 16, 2010 5:56 pm
by Vadi
Ah yes, that did it. Thanks.