Download

Unable to generate FSlateIcon from style

Hi I am struggling with this now,

1.- First I Created a new style setting all and making a static method to get the style name:



TSharedRef<FSlateStyleSet> StyleRef = MakeShareable(new FSlateStyleSet("ArchVisSequencerStyle"));
StyleRef->SetContentRoot(IPluginManager::Get().FindPlugin("ArchVisSequencer")->GetBaseDir() / TEXT("Resources"));

StyleRef->Set("save", new IMAGE_BRUSH("icon_Save_24x", FVector2D(24, 24)));

FName FAVSequencerStyle::GetStyleSetName()
{
    return MenuStyleInstance->GetStyleSetName();
}



2.- After that I registered all in the startupModule, and I trying to create my icon like this:



FToolBarBuilder ToolBarBuilder(NULL, FMultiBoxCustomization::None, TSharedPtr<FExtender>(), Orient_Horizontal, true);

    ToolBarBuilder.BeginSection("Base Commans");
    {
        ToolBarBuilder.AddToolBarButton(
            FUIAction(FExecuteAction::CreateSP(this, &SAVSequencer::SaveSequence)),
            NAME_None,
            FText::FromString("Save"),
            FText::FromString("Save this sequence dude"),
            FSlateIcon(FAVSequencerStyle::GetStyleSetName(), "save")
        );
    }
    ToolBarBuilder.EndSection();


I know the style is working, since I can access the brush like this:
FAVSequencerStyle::Get().GetBrush(TEXT(“save”));
to be honest I don’t have any idea at this point, I am reading the source to see some examples and discover what the heck is happening

this are all my test:



FSlateIcon icone = FSlateIcon(FAVSequencerStyle::GetStyleSetName(), "save");
        const ISlateStyle* StyleSet = FAVSequencerStyle::GetStyleSetName().IsNone() ? nullptr : FSlateStyleRegistry::FindSlateStyle(FAVSequencerStyle::GetStyleSetName());
        if (icone.IsSet())
        {
            FString yes = FAVSequencerStyle::GetStyleSetName().ToString();
            UE_LOG(LogTemp, Warning, TEXT("yes it is %s"), *yes);
        }
        else
        {
            UE_LOG(LogTemp, Error, TEXT("nop"));
        }

        FSlateIcon hyperPowerfullIcon = FSlateIcon(FAVSequencerStyle::GetStyleSetName(), "save");

        TSharedRef<SWidget> widget = SNew(SImage)
            .Image(hyperPowerfullIcon.GetIcon());
        ToolBarBuilder.AddWidget(
            widget
        );


apparently my style is registered, is not null, and we can get the SlateBrush* directly from the FSlateIcon which is really annoying, if this is valid then why is not working?:rolleyes:

I forgot this, in the end I couldn’t find any explanation, so I decided use AddWidget from the FToolBarBuilder and basically reproduce the add button functionality which is better, because I don’t like the current orange style, here the code:



TSharedRef<SWidget> FAVSequencerStyle::GenerateButton(const FSlateBrush* InIcon, FOnClicked InDelegate, FString ToolTip)
{
    FButtonStyle* btnStyle = new FButtonStyle();
    FSlateImageBrush* brush = (FSlateImageBrush*)FAVSequencerStyle::Get().GetBrush("btn");
    btnStyle->Normal = *brush;
    btnStyle->Hovered = *brush;
    btnStyle->Pressed = *brush;
    btnStyle->Normal.TintColor = FSlateColor(FLinearColor(0,0,0,0));
    btnStyle->Hovered.TintColor = FSlateColor(FLinearColor(0.107f, 0.491f, 0.107f, 1));
    btnStyle->Pressed.TintColor = FSlateColor(FLinearColor(0.107f, 0.491f, 0.107f, 1) * .5f);

    TSharedRef<SWidget> widget = SNew(SButton)
        .ButtonStyle(btnStyle)
        .OnClicked(InDelegate)
        .ToolTipText(FText::FromString(*ToolTip))
        .Content()
            
            SNew(SImage)
            .Image(InIcon)
        ];

    return widget;
}


inside the FToolBarBuilder is used almost the same :



//play
        ToolBarBuilder.AddWidget(
            FAVSequencerStyle::GenerateButton(FAVSequencerStyle::Get().GetBrush("play"),FOnClicked::CreateSP(this, &SAVSequencer::SaveSequence),
                "Play animation")
        );


I left it here, in case that someone need this info