Files
UnrealEngineUWP/Engine/Source/Runtime/UMG/Private/Components/ScrollBox.cpp
Matthew Griffin f3489ab89d [INTEGRATE] Change 2431842 by Nick.Darnell@Nick.Darnell_Dev on 2015/02/04 11:44:03
UMG - Fixing the scrollview widget to properly use the Bar style.

[CL 2438208 by Matthew Griffin in Main branch]
2015-02-09 11:37:17 -05:00

163 lines
3.4 KiB
C++

// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
#include "UMGPrivatePCH.h"
#define LOCTEXT_NAMESPACE "UMG"
/////////////////////////////////////////////////////
// UScrollBox
UScrollBox::UScrollBox(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
bIsVariable = false;
Orientation = Orient_Vertical;
SScrollBox::FArguments Defaults;
Visiblity_DEPRECATED = Visibility = UWidget::ConvertRuntimeToSerializedVisibility(Defaults._Visibility.Get());
WidgetStyle = *Defaults._Style;
WidgetBarStyle = *Defaults._ScrollBarStyle;
AlwaysShowScrollbar = false;
ScrollbarThickness = FVector2D(5, 5);
ScrollBarVisibility = ESlateVisibility::Visible;
}
void UScrollBox::ReleaseSlateResources(bool bReleaseChildren)
{
Super::ReleaseSlateResources(bReleaseChildren);
MyScrollBox.Reset();
}
UClass* UScrollBox::GetSlotClass() const
{
return UScrollBoxSlot::StaticClass();
}
void UScrollBox::OnSlotAdded(UPanelSlot* Slot)
{
// Add the child to the live canvas if it already exists
if ( MyScrollBox.IsValid() )
{
Cast<UScrollBoxSlot>(Slot)->BuildSlot(MyScrollBox.ToSharedRef());
}
}
void UScrollBox::OnSlotRemoved(UPanelSlot* Slot)
{
// Remove the widget from the live slot if it exists.
if ( MyScrollBox.IsValid() )
{
TSharedPtr<SWidget> Widget = Slot->Content->GetCachedWidget();
if ( Widget.IsValid() )
{
MyScrollBox->RemoveSlot(Widget.ToSharedRef());
}
}
}
TSharedRef<SWidget> UScrollBox::RebuildWidget()
{
MyScrollBox = SNew(SScrollBox)
.Style(&WidgetStyle)
.ScrollBarStyle(&WidgetBarStyle)
.Orientation(Orientation);
for ( UPanelSlot* Slot : Slots )
{
if ( UScrollBoxSlot* TypedSlot = Cast<UScrollBoxSlot>(Slot) )
{
TypedSlot->Parent = this;
TypedSlot->BuildSlot(MyScrollBox.ToSharedRef());
}
}
return BuildDesignTimeWidget( MyScrollBox.ToSharedRef() );
}
void UScrollBox::SynchronizeProperties()
{
MyScrollBox->SetScrollOffset(DesiredScrollOffset);
MyScrollBox->SetOrientation(Orientation);
MyScrollBox->SetScrollBarVisibility(UWidget::ConvertSerializedVisibilityToRuntime(ScrollBarVisibility));
MyScrollBox->SetScrollBarThickness(ScrollbarThickness);
MyScrollBox->SetScrollBarAlwaysVisible(AlwaysShowScrollbar);
}
void UScrollBox::SetScrollOffset(float NewScrollOffset)
{
DesiredScrollOffset = NewScrollOffset;
if ( MyScrollBox.IsValid() )
{
MyScrollBox->SetScrollOffset(NewScrollOffset);
}
}
void UScrollBox::ScrollToStart()
{
if ( MyScrollBox.IsValid() )
{
MyScrollBox->ScrollToStart();
}
}
void UScrollBox::ScrollToEnd()
{
if ( MyScrollBox.IsValid() )
{
MyScrollBox->ScrollToEnd();
}
}
void UScrollBox::PostLoad()
{
Super::PostLoad();
if ( GetLinkerUE4Version() < VER_UE4_DEPRECATE_UMG_STYLE_ASSETS )
{
if ( Style_DEPRECATED != nullptr )
{
const FScrollBoxStyle* StylePtr = Style_DEPRECATED->GetStyle<FScrollBoxStyle>();
if ( StylePtr != nullptr )
{
WidgetStyle = *StylePtr;
}
Style_DEPRECATED = nullptr;
}
if ( BarStyle_DEPRECATED != nullptr )
{
const FScrollBarStyle* StylePtr = BarStyle_DEPRECATED->GetStyle<FScrollBarStyle>();
if ( StylePtr != nullptr )
{
WidgetBarStyle = *StylePtr;
}
BarStyle_DEPRECATED = nullptr;
}
}
}
#if WITH_EDITOR
const FSlateBrush* UScrollBox::GetEditorIcon()
{
return FUMGStyle::Get().GetBrush("Widget.ScrollBox");
}
const FText UScrollBox::GetPaletteCategory()
{
return LOCTEXT("Panel", "Panel");
}
#endif
/////////////////////////////////////////////////////
#undef LOCTEXT_NAMESPACE