Files
UnrealEngineUWP/Engine/Source/Runtime/Slate/Private/Framework/Text/SlateTextHighlightRunRenderer.cpp
Matt Kuhlenschmidt aa0df604d3 Slate text widgets now have a "Text Overflow" argument that dicates what happens to text when it is larger than its clip rect. The two overflow methods are Clip and Ellipsis. Clip is the default and existing behavior where text is clipped per pixel. Ellipsis replaces clipped text with a "..." string to provide a more polished look when text is clipped.
Supports left and right justification and left and right text flows.

The ellipsis uses the U+2026 character or 3 dots if the font does not have U+2026. Localizers can override the text used.

Unsupported:
- Simple, non-shaped text
- Non-axis aligned clip rects.
- Center justified text

#rb jamie.dale
#preflight 0f59f9a92cf890001166d15

[CL 16898534 by Matt Kuhlenschmidt in ue5-main branch]
2021-07-20 13:19:19 -04:00

46 lines
2.2 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "Framework/Text/SlateTextHighlightRunRenderer.h"
#include "Rendering/DrawElements.h"
#include "Styling/SlateTypes.h"
FSlateTextHighlightRunRenderer::FSlateTextHighlightRunRenderer()
{
}
int32 FSlateTextHighlightRunRenderer::OnPaint( const FPaintArgs& Args, const FTextLayout::FLineView& Line, const TSharedRef< ISlateRun >& Run, const TSharedRef< ILayoutBlock >& Block, const FTextBlockStyle& DefaultStyle, const FGeometry& AllottedGeometry, const FSlateRect& MyCullingRect, FSlateWindowElementList& OutDrawElements, int32 LayerId, const FWidgetStyle& InWidgetStyle, bool bParentEnabled ) const
{
FVector2D Location( Block->GetLocationOffset() );
Location.Y = Line.Offset.Y;
// The block size and offset values are pre-scaled, so we need to account for that when converting the block offsets into paint geometry
const float InverseScale = Inverse(AllottedGeometry.Scale);
// Draw the actual highlight rectangle
FSlateDrawElement::MakeBox(
OutDrawElements,
++LayerId,
AllottedGeometry.ToPaintGeometry(TransformVector(InverseScale, FVector2D(Block->GetSize().X, Line.Size.Y)), FSlateLayoutTransform(TransformPoint(InverseScale, Location))),
&DefaultStyle.HighlightShape,
bParentEnabled ? ESlateDrawEffect::None : ESlateDrawEffect::DisabledEffect,
InWidgetStyle.GetColorAndOpacityTint() * DefaultStyle.HighlightShape.TintColor.GetColor(InWidgetStyle)
);
FLinearColor InvertedHighlightColor = DefaultStyle.HighlightColor.GetColor(InWidgetStyle);
InvertedHighlightColor.A = InWidgetStyle.GetForegroundColor().A;
FWidgetStyle WidgetStyle( InWidgetStyle );
WidgetStyle.SetForegroundColor( InvertedHighlightColor );
// When highlighting text we want the actual text so do not replace any of it with ellipsis
const ETextOverflowPolicy OverflowPolicy = ETextOverflowPolicy::Clip;
return Run->OnPaint( Args, FTextArgs(Line, Block, DefaultStyle, OverflowPolicy, ETextOverflowDirection::NoOverflow), AllottedGeometry, MyCullingRect, OutDrawElements, LayerId, WidgetStyle, bParentEnabled );
}
TSharedRef< FSlateTextHighlightRunRenderer > FSlateTextHighlightRunRenderer::Create()
{
return MakeShareable( new FSlateTextHighlightRunRenderer() );
}