XWidgetSoft Forum
https://www.bbs.xwidget.com/

Change colour if text has value xx
https://www.bbs.xwidget.com/viewtopic.php?f=8&t=2581
Page 1 of 1

Author:  jackiD [ February 9th, 2013, 9:44 pm ]
Post subject:  Change colour if text has value xx

Hello everybody,

I created a football table widget, using webparsercore which works fine so far.
Now I would like to highlight my favourite team.

How could I manage that?

Possibilities:
1. Highlight the complete line/layer (all lines are different layers) <- preferred (e.g. different background colour and/or text colour)
2. Highlight only the team name (text colour)

Many thanks in advance.

Author:  Sooner266 [ March 4th, 2013, 11:27 am ]
Post subject:  Re: Change colour if text has value xx

The way I would do it is by putting all the layers in an array, then looping through them checking text.

Code:
layers = [layer1, layer2, layer3];
favoriteTeam = "Patriots";

//after loading the feed or updating favorite team:
for(int i = 0; i < layers.length; i++){
    if(layers[i].text == favoriteTeam){ //or maybe "layers[i].text.indexOf(favoriteTeam) != -1"
        layers[i].Background.SolidColor.Enabled == true;
    } else {
        layers[i].Background.SolidColor.Enabled == false; //removes background from old favorite team layer
    }
}


That code isn't tested, it's just a quick example I wrote while glancing at my own skins.
Hope that helps you.

Author:  jackiDi [ March 5th, 2013, 12:42 am ]
Post subject:  Re: Change colour if text has value xx

Thanks a lot for your reply :)

I've tried your suggestion but could not really manage it, which is probably caused by my lack of JavaScript.
So I created a very simple widget:

layer1
   text1 (="Patriots")
layer2
   text1 (="other Team")

I changed the background colour for both layers to red (but left it disabled).
Then I took your code and copied it into the code window, trying "if(layers[i].text == favoriteTeam)" and "layers[i].text.indexOf(favoriteTeam) != -1".

Now I was expecting, the layer1 background turns to red but that was not the case (for both). :?:

My original widget has this kind of structure (with 2 additional sliders)

matches [layer]
   match1 [layer]
      hometeam
      guestteam
      result
   match2 [layer]
      hometeam
      guestteam
      result
   ...

Sorry for being a bit dummy but could you give me more hints and tell me where is my mistake (in understanding)?
And do I have to create a new function myFavTeam (which has to be loaded "On Change" for each layer)?

Page 1 of 1 All times are UTC - 8 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/