[Slate] How does .Style work?

I’m working with a STreeView and I want to modify the colour of an item when it’s highlighted. I’m guessing the functionality is in the .Style argument, but I can’t find any examples or documentation on how it works. It only takes a name, which I’m guessing is a SlateStyle PropertyName, but I’m not sure what I should be defining in that property.

Does anyone have any examples or information on how I’d go about using it?

In the latest version we have made all styles into structs, so that they are much less ad-hoc. You can set the TextColor and SelectedTextColor. They should drive the color of anything inside a table row that has its color set to FSlateColor::UseForeground().

Excellent, thank you very much :slight_smile:

Out of interest, how do you set TextColor and SelectedTextColor?
I can see them inside TableRowBrushes, but it’s protected, and I can’t see any way to set them.

Well, you probably have all the code for STableRow because it is a template. If that’s so, you can just inherit from it and set its foreground color however you like. Does that help?

Slate is a big, nasty mess of macros which makes it practically impossible to find anything you’re looking for as Visual Studio simply can’t follow it (even Visual Assist struggles pretty badly). It’s also completely impossible to debug as a result as everything is on a single line (have fun finding an error on line #3 when ‘line 3’ is actually 6000 lines of code).

Ranting aside, I’m not sure .Style is what you’re looking for, try .ColorAndOpacity instead. Some are valid on some widgets, and not on others, but this seems like a more generic one.

You can pass in either a variable or function or use a boolean condition:

.ColorAndOpacity( &MyClass::ColourReference )

.ColorAndOpacity( MyClass::ColourFunction() )

.ColorAndOpacity( bColourGray ? FLinearColor::Gray : FLinearColor(0.25f, 0.25f, 0.25f))

Tell me about it, I kinda get the thinking behind it, but having no documentation and being impossible to debug properly makes it an incredibly painful thing to deal with.

I found how to use .Style by looking through the complete source code of an old version of Rocket.

Basically, you define a set of style properties under a single tree in a SlateStyleSet. This is how I did it for STreeView:

In my Style code:

Style.Set("MyGame.TreeStyle.Selection.Active",new FSlateColorBrush(FLinearColor(FColor(100,100,100))));
	Style.Set("MyGame.TreeStyle.Selection.ActiveHovered",new FSlateColorBrush(FLinearColor(FColor(100,100,100))));
	Style.Set("MyGame.TreeStyle.Selection.Inactive",new FSlateColorBrush(FLinearColor(FColor(80,80,80))));
	Style.Set("MyGame.TreeStyle.Selection.InactiveHovered",new FSlateColorBrush(FLinearColor(FColor(80,80,80))));
	Style.Set("MyGame.TreeStyle.EvenRowBackground",new FSlateColorBrush(FLinearColor(0,0,0,0)));
	Style.Set("MyGame.TreeStyle.EvenRowBackgroundHovered",new FSlateColorBrush(FLinearColor(FColor(70,70,70))));
	Style.Set("MyGame.TreeStyle.OddRowBackground",new FSlateColorBrush(FLinearColor(0,0,0,0)));
	Style.Set("MyGame.TreeStyle.OddRowBackgroundHovered",new FSlateColorBrush(FLinearColor(FColor(70,70,70))));
	Style.Set("MyGame.TreeStyle.Selection.SelectorFocused",new FSlateColorBrush(FLinearColor(0,0,0,0)));

In my slate STreeView definition:

.Style("MyGame.TreeStyle")

The problem is, those style names are set, but there’s no-where that actually defines what they are for each widget :frowning:

I feel like I’m using a tool that was developed solely for in-house use where you could just talk to the guy who put it together, then just released to the public without any resources.

Still, hopefully that’s coming soon…