From 2064c37bc357ca8d227f373df2ea43304409394b Mon Sep 17 00:00:00 2001 From: Mateus Rodrigues Date: Mon, 18 May 2026 23:12:14 -0300 Subject: [PATCH] feat(ui): text style via CommonTextStyle por variante (padrao Hyper) + align + auto-size MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit FUIStyleButtonVariant.Font (FSlateFontInfo) -> TSubclassOf TextStyle (idiomatico CommonUI, como BP_Style_Text_* do Hyper; theme-driven via DT_UI_Styles por variante). ButtonText volta a UCommonTextBlock; RefreshUIStyle: SetStyle(variante.TextStyle) + cor do FUIStyle por cima (FUIStyle manda na cor por tema). Mantidos TextAlign (ETextJustify L/C/R via SetJustification + slot do Overlay) e bAutoSizeText (TextScaleBox ScaleToFit/None) — ortogonais ao CommonTextStyle. ButtonTextValue default 'Button Text' agora no header. Co-Authored-By: Claude Opus 4.7 (1M context) --- Source/ZMMO/Data/UI/UIStyleTokens.h | 12 +++++++ Source/ZMMO/Game/UI/Widgets/UIButton_Base.cpp | 31 +++++++++++++++++++ Source/ZMMO/Game/UI/Widgets/UIButton_Base.h | 19 ++++++++++-- 3 files changed, 60 insertions(+), 2 deletions(-) diff --git a/Source/ZMMO/Data/UI/UIStyleTokens.h b/Source/ZMMO/Data/UI/UIStyleTokens.h index 97e5505..2bb2070 100644 --- a/Source/ZMMO/Data/UI/UIStyleTokens.h +++ b/Source/ZMMO/Data/UI/UIStyleTokens.h @@ -3,9 +3,12 @@ #include "CoreMinimal.h" #include "Fonts/SlateFontInfo.h" #include "Layout/Margin.h" +#include "Templates/SubclassOf.h" #include "UIStyleTypes.h" #include "UIStyleTokens.generated.h" +class UCommonTextStyle; + /** * Tokens de estilo da UI organizados em 3 camadas (design tokens): * @@ -193,6 +196,15 @@ struct ZMMO_API FUIStyleButtonVariant UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "UI Style|Button") FLinearColor TextColor = FLinearColor::White; + + /** + * Estilo de texto desta variante (padrão Hyper/CommonUI: CommonTextStyle). + * Define fonte/tamanho/peso. A COR é sobreposta pelo TextColor acima + * (FUIStyle manda na cor por tema). Permite Primary/Secondary/Danger/Ghost + * com tipografias diferentes. Preenchido em DT_UI_Styles por tema. + */ + UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "UI Style|Button") + TSubclassOf TextStyle; }; USTRUCT(BlueprintType) diff --git a/Source/ZMMO/Game/UI/Widgets/UIButton_Base.cpp b/Source/ZMMO/Game/UI/Widgets/UIButton_Base.cpp index 9e5e8df..ebe0156 100644 --- a/Source/ZMMO/Game/UI/Widgets/UIButton_Base.cpp +++ b/Source/ZMMO/Game/UI/Widgets/UIButton_Base.cpp @@ -8,7 +8,9 @@ #include "Components/TextBlock.h" #include "Components/Image.h" #include "Components/SizeBox.h" +#include "Components/ScaleBox.h" #include "Components/OverlaySlot.h" +#include "CommonTextBlock.h" #include "CommonActionWidget.h" namespace @@ -169,7 +171,36 @@ void UUIButton_Base::RefreshUIStyle() } if (ButtonText) { + // Tipografia: CommonTextStyle da variante (padrão Hyper/CommonUI). + if (VariantStyle.TextStyle) + { + ButtonText->SetStyle(VariantStyle.TextStyle); + } + // Cor: FUIStyle manda na cor por tema (sobrepõe o CommonTextStyle). ButtonText->SetColorAndOpacity(FSlateColor(VariantStyle.TextColor)); + + // Alinhamento L/C/R dentro da largura do botão. + ButtonText->SetJustification(TextAlign); + } + + // Texto adapta ao tamanho do botão (ScaleToFit) ou usa tamanho fixo. + if (TextScaleBox) + { + TextScaleBox->SetStretch(bAutoSizeText ? EStretch::ScaleToFit : EStretch::None); + + // Posiciona o bloco de texto L/C/R dentro do botão (slot do Overlay). + if (UOverlaySlot* OS = Cast(TextScaleBox->Slot)) + { + EHorizontalAlignment H = HAlign_Center; + switch (TextAlign) + { + case ETextJustify::Left: H = HAlign_Left; break; + case ETextJustify::Right: H = HAlign_Right; break; + default: H = HAlign_Center; break; + } + OS->SetHorizontalAlignment(H); + OS->SetVerticalAlignment(VAlign_Center); + } } BP_ApplyUIStyle(ActiveStyle.Button, VariantStyle); diff --git a/Source/ZMMO/Game/UI/Widgets/UIButton_Base.h b/Source/ZMMO/Game/UI/Widgets/UIButton_Base.h index 881a089..4caf79d 100644 --- a/Source/ZMMO/Game/UI/Widgets/UIButton_Base.h +++ b/Source/ZMMO/Game/UI/Widgets/UIButton_Base.h @@ -12,6 +12,8 @@ class UBorder; class UTextBlock; class UImage; class USizeBox; +class UScaleBox; +class UCommonTextBlock; class UCommonActionWidget; DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnUIButtonActivatedByTimeout); @@ -49,7 +51,16 @@ public: // ---- Text Style ---- UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Text Style") - FText ButtonTextValue; + FText ButtonTextValue = FText::FromString(TEXT("Button Text")); + + /** Alinhamento do texto dentro do botão (esquerda/centro/direita). */ + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Text Style") + TEnumAsByte TextAlign = ETextJustify::Center; + + /** true = texto escala p/ caber no tamanho do botão (ScaleBox ScaleToFit); + * false = usa o tamanho fixo da fonte da variante. */ + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Text Style") + bool bAutoSizeText = true; // ---- Number Text ---- UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Number Text") @@ -151,7 +162,11 @@ protected: TObjectPtr SizeBox_Master; UPROPERTY(meta = (BindWidgetOptional)) - TObjectPtr ButtonText; + TObjectPtr ButtonText; + + /** Envolve o ButtonText: escala o texto p/ caber no botão (bAutoSizeText). */ + UPROPERTY(meta = (BindWidgetOptional)) + TObjectPtr TextScaleBox; UPROPERTY(meta = (BindWidgetOptional)) TObjectPtr Number_Text;