Skip to content

Commit ccc46ae

Browse files
committed
an approach at updating the Tile size when the fontsize/padding changes.
numColums removed cell padding added (which gives some control about the space between the entries)
1 parent 2ea4ccc commit ccc46ae

File tree

5 files changed

+58
-33
lines changed

5 files changed

+58
-33
lines changed

Source/UnicodeBrowser/UnicodeBrowserOptions.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ class UNICODEBROWSER_API UUnicodeBrowserOptions : public UDeveloperSettings
1717
UPROPERTY(DisplayName="Preset")
1818
TObjectPtr<UDataAsset_FontTags> Preset;
1919

20-
UPROPERTY(Config, EditAnywhere, meta=(UIMin=1))
21-
int32 NumCols = 16;
20+
UPROPERTY(Config, EditAnywhere, meta=(UIMin=0))
21+
int32 GridCellPadding = 5;
2222

2323
// allow to toggle the right side panel on/off
2424
UPROPERTY(Config, EditAnywhere)

Source/UnicodeBrowser/UnicodeBrowserWidget.cpp

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ void SUnicodeBrowserWidget::Construct(FArguments const& InArgs)
3636

3737
UUnicodeBrowserOptions::Get()->OnFontChanged.RemoveAll(this);
3838
UUnicodeBrowserOptions::Get()->OnFontChanged.AddLambda([this, UnicodeBrowser = AsWeak()]()
39-
{
39+
{
4040
if(UnicodeBrowser.IsValid()){
4141
if( CurrentFont.FontObject != UUnicodeBrowserOptions::Get()->GetFontInfo().FontObject
4242
|| CurrentFont.TypefaceFontName != UUnicodeBrowserOptions::Get()->GetFontInfo().TypefaceFontName)
@@ -250,8 +250,9 @@ void SUnicodeBrowserWidget::Construct(FArguments const& InArgs)
250250
];
251251

252252
SetSidePanelVisibility(UUnicodeBrowserOptions::Get()->bShowSidePanel);
253-
254-
MarkDirty(static_cast<uint8>(EDirtyFlags::INIT) | static_cast<uint8>(EDirtyFlags::FONT));
253+
254+
MarkDirty(static_cast<uint8>(EDirtyFlags::INIT));
255+
MarkDirty(static_cast<uint8>(EDirtyFlags::FONT));
255256
}
256257

257258
UToolMenu* SUnicodeBrowserWidget::CreateMenuSection_Settings()
@@ -351,27 +352,28 @@ UToolMenu* SUnicodeBrowserWidget::CreateMenuSection_Settings()
351352
.AutoWidth()
352353
[
353354
SNew(STextBlock)
354-
.Text(INVTEXT("columns"))
355+
.Text(INVTEXT("cell padding"))
355356
]
356357
+SHorizontalBox::Slot()
357358
.Padding(10, 0, 10, 0)
358359
.VAlign(VAlign_Center)
359360
[
360361
SNew(SSpinBox<int32>)
361362
.Delta(1)
362-
.MinValue(1)
363-
.MaxValue(32)
364-
.Value_Lambda([this]() { return UUnicodeBrowserOptions::Get()->NumCols; })
363+
.MinValue(0)
364+
.MaxValue(25)
365+
.Value_Lambda([this]() { return UUnicodeBrowserOptions::Get()->GridCellPadding; })
365366
.OnValueChanged_Lambda([this](int32 CurrentValue)
366367
{
367-
UUnicodeBrowserOptions::Get()->NumCols = CurrentValue;
368+
UUnicodeBrowserOptions::Get()->GridCellPadding = CurrentValue;
368369
UUnicodeBrowserOptions::Get()->TryUpdateDefaultConfigFile();
369370
CharactersTileView->RebuildList();
371+
MarkDirty(static_cast<uint8>(EDirtyFlags::FONT_STYLE));
370372
})
371373
]
372374
];
373375

374-
DisplaySettingsSection.AddEntry(FToolMenuEntry::InitWidget("BrowserNumColumns", Widget, FText::GetEmpty(), false, false, false, INVTEXT("you can use CTRL + Shift + MouseWheel to adjust column count in the browser")));
376+
DisplaySettingsSection.AddEntry(FToolMenuEntry::InitWidget("BrowserGridCellPadding", Widget, FText::GetEmpty(), false, false, false, INVTEXT("you can use CTRL + Shift + MouseWheel to adjust cell padding in the browser")));
375377
}
376378

377379

@@ -402,6 +404,7 @@ TSharedRef<ITableRow> SUnicodeBrowserWidget::GenerateItemRow(TSharedPtr<FUnicode
402404
.UnicodeCharacter(CharacterData)
403405
.OnMouseMove(this, &SUnicodeBrowserWidget::OnCharacterMouseMove, CharacterData)
404406
.OnZoomFontSize(this, &SUnicodeBrowserWidget::HandleZoomFont)
407+
.OnZoomCellPadding(this, &SUnicodeBrowserWidget::HandleZoomPadding)
405408
];
406409
}
407410

@@ -410,6 +413,27 @@ void SUnicodeBrowserWidget::Tick(FGeometry const& AllottedGeometry, double const
410413
{
411414
if (DirtyFlags && IsConstructed()) // wait for the widget to be constructed before updating
412415
{
416+
// grid size MUST be evaluated before the font, because FONT flag may set it dirty for the next tick
417+
if(DirtyFlags & static_cast<uint8>(EDirtyFlags::TILEVIEW_GRID_SIZE))
418+
{
419+
double DesiredSize = 0;
420+
for(int ChildIdx = 0; ChildIdx < CharactersTileView->GetNumGeneratedChildren(); ChildIdx++){
421+
if(!CharactersTileView->GetGeneratedChildAt(ChildIdx).Get()->NeedsPrepass())
422+
{
423+
FVector2D ChildDesiredSize = CharactersTileView->GetGeneratedChildAt(ChildIdx).Get()->GetDesiredSize();
424+
DesiredSize = FMath::Max(DesiredSize, FMath::Max(ChildDesiredSize.X, ChildDesiredSize.X));
425+
}
426+
}
427+
428+
if(DesiredSize > 0){
429+
CharactersTileView->SetItemWidth(FMath::Min(DesiredSize, CharactersTileView->GetCachedGeometry().Size.X / 2.0));
430+
CharactersTileView->SetItemHeight(FMath::Min(DesiredSize, CharactersTileView->GetCachedGeometry().Size.Y / 2.0));
431+
CharactersTileView->RebuildList();
432+
}
433+
434+
DirtyFlags &= ~static_cast<uint8>(EDirtyFlags::TILEVIEW_GRID_SIZE);
435+
}
436+
413437
if(DirtyFlags & static_cast<uint8>(EDirtyFlags::FONT))
414438
{
415439
CurrentFont = UUnicodeBrowserOptions::Get()->GetFontInfo();
@@ -444,11 +468,12 @@ void SUnicodeBrowserWidget::Tick(FGeometry const& AllottedGeometry, double const
444468

445469
if(DirtyFlags & static_cast<uint8>(EDirtyFlags::FONT_STYLE))
446470
{
447-
CharactersTileView->RebuildList();
471+
CharactersTileView->RebuildList();
472+
MarkDirty(static_cast<uint8>(EDirtyFlags::TILEVIEW_GRID_SIZE)); // set grid size dirty
448473
DirtyFlags &= ~static_cast<uint8>(EDirtyFlags::FONT_STYLE);
449474
}
450475
}
451-
476+
452477
if(DirtyFlags & static_cast<uint8>(EDirtyFlags::INIT)){
453478
if(SidePanel.IsValid() && SidePanel->RangeSelector.IsValid())
454479
{
@@ -642,12 +667,14 @@ void SUnicodeBrowserWidget::HandleZoomFont(float Offset)
642667
}
643668

644669

645-
void SUnicodeBrowserWidget::HandleZoomColumns(float Offset)
670+
void SUnicodeBrowserWidget::HandleZoomPadding(float Offset)
646671
{
647-
// we want inverted behavior for columns
648-
UUnicodeBrowserOptions::Get()->NumCols = FMath::Max(1, FMath::RoundToInt(UUnicodeBrowserOptions::Get()->NumCols - Offset));
649-
672+
// we want inverted behavior for cellpadding
673+
UUnicodeBrowserOptions::Get()->GridCellPadding = FMath::Max(0, FMath::RoundToInt(UUnicodeBrowserOptions::Get()->GridCellPadding - Offset));
674+
UUnicodeBrowserOptions::Get()->TryUpdateDefaultConfigFile();
675+
650676
CharactersTileView->RebuildList();
677+
MarkDirty(static_cast<uint8>(EDirtyFlags::FONT_STYLE));
651678
}
652679

653680
END_SLATE_FUNCTION_BUILD_OPTIMIZATION

Source/UnicodeBrowser/UnicodeBrowserWidget.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
#include "Widgets/SCompoundWidget.h"
1111
#include "Widgets/SUbSearchBar.h"
12-
#include "Widgets/SUnicodeCharacterGridEntry.h"
1312
#include "Widgets/Views/SListView.h"
1413
#include "Widgets/Views/STileView.h"
1514

@@ -68,7 +67,8 @@ class SUnicodeBrowserWidget : public SCompoundWidget
6867
INIT = 1 << 0,
6968
FONT_FACE = 1 << 1, // never use this to call MarkDirt, use FONT which also invalidates the style
7069
FONT_STYLE = 1 << 2,
71-
FONT = FONT_FACE | FONT_STYLE
70+
FONT = FONT_FACE | FONT_STYLE,
71+
TILEVIEW_GRID_SIZE = 1 << 3
7272
};
7373

7474
public:
@@ -83,9 +83,8 @@ class SUnicodeBrowserWidget : public SCompoundWidget
8383

8484
FSlateFontInfo DefaultFont = FCoreStyle::GetDefaultFontStyle("Regular", 18);
8585

86-
TMap<EUnicodeBlockRange, TArray<TSharedPtr<FUnicodeBrowserRow>>> RowsRaw;
87-
88-
TMap<EUnicodeBlockRange, TArray<TSharedPtr<FUnicodeBrowserRow>>> Rows;
86+
TMap<EUnicodeBlockRange, TArray<TSharedPtr<FUnicodeBrowserRow>>> RowsRaw; // a raw list of all characters for the current font
87+
TMap<EUnicodeBlockRange, TArray<TSharedPtr<FUnicodeBrowserRow>>> Rows; // a filtered view of the raw data, those are the characters that a
8988

9089
public:
9190
virtual ~SUnicodeBrowserWidget() override;
@@ -103,10 +102,8 @@ class SUnicodeBrowserWidget : public SCompoundWidget
103102

104103
mutable TSharedPtr<FUnicodeBrowserRow> CurrentRow;
105104
FSlateFontInfo CurrentFont = DefaultFont;
106-
107105

108106
protected:
109-
void Update(bool bForceRepopulateCharacters = false);
110107
void PopulateSupportedCharacters();
111108
void UpdateCharacters();
112109
void UpdateCharactersArray();
@@ -116,7 +113,7 @@ class SUnicodeBrowserWidget : public SCompoundWidget
116113

117114
FReply OnCharacterMouseMove(FGeometry const& Geometry, FPointerEvent const& PointerEvent, TSharedPtr<FUnicodeBrowserRow> Row) const;
118115
void HandleZoomFont(float Offset);
119-
void HandleZoomColumns(float Offset);
116+
void HandleZoomPadding(float Offset);
120117

121118
private:
122119
UToolMenu* CreateMenuSection_Settings();

Source/UnicodeBrowser/Widgets/SUnicodeCharacterGridEntry.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include "SlateOptMacros.h"
55
#include "HAL/PlatformApplicationMisc.h"
6+
#include "UnicodeBrowser/UnicodeBrowserOptions.h"
67

78
BEGIN_SLATE_FUNCTION_BUILD_OPTIMIZATION
89

@@ -11,14 +12,13 @@ void SUnicodeCharacterGridEntry::Construct(const FArguments& InArgs)
1112
UnicodeCharacter = InArgs._UnicodeCharacter.Get();
1213

1314
OnZoomFontSize = InArgs._OnZoomFontSize;
14-
OnZoomColumnCount = InArgs._OnZoomColumnCount;
15+
OnZoomCellPadding = InArgs._OnZoomCellPadding;
1516

1617
SBorder::Construct(SBorder::FArguments()
1718
.BorderImage(nullptr)
1819
.OnMouseMove(InArgs._OnMouseMove)
19-
.Padding(5)
20-
.VAlign(VAlign_Center)
21-
);
20+
.VAlign(VAlign_Center)
21+
);
2222

2323
if(!UnicodeCharacter.IsValid())
2424
{
@@ -33,6 +33,7 @@ void SUnicodeCharacterGridEntry::Construct(const FArguments& InArgs)
3333
.Justification(ETextJustify::Center)
3434
.Text(FText::FromString(*UnicodeCharacter->Character))
3535
.Visibility(EVisibility::HitTestInvisible)
36+
.Margin(UUnicodeBrowserOptions::Get()->GridCellPadding)
3637
];
3738

3839
}
@@ -68,9 +69,9 @@ FReply SUnicodeCharacterGridEntry::OnMouseWheel(const FGeometry& MyGeometry, con
6869
}
6970

7071
// CTRL + Shift => Zoom Columns
71-
if(MouseEvent.IsShiftDown() && OnZoomColumnCount.IsBound())
72+
if(MouseEvent.IsShiftDown() && OnZoomCellPadding.IsBound())
7273
{
73-
OnZoomColumnCount.Execute(MouseEvent.GetWheelDelta());
74+
OnZoomCellPadding.Execute(MouseEvent.GetWheelDelta());
7475
return FReply::Handled();
7576
}
7677
}

Source/UnicodeBrowser/Widgets/SUnicodeCharacterGridEntry.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class UNICODEBROWSER_API SUnicodeCharacterGridEntry : public SBorder
1717
SLATE_EVENT(FPointerEventHandler, OnMouseMove)
1818
SLATE_EVENT(FPointerEventHandler, OnMouseDoubleClick)
1919
SLATE_EVENT(FZoomEvent, OnZoomFontSize)
20-
SLATE_EVENT(FZoomEvent, OnZoomColumnCount)
20+
SLATE_EVENT(FZoomEvent, OnZoomCellPadding)
2121
SLATE_END_ARGS()
2222

2323
/** Constructs this widget with InArgs */
@@ -36,5 +36,5 @@ class UNICODEBROWSER_API SUnicodeCharacterGridEntry : public SBorder
3636

3737

3838
FZoomEvent OnZoomFontSize;
39-
FZoomEvent OnZoomColumnCount;
39+
FZoomEvent OnZoomCellPadding;
4040
};

0 commit comments

Comments
 (0)