Skip to content

Commit 21f6e57

Browse files
committed
Improve log dialog layout
1 parent 9cf99c1 commit 21f6e57

4 files changed

Lines changed: 64 additions & 23 deletions

File tree

BetterModMenu.Tests/LogicTests.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,6 +1086,17 @@ public void FitTutorialDialogToViewport_ReservesRoomForDialogButtons()
10861086
Assert.IsTrue(layout.PopupHeight - layout.ContentHeight >= 180);
10871087
}
10881088

1089+
[TestMethod]
1090+
public void GetPreferredLogDialogLayout_ReservesVisibleActionRowOutsideScroll()
1091+
{
1092+
LogDialogLayout layout = ModdingScreenDialogRules.GetPreferredLogDialogLayout();
1093+
1094+
Assert.IsTrue(layout.ActionRowHeight >= 40);
1095+
Assert.IsTrue(layout.ScrollHeight < layout.PanelHeight);
1096+
Assert.IsTrue(layout.ScrollHeight + layout.ActionRowHeight <= layout.PanelHeight);
1097+
Assert.IsTrue(layout.PopupHeight > layout.PanelHeight);
1098+
}
1099+
10891100
[TestMethod]
10901101
public void ShouldCreateAutomaticBackup_RunsAutomaticReasonsOnceAndNeverForManual()
10911102
{

Patches/ModdingScreenChromeOps.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,23 +277,26 @@ private static void ReapplyModsScrollbarAfterFrame(NModdingScreen screen, NScrol
277277

278278
private static void MaintainModsScrollbar(NModdingScreen screen, NScrollableContainer scrollContainer)
279279
{
280-
ClampModsScrollIfContentFits(screen, scrollContainer);
280+
if (ClampModsScrollIfContentFits(screen, scrollContainer))
281+
return;
282+
281283
ForceModsScrollbarVisible(scrollContainer);
282284
}
283285

284-
private static void ClampModsScrollIfContentFits(NModdingScreen screen, NScrollableContainer scrollContainer)
286+
private static bool ClampModsScrollIfContentFits(NModdingScreen screen, NScrollableContainer scrollContainer)
285287
{
286288
var content = ModdingScreenNodeOps.GetModRowContainer(screen);
287289
var viewport = content?.GetParentOrNull<Control>();
288290
if (content == null || viewport == null)
289-
return;
291+
return false;
290292

291293
content.UpdateMinimumSize();
292294
if (content.GetCombinedMinimumSize().Y > viewport.Size.Y + ModdingScreenConstants.ScrollFitTolerance)
293-
return;
295+
return false;
294296

295297
scrollContainer.DisableScrollingIfContentFits();
296298
scrollContainer.InstantlyScrollToTop();
299+
return true;
297300
}
298301

299302
private static void ForceModsScrollbarVisible(NScrollableContainer scrollContainer)

Patches/ModdingScreenDialogRules.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,31 @@ internal readonly record struct TutorialDialogLayout(
1414
int ContentHorizontalPadding,
1515
int ContentVerticalPadding);
1616

17+
internal readonly record struct LogDialogLayout(
18+
int PopupWidth,
19+
int PopupHeight,
20+
int PanelWidth,
21+
int PanelHeight,
22+
int ScrollHeight,
23+
int BodyFontSize,
24+
int ButtonFontSize,
25+
int ActionRowHeight);
26+
1727
internal static class ModdingScreenDialogRules
1828
{
29+
public static LogDialogLayout GetPreferredLogDialogLayout()
30+
{
31+
return new LogDialogLayout(
32+
PopupWidth: 1080,
33+
PopupHeight: 680,
34+
PanelWidth: 1020,
35+
PanelHeight: 600,
36+
ScrollHeight: 540,
37+
BodyFontSize: 22,
38+
ButtonFontSize: 22,
39+
ActionRowHeight: 44);
40+
}
41+
1942
public static TutorialDialogLayout GetPreferredTutorialDialogLayout()
2043
{
2144
return new TutorialDialogLayout(

Patches/ModdingScreenDialogs.cs

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,6 @@ namespace BetterModMenu.Patches;
88
internal static class ModdingScreenDialogs
99
{
1010
private const int MaxVisibleBackupChoices = 12;
11-
private const int LogPopupWidth = 1080;
12-
private const int LogPopupHeight = 680;
13-
private const int LogContentWidth = 1020;
14-
private const int LogContentHeight = 600;
15-
private const int LogBodyFontSize = 22;
16-
private const int LogButtonFontSize = 22;
1711

1812
public static void ShowInfoDialog(NModdingScreen screen, string title, string message)
1913
{
@@ -100,30 +94,26 @@ public static void ShowBackupSelectionDialog(NModdingScreen screen, IReadOnlyLis
10094

10195
public static void ShowLogDialog(NModdingScreen screen, string title, string content, string logPath)
10296
{
97+
LogDialogLayout layout = ModdingScreenDialogRules.GetPreferredLogDialogLayout();
10398
var popup = new AcceptDialog
10499
{
105100
Title = title,
106101
DialogText = string.Empty
107102
};
108103

109-
var scroll = new ScrollContainer
110-
{
111-
HorizontalScrollMode = ScrollContainer.ScrollMode.Disabled,
112-
SizeFlagsHorizontal = Control.SizeFlags.ExpandFill,
113-
SizeFlagsVertical = Control.SizeFlags.ExpandFill
114-
};
115104
var panel = new PanelContainer
116105
{
117-
CustomMinimumSize = new Vector2(LogContentWidth, LogContentHeight)
106+
CustomMinimumSize = new Vector2(layout.PanelWidth, layout.PanelHeight)
118107
};
119108
ModdingScreenVanillaStyle.ApplyLogPanel(panel);
120-
var contentBox = new VBoxContainer
109+
var panelBox = new VBoxContainer
121110
{
122111
SizeFlagsHorizontal = Control.SizeFlags.ExpandFill,
123112
SizeFlagsVertical = Control.SizeFlags.ExpandFill
124113
};
125114
var actionRow = new HBoxContainer
126115
{
116+
CustomMinimumSize = new Vector2(0, layout.ActionRowHeight),
127117
SizeFlagsHorizontal = Control.SizeFlags.ExpandFill
128118
};
129119
var copyButton = new Button
@@ -143,7 +133,20 @@ public static void ShowLogDialog(NModdingScreen screen, string title, string con
143133
ModdingScreenVanillaStyle.ApplyButton(openFolderButton);
144134
openFolderButton.Pressed += () => OpenLogFolder(screen, logPath);
145135
actionRow.AddChild(openFolderButton);
146-
contentBox.AddChild(actionRow);
136+
panelBox.AddChild(actionRow);
137+
138+
var scroll = new ScrollContainer
139+
{
140+
HorizontalScrollMode = ScrollContainer.ScrollMode.Disabled,
141+
CustomMinimumSize = new Vector2(0, layout.ScrollHeight),
142+
SizeFlagsHorizontal = Control.SizeFlags.ExpandFill,
143+
SizeFlagsVertical = Control.SizeFlags.ExpandFill
144+
};
145+
var contentBox = new VBoxContainer
146+
{
147+
SizeFlagsHorizontal = Control.SizeFlags.ExpandFill,
148+
SizeFlagsVertical = Control.SizeFlags.ExpandFill
149+
};
147150

148151
var label = new RichTextLabel
149152
{
@@ -158,15 +161,16 @@ public static void ShowLogDialog(NModdingScreen screen, string title, string con
158161
SizeFlagsVertical = Control.SizeFlags.ExpandFill
159162
};
160163
label.AddThemeColorOverride("default_color", new Color(0.92f, 0.86f, 0.74f, 1f));
161-
label.AddThemeFontSizeOverride("font_size", LogBodyFontSize);
164+
label.AddThemeFontSizeOverride("font_size", layout.BodyFontSize);
162165

163166
contentBox.AddChild(label);
164167
scroll.AddChild(contentBox);
165-
panel.AddChild(scroll);
168+
panelBox.AddChild(scroll);
169+
panel.AddChild(panelBox);
166170
popup.AddChild(panel);
167-
ApplyReadableDialogButtons(popup, LogButtonFontSize);
171+
ApplyReadableDialogButtons(popup, layout.ButtonFontSize);
168172
screen.AddChild(popup);
169-
popup.PopupCentered(new Vector2I(LogPopupWidth, LogPopupHeight));
173+
popup.PopupCentered(new Vector2I(layout.PopupWidth, layout.PopupHeight));
170174
}
171175

172176
private static void OpenLogFolder(NModdingScreen screen, string logPath)

0 commit comments

Comments
 (0)