Override Font Color

Posts: 287
I want to override some font color by a input label to choose for exemple specific color for Class0 cars.

I do INPUT, use this to show on a label and the read the text label by a script and return the value at the end of script.
(I use input to label because I don't see possibility to read directly in the input by script)

If I use only data binding classcolor in override font color it give me the iRacing color (ok)
If I use my script in override font color it is like no override ....

My label had this sort of text #B1A33333

Edited (1 time)
Posts: 785
You can get the text in an Input from its Text property.

If you put a converter for the Override Fontcolor (or any color), you have to return an actual Color and not just the hex string. You can convert from hex string to color using ColorConverter.

Example:
using System;
using ATVO.ThemesSDK;
using ATVO.ThemeEditor.ThemeModels;
using ATVO.ThemeEditor.Scripting.DotNET;
using System.Windows.Media;

namespace Scripts
{
public class OverrideColor : IScript
{
public object Execute(ThemeContentItem item, object value, string parameter, ISimulation sim)
{
var input = item.Theme.ControlInputs.Find("Input1");
var hex = input.Text;

if (string.IsNullOrWhiteSpace(hex))
return Colors.White;
return (Color) ColorConverter.ConvertFromString(hex);
}
}
}


Instead of hex this also supports many other values like RGB "(255,0,125)" or even names ("Red", "Blue", etc)

Note this will throw an error if the string value (hex) is not a valid color. I don't know any way to avoid that, typically you just catch the error when it happens and return something sensible.
Edited (2 times)
Posts: 287
Just PERFECT :)

With RGB "(255,0,125)" or 255,0,125 it is not ok, but Red yes and #FF0124 ok too.