Stream Chat Unreal SDK
Loading...
Searching...
No Matches
AttachmentWidget.h
1// Copyright 2026 Stream.IO, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "Channel/Attachment.h"
6#include "Components/Border.h"
7#include "Components/Image.h"
8#include "Components/PanelWidget.h"
9#include "Components/SizeBox.h"
10#include "Components/TextBlock.h"
11#include "CoreMinimal.h"
12#include "MessageSide.h"
13#include "StreamWidget.h"
14
15#include "AttachmentWidget.generated.h"
16
17class UTexture2DDynamic;
18
31UCLASS()
32class STREAMCHATUI_API UAttachmentWidget : public UStreamWidget
33{
34 GENERATED_BODY()
35
36public:
37 UFUNCTION(BlueprintCallable, Category = "Stream Chat")
38 void Setup(const FAttachment& InAttachment, EMessageSide InSide);
39
40protected:
42 UPROPERTY(meta = (BindWidgetOptional))
43 UPanelWidget* ContentPanel;
44
46 UPROPERTY(EditDefaultsOnly, Category = Defaults, meta = (ClampMin = "0.1", ClampMax = "1.0"))
47 float ImageWidthFraction = 0.66f;
48
50 UPROPERTY(EditDefaultsOnly, Category = Defaults)
51 float MaxImageWidth = 320.f;
52
54 UPROPERTY(EditDefaultsOnly, Category = Defaults, meta = (ClampMin = "1.0"))
55 float MaxImageAspect = 2.f;
56
63 UPROPERTY(EditDefaultsOnly, Category = Defaults)
64 bool bRequestResizedImages = true;
65
66 UPROPERTY(EditDefaultsOnly, Category = Defaults)
67 FMargin FileRowPadding = FMargin{12.f, 8.f};
68
69 // Only the size is configurable: the typeface is taken from whatever font the text block already
70 // carries, which keeps this working without a font asset of our own.
71 UPROPERTY(EditDefaultsOnly, Category = Defaults)
72 int32 TitleFontSize = 14;
73
74 UPROPERTY(EditDefaultsOnly, Category = Defaults)
75 int32 SubtitleFontSize = 12;
76
77 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Setup)
78 FAttachment Attachment;
79
80 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Setup)
81 EMessageSide Side = EMessageSide::You;
82
83private:
84 virtual void OnSetup() override;
85 virtual void NativePreConstruct() override;
86
88 bool ShouldRenderInline() const;
89 void FetchRemoteImage();
90 void OnImageDownloaded(UTexture2DDynamic* Texture);
91
93 float GetAvailableWidth() const;
95 float GetImageBudgetWidth() const;
102 FVector2D GetImageDisplaySize(int32 SourceWidth, int32 SourceHeight) const;
104 float GetDpiScale() const;
105 void ApplyImageSize(const FVector2D& Size);
106
108 FString GetTitle() const;
110 FString GetSubtitle() const;
111
112 UPanelWidget* GetOrCreateContentPanel();
113
114 // Both the image and the file row are built for every attachment: an image that fails to
115 // download falls back to the row, and there is no theme to style a late-built one with.
116 UPROPERTY(Transient)
117 UImage* Image;
118 // The image is sized by this rather than by UImage::SetDesiredSizeOverride, which does nothing
119 // unless the slate widget already exists and is not reapplied when it is rebuilt
120 UPROPERTY(Transient)
121 USizeBox* ImageSizer;
122 UPROPERTY(Transient)
123 UBorder* FileRow;
124 UPROPERTY(Transient)
125 UTextBlock* TitleTextBlock;
126 UPROPERTY(Transient)
127 UTextBlock* SubtitleTextBlock;
128
129 bool bImageLoaded = false;
130};
Displays a single attachment of a message.
Definition AttachmentWidget.h:33
@ Image
A still image, rendered inline.
A file, image or link attached to a message.
Definition Attachment.h:42