Adding colors to labels constructor?

Geyser is an object oriented framework for creating, updating and organizing GUI elements within Mudlet.
Post Reply
User avatar
Vadi
Posts: 5035
Joined: Sat Mar 14, 2009 3:13 pm

Adding colors to labels constructor?

Post 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.

guy
Posts: 26
Joined: Wed Mar 03, 2010 5:41 am
Location: Seattle

Re: Adding colors to labels constructor?

Post 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.

User avatar
Vadi
Posts: 5035
Joined: Sat Mar 14, 2009 3:13 pm

Re: Adding colors to labels constructor?

Post 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.

guy
Posts: 26
Joined: Wed Mar 03, 2010 5:41 am
Location: Seattle

Re: Adding colors to labels constructor?

Post 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.

User avatar
Vadi
Posts: 5035
Joined: Sat Mar 14, 2009 3:13 pm

Re: Adding colors to labels constructor?

Post by Vadi »

Ah yes, that did it. Thanks.

Post Reply