Changing label colour and font weight

Posts: 53
I got inspired by the ATVO Theme's script to change the Tower widget ticker data on the fly. In the past, I used to have different widgets for every data set, but I like the way that in the Theme example, it's via a script, which seems much easier on the FPS.

I'm trying to add to the original ConvertToGapOrInterval part that the font color of the Gap or Interval should get colourized in case the cars are close each other. However, there seem to be a problem. It says that ForeColor for Label isn't possible. How do I change the colour? Before, I used an override font colour, but that does not work, when I change the data via the script.

Also, I'd like to put P1 position data to the Bold font style and it says the same thing? And also that he tWidgetBase.Font is READ only.

var inter = race.LiveInterval;
var color = "#F59784";
var widget = item.Theme.Widgets.Find("W_Tower");

foreach (var subwidget in widget.Ticker.RepeatedSubWidgets)
{
      var label = subwidget.Labels.Find("L_Tower_Temp");ont, FontStyle.Bold);
   
      if (inter < 0.300 && inter > 0)
label.ForeColor = ColorConverter.ConvertFromString(color);
      else
label.ForetColor = System.Drawing.Color.White;
}

Edited (1 time)
Posts: 785
Here are some examples on how to change label fonts:

label.Font.FontColor = Colors.Red;
label.Font.FontColor = Color.FromRgb(255,0,125);

label.Font.FontWeight = TextFontWeights.Bold;
label.Font.FontItalic = true;
Posts: 53
I've just tried a simple implementation of both, but without success - the text remain white and "normal" as inherited in the widget settings. No errors found when compiling. Is this correct?

if (race.LivePosition == 1)
{
  var widget = item.Theme.Widgets.Find("W_Tower");

  foreach (var subwidget in widget.Ticker.RepeatedSubWidgets)
  {
      var label = subwidget.Labels.Find("L_Tower_Temp");
      label.Font.FontWeight = TextFontWeights.Bold;
      label.Font.FontColor = Colors.Red;
}


Edited (2 times)
Posts: 785
I don't know if you can do a Find on a label in a Ticker like that. Tickers behave differently as each copy of the template subwidget is a separate copy that's not otherwise connected to the theme. It may work, or it may not.

Can you check if your "label" variable is valid? Are you getting errors during execution? You can add a log statement and check the event log:
var label = subwidget.Labels.Find("L_Tower_Temp");
if (label == null) Console.WriteLine("Label not found");


If that is the case, you can try getting the label by its index using the following. You'll need to ensure the order of the labels remains the same though (or update the script). Assuming it's the 4th label (index 3):
var label = subwidget.Labels[3];
Posts: 61
Nick Thissen wrote:
Here are some examples on how to change label fonts:

label.Font.FontColor = Colors.Red;
label.Font.FontColor = Color.FromRgb(255,0,125);

label.Font.FontWeight = TextFontWeights.Bold;
label.Font.FontItalic = true;

Correct me if I am wrong Nick, that snippit of code gave an error on "Colors". Did I act correctly by adding this to the top of the code?
using System.Windows.Media;
Posts: 53
Nick Thissen wrote:
I don't know if you can do a Find on a label in a Ticker like that. Tickers behave differently as each copy of the template subwidget is a separate copy that's not otherwise connected to the theme. It may work, or it may not.

Can you check if your "label" variable is valid? Are you getting errors during execution? You can add a log statement and check the event log:
var label = subwidget.Labels.Find("L_Tower_Temp");
      if (label == null) Console.WriteLine("Label not found");


If that is the case, you can try getting the label by its index using the following. You'll need to ensure the order of the labels remains the same though (or update the script). Assuming it's the 4th label (index 3):
var label = subwidget.Labels[3];


You were right. I can't choose the specific widget in a ticker. So, instead, I did a little work around. Here's my solution, hopefully it's going to help someone.

1) I have split the widget in two. One widget is for the leader with a BOLD text as default, with the other used as a ticker for the rest of the grid, with a NORMAL font weight. I might have 2 widgets, but thanks to the script changing the data, it's still far better than having X widgets for each. The performance of the TV graphics has improved a lot.

2) As of colours, I had to make a mistake somewhere, because the override function has started to work again, so I just returned to use though. However, there are some animations disadvantages, so in a long-term plan, I still want to add it to the Tower code and I believe the problem is in a way the GAP/INTERVAL times are processed in the background.

Maybe a question - if I want to look for a live interval between 0 and 0.300 seconds, how to write it so ATVO can compare it with raw data from iRacing? What is the unit? Is it 300, or 30?
Posts: 785
The LiveInterval should be time in seconds. However; I am not fully sure but I think it does not take into account a lap difference. So if you are lapping someone there may also be a gap < 0.3 (but a lap behind). To check this, you would also need to add a check on LiveIntervalLaps and see if that equals 0. If LiveIntervalLaps > 0 it means there is this many laps difference between the drivers (on top of the normal LiveInterval).