MCRO
C++23 utilities for Unreal Engine.
Loading...
Searching...
No Matches
SErrorDisplay.h
Go to the documentation of this file.
1/** @noop License Comment
2 * @file
3 * @copyright
4 * This Source Code is subject to the terms of the Mozilla Public License, v2.0.
5 * If a copy of the MPL was not distributed with this file You can obtain one at
6 * https://mozilla.org/MPL/2.0/
7 *
8 * @author David Mórász
9 * @date 2025
10 */
11
12#pragma once
13
14#include "CoreMinimal.h"
15#include "Widgets/SCompoundWidget.h"
16#include "Widgets/Text/STextBlock.h"
17#include "Widgets/Layout/SExpandableArea.h"
18#include "Widgets/Input/SEditableTextBox.h"
19#include "Mcro/Error.h"
20#include "Mcro/Slate.h"
22
23namespace Mcro::Error
24{
25 using namespace Mcro::AutoModularFeature;
26
27 /**
28 * @brief
29 * A modular feature which allows other modules to inject their own UI into the common error display widget.
30 *
31 * Of course these functions are only triggered when an error is using `SErrorDisplay` as its widget type, but
32 * errors may declare any other widget type to be used to represent themselves.
33 */
34 class MCRO_API IErrorDisplayExtension : public TAutoModularFeature<IErrorDisplayExtension>
35 {
36 public:
37 virtual bool SupportsError(IErrorRef const& error) { return true; };
38 virtual TSharedPtr<SWidget> PostSeverity(IErrorRef const& error) { return {}; };
39 virtual TSharedPtr<SWidget> PostMessage(IErrorRef const& error) { return {}; };
40 virtual TSharedPtr<SWidget> PostDetails(IErrorRef const& error) { return {}; };
41 virtual TSharedPtr<SWidget> PostCodeContext(IErrorRef const& error) { return {}; };
42 virtual TSharedPtr<SWidget> PostErrorPropagation(IErrorRef const& error) { return {}; };
43 virtual TSharedPtr<SWidget> PostInnerErrors(IErrorRef const& error) { return {}; };
44 };
45
46 /** @brief Base class for displaying Mcro::Error::IError objects to the user */
47 class MCRO_API SErrorDisplay : public SCompoundWidget
48 {
49 public:
52 SLATE_NAMED_SLOT(FArguments, PostSeverity);
53 SLATE_NAMED_SLOT(FArguments, PostMessage);
54 SLATE_NAMED_SLOT(FArguments, PostDetails);
55 SLATE_NAMED_SLOT(FArguments, PostCodeContext);
56 SLATE_NAMED_SLOT(FArguments, PostErrorPropagation);
57 SLATE_NAMED_SLOT(FArguments, PostInnerErrors);
58 SLATE_END_ARGS()
59
60 /** Constructs this widget with InArgs */
61 void Construct(const FArguments& inArgs);
62
63 static auto Text(const FString& text) -> Slate::TAttributeBlock<SEditableTextBox>;
64 static auto Text(const FStringView& text) -> Slate::TAttributeBlock<SEditableTextBox>;
65 static auto OptionalText(const FString& text) -> Slate::TAttributeBlock<SEditableTextBox>;
66 static auto OptionalTextWidget(const FString& text) -> TSharedRef<SEditableTextBox>;
67
68 static auto ExpandableText(const FText& title, const FString& text) -> Slate::TAttributeBlock<SExpandableArea>;
69 static auto ExpandableTextWidget(const FText& title, const FString& text) -> TSharedRef<SExpandableArea>;
70
71 static auto Severity(const IErrorRef& error) -> Slate::TAttributeBlock<STextBlock>;
72 static auto SeverityWidget(const IErrorRef& error) -> TSharedRef<STextBlock>;
73
74 static auto Row() -> SVerticalBox::FSlot::FSlotArguments;
75 };
76}
Auto Modular Features are a workflow with Modular Features where the developer doesn't have to rely o...
A modular feature which allows other modules to inject their own UI into the common error display wid...
virtual TSharedPtr< SWidget > PostMessage(IErrorRef const &error)
virtual TSharedPtr< SWidget > PostInnerErrors(IErrorRef const &error)
virtual TSharedPtr< SWidget > PostSeverity(IErrorRef const &error)
virtual TSharedPtr< SWidget > PostErrorPropagation(IErrorRef const &error)
virtual TSharedPtr< SWidget > PostCodeContext(IErrorRef const &error)
virtual TSharedPtr< SWidget > PostDetails(IErrorRef const &error)
virtual bool SupportsError(IErrorRef const &error)
Base class for displaying Mcro::Error::IError objects to the user.
SLATE_ARGUMENT(IErrorPtr, Error)
SLATE_NAMED_SLOT(FArguments, PostErrorPropagation)
SLATE_NAMED_SLOT(FArguments, PostMessage)
SLATE_NAMED_SLOT(FArguments, PostDetails)
SLATE_BEGIN_ARGS(SErrorDisplay)
SLATE_NAMED_SLOT(FArguments, PostSeverity)
SLATE_NAMED_SLOT(FArguments, PostInnerErrors)
SLATE_NAMED_SLOT(FArguments, PostCodeContext)
Contains utilities for structured error handling.
Definition Error.Fwd.h:19
TSharedRef< IError > IErrorRef
Convenience alias for an instance of an error.
Definition Error.Fwd.h:25
TSharedPtr< IError > IErrorPtr
Convenience alias for an instance of an error.
Definition Error.Fwd.h:26