Hi I’ve been working on a tooltip widget for slate widgets but when I add more then one child to the vertical box or if it contains a text box and I change its font and font size it stretches to double or more its base height, Sorry if this is a stupid question I’m new to using slate any help I would appreciate any help.
.h
class UNREALCOC_API SStandardTooltip : public SToolTip
{
SLATE_BEGIN_ARGS(SStandardTooltip) : _HeaderText(), _BodyText(), _Content(), _HeadFont(), _BodyFont(), _BorderImage(FCoreStyle::Get().GetBrush("ToolTip.Background")), _IsInteractive(false)
{
};
//SLATE_ARGUMENT();
/** The text displayed in this tool tip */
SLATE_ATTRIBUTE(FText, HeaderText)
/** The text displayed in this tool tip */
SLATE_ATTRIBUTE(FText, BodyText)
/** Arbitrary content to be displayed in the tool tip; overrides any text that may be set. */
SLATE_DEFAULT_SLOT(FArguments, Content)
SLATE_ATTRIBUTE(FSlateFontInfo, HeadFont)
SLATE_ATTRIBUTE(FSlateFontInfo, BodyFont)
/** The background/border image to display */
SLATE_ATTRIBUTE(const FSlateBrush*, BorderImage)
/** Whether the tooltip should be considered interactive */
SLATE_ATTRIBUTE(bool, IsInteractive)
SLATE_END_ARGS();
public:
void Construct(const FArguments& InArgs);
virtual void SetContentWidget(const TSharedRef<SWidget>& InContentWidget) override;
virtual bool SupportsKeyboardFocus() const override{ return true; }
virtual bool IsEmpty() const override;
virtual bool IsInteractive() const override;
virtual void OnOpening() override { }
virtual void OnClosed() override { }
private:
// Content widget.
TWeakPtr<SWidget> WidgetContent;
TAttribute<FText> HText;
TAttribute<FText> BText;
TAttribute<FSlateFontInfo> HeadFont;
TAttribute<FSlateFontInfo> BodyFont;
// Wrapped content within the widget;
TSharedPtr<SWidget> ToolTipContent;
// The background/border image to display
TAttribute<const FSlateBrush*> BorderImage;
// Whether the tooltip should be considered interactive.
TAttribute<bool> bIsInteractive;
};
Default size it should be (One child)
Screenshot
.cpp
void SStandardTooltip::Construct(const FArguments& InArgs)
{
HText = InArgs._HeaderText;
BText = InArgs._BodyText;
SetContentWidget(InArgs._Content.Widget);
}
void SStandardTooltip::SetContentWidget(const TSharedRef<SWidget>& InContentWidget)
{
if (InContentWidget != SNullWidget::NullWidget)
{
// Widget content argument takes precedence over the text content.
WidgetContent = InContentWidget;
}
TSharedPtr< SWidget > PinnedWidgetContent = WidgetContent.Pin();
if (PinnedWidgetContent.IsValid())
{
ToolTipContent = PinnedWidgetContent;
ChildSlot[
SNew(STextBlock)
];
}
else
{
USlateBrushAsset* LoadB = LoadObject<USlateBrushAsset>(nullptr, TEXT("SlateBrushAsset'/Game/Assets/ProjectMaterials/ToolTip/ToolTipBrush.ToolTipBrush'"));
FSlateRenderTransform Text(FScale2D(0.91f, 0.8f), FVector2D(0.f, 19.0f));
FSlateRenderTransform Image(FScale2D(0.899f, 0.09), FVector2D(0.f, 1.0f));
FSlateRenderTransform SizeBox(FScale2D(0.93f, 1.0f), FVector2D(0.f, -7.5f));
const FSlateBrush* Brush = &LoadB->Brush;
UDataTable* DT = LoadObject<UDataTable>(nullptr, TEXT("DataTable'/Game/Font.Font'"));
FSlateFontInfo GG = DT->FindRow<FToolTipFonts_S>(FName("Font"), "")->HeaderFont;
ChildSlot[
SNew(SBox).MinDesiredWidth(717.2).MinDesiredHeight(517.2).MaxDesiredWidth(717.2)[
SNew(SBorder).BorderImage(Brush).DesiredSizeScale(FVector2D(31.1, 26.1)).VAlign(VAlign_Fill).HAlign(HAlign_Fill)[
SNew(SVerticalBox) + SVerticalBox::Slot().VAlign(VAlign_Fill).HAlign(HAlign_Fill).FillHeight(1000)[
SNew(STextBlock).Text(FText::FromString("Heeeeeeeeeeeeeee")).ColorAndOpacity(FColor::Black)
]
]
]
];
}
}
bool SStandardTooltip::IsEmpty() const
{
return !WidgetContent.IsValid() && HText.Get().IsEmpty() && BText.Get().IsEmpty();
}
bool SStandardTooltip::IsInteractive() const
{
return bIsInteractive.Get();
}
What happens when I add a second child widget to the vertical box
Screenshot
Note: The image appears at the very bottom of the widget and is very thin
void SStandardTooltip::Construct(const FArguments& InArgs)
{
HText = InArgs._HeaderText;
BText = InArgs._BodyText;
SetContentWidget(InArgs._Content.Widget);
}
void SStandardTooltip::SetContentWidget(const TSharedRef<SWidget>& InContentWidget)
{
if (InContentWidget != SNullWidget::NullWidget)
{
// Widget content argument takes precedence over the text content.
WidgetContent = InContentWidget;
}
TSharedPtr< SWidget > PinnedWidgetContent = WidgetContent.Pin();
if (PinnedWidgetContent.IsValid())
{
ToolTipContent = PinnedWidgetContent;
ChildSlot[
SNew(STextBlock)
];
}
else
{
USlateBrushAsset* LoadB = LoadObject<USlateBrushAsset>(nullptr, TEXT("SlateBrushAsset'/Game/Assets/ProjectMaterials/ToolTip/ToolTipBrush.ToolTipBrush'"));
FSlateRenderTransform Text(FScale2D(0.91f, 0.8f), FVector2D(0.f, 19.0f));
FSlateRenderTransform Image(FScale2D(0.899f, 0.09), FVector2D(0.f, 1.0f));
FSlateRenderTransform SizeBox(FScale2D(0.93f, 1.0f), FVector2D(0.f, -7.5f));
const FSlateBrush* Brush = &LoadB->Brush;
UDataTable* DT = LoadObject<UDataTable>(nullptr, TEXT("DataTable'/Game/Font.Font'"));
FSlateFontInfo GG = DT->FindRow<FToolTipFonts_S>(FName("Font"), "")->HeaderFont;
ChildSlot[
SNew(SBox).MinDesiredWidth(717.2).MinDesiredHeight(517.2).MaxDesiredWidth(717.2)[
SNew(SBorder).BorderImage(Brush).DesiredSizeScale(FVector2D(31.1, 26.1)).VAlign(VAlign_Fill).HAlign(HAlign_Fill)[
SNew(SVerticalBox) + SVerticalBox::Slot().VAlign(VAlign_Fill).HAlign(HAlign_Fill).FillHeight(1000)[
SNew(STextBlock).Text(FText::FromString("Heeeeeeeeeeeeeee")).ColorAndOpacity(FColor::Black)
] + SVerticalBox::Slot().VAlign(VAlign_Top).HAlign(HAlign_Fill)[
SNew(SImage).ColorAndOpacity(FColor::Black)
]
]
]
];
}
}
bool SStandardTooltip::IsEmpty() const
{
return !WidgetContent.IsValid() && HText.Get().IsEmpty() && BText.Get().IsEmpty();
}
bool SStandardTooltip::IsInteractive() const
{
return bIsInteractive.Get();
}
What happens when I add a new font to the text box (One child in vertical box)
Screenshot
void SStandardTooltip::Construct(const FArguments& InArgs)
{
HText = InArgs._HeaderText;
BText = InArgs._BodyText;
SetContentWidget(InArgs._Content.Widget);
}
void SStandardTooltip::SetContentWidget(const TSharedRef<SWidget>& InContentWidget)
{
if (InContentWidget != SNullWidget::NullWidget)
{
// Widget content argument takes precedence over the text content.
WidgetContent = InContentWidget;
}
TSharedPtr< SWidget > PinnedWidgetContent = WidgetContent.Pin();
if (PinnedWidgetContent.IsValid())
{
ToolTipContent = PinnedWidgetContent;
ChildSlot[
SNew(STextBlock)
];
}
else
{
USlateBrushAsset* LoadB = LoadObject<USlateBrushAsset>(nullptr, TEXT("SlateBrushAsset'/Game/Assets/ProjectMaterials/ToolTip/ToolTipBrush.ToolTipBrush'"));
FSlateRenderTransform Text(FScale2D(0.91f, 0.8f), FVector2D(0.f, 19.0f));
FSlateRenderTransform Image(FScale2D(0.899f, 0.09), FVector2D(0.f, 1.0f));
FSlateRenderTransform SizeBox(FScale2D(0.93f, 1.0f), FVector2D(0.f, -7.5f));
const FSlateBrush* Brush = &LoadB->Brush;
UDataTable* DT = LoadObject<UDataTable>(nullptr, TEXT("DataTable'/Game/Font.Font'"));
FSlateFontInfo GG = DT->FindRow<FToolTipFonts_S>(FName("Font"), "")->HeaderFont;
ChildSlot[
SNew(SBox).MinDesiredWidth(717.2).MinDesiredHeight(517.2).MaxDesiredWidth(717.2)[
SNew(SBorder).BorderImage(Brush).DesiredSizeScale(FVector2D(31.1, 26.1)).VAlign(VAlign_Fill).HAlign(HAlign_Fill)[
SNew(SVerticalBox) + SVerticalBox::Slot().VAlign(VAlign_Fill).HAlign(HAlign_Fill).FillHeight(1000)[
SNew(STextBlock).Text(FText::FromString("Heeeeeeeeeeeeeee")).ColorAndOpacity(FColor::Black).Font(GG)
]
]
]
];
}
}
bool SStandardTooltip::IsEmpty() const
{
return !WidgetContent.IsValid() && HText.Get().IsEmpty() && BText.Get().IsEmpty();
}
bool SStandardTooltip::IsInteractive() const
{
return bIsInteractive.Get();
}