Skip to content

Commit 948efb2

Browse files
committed
feat(Settings): enhance ModSettings UI and modal behavior
- Centered text alignment for buttons in ModSettings UI for improved aesthetics. - Added new parameters to modal dialog methods to control cancel button behavior and escape key functionality, enhancing user experience. - Updated minimum size resolution for action buttons in modal dialogs to ensure consistent layout across different themes. - Adjusted toast entry configuration to improve cursor interaction and visual feedback during user interactions.
1 parent d369f94 commit 948efb2

4 files changed

Lines changed: 30 additions & 17 deletions

File tree

Settings/ModSettingsUi/Controls/ModSettingsUiControls.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5739,6 +5739,7 @@ public ModSettingsTextButton(string text, ModSettingsButtonTone tone, Action? ac
57395739
_tone = tone;
57405740

57415741
Text = text;
5742+
Alignment = HorizontalAlignment.Center;
57425743
CustomMinimumSize = RitsuShellThemeLayoutResolver.ResolveMinSize(
57435744
"components.textButton.layout.minSize",
57445745
new(ModSettingsUiFactory.EntryControlWidth,
@@ -5785,6 +5786,7 @@ public ModSettingsTextButton()
57855786
public override void _Ready()
57865787
{
57875788
Text = _text ?? string.Empty;
5789+
Alignment = HorizontalAlignment.Center;
57885790
ApplyVisualState();
57895791
}
57905792

Settings/ModSettingsUi/Controls/ModSettingsUiFactory.Modal.cs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ internal static void ShowStyledConfirm(
2222
Action onConfirm,
2323
bool showCancel = true,
2424
Action? onCancel = null,
25-
Action? onDismiss = null)
25+
Action? onDismiss = null,
26+
bool escapeTriggersCancel = true,
27+
bool cancelIsDanger = false)
2628
{
2729
ArgumentNullException.ThrowIfNull(attachParent);
2830
ArgumentException.ThrowIfNullOrWhiteSpace(title);
@@ -132,6 +134,10 @@ internal static void ShowStyledConfirm(
132134
RitsuShellThemeLayoutResolver.ResolveInt("components.modal.layout.buttonRow.separation", 12));
133135
vbox.AddChild(btnRow);
134136

137+
var actionButtonMinSize = RitsuShellThemeLayoutResolver.ResolveMinSize(
138+
"components.modal.layout.buttonRow.actionMinSize",
139+
new(184f, RitsuShellTheme.Current.Metric.Entry.ValueMinHeight));
140+
135141
var confirmBtn = new ModSettingsTextButton(
136142
confirmText,
137143
confirmIsDanger ? ModSettingsButtonTone.Danger : ModSettingsButtonTone.Accent,
@@ -141,19 +147,20 @@ internal static void ShowStyledConfirm(
141147
CloseDialog(false, false);
142148
})
143149
{
144-
CustomMinimumSize = RitsuShellThemeLayoutResolver.ResolveMinSize(
145-
"components.modal.layout.buttonRow.confirmMinSize",
146-
new(168f, RitsuShellTheme.Current.Metric.Entry.ValueMinHeight)),
150+
CustomMinimumSize = actionButtonMinSize,
151+
SizeFlagsHorizontal = Control.SizeFlags.ShrinkEnd,
147152
};
148153

149154
ModSettingsTextButton? cancelBtn = null;
150155
if (showCancel)
151156
{
152-
cancelBtn = new(cancelText, ModSettingsButtonTone.Normal, () => CloseDialog(true, false))
157+
cancelBtn = new(
158+
cancelText,
159+
cancelIsDanger ? ModSettingsButtonTone.Danger : ModSettingsButtonTone.Normal,
160+
() => CloseDialog(true, false))
153161
{
154-
CustomMinimumSize = RitsuShellThemeLayoutResolver.ResolveMinSize(
155-
"components.modal.layout.buttonRow.cancelMinSize",
156-
new(132f, RitsuShellTheme.Current.Metric.Entry.ValueMinHeight)),
162+
CustomMinimumSize = actionButtonMinSize,
163+
SizeFlagsHorizontal = Control.SizeFlags.ShrinkEnd,
157164
};
158165
btnRow.AddChild(cancelBtn);
159166
}
@@ -181,12 +188,12 @@ internal static void ShowStyledConfirm(
181188

182189
var escShortcut = new Shortcut();
183190
escShortcut.Events = [new InputEventKey { Keycode = Key.Escape, Pressed = true }];
184-
if (cancelBtn != null)
191+
if (escapeTriggersCancel && cancelBtn != null)
185192
{
186193
cancelBtn.Shortcut = escShortcut;
187194
cancelBtn.ShortcutInTooltip = false;
188195
}
189-
else
196+
else if (escapeTriggersCancel)
190197
{
191198
confirmBtn.Shortcut = escShortcut;
192199
confirmBtn.ShortcutInTooltip = false;

Telemetry/Integration/TelemetryConsentPromptCoordinator.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ private static void ShowPendingConsentPrompt()
9999
() => GrantApplicant(applicant),
100100
true,
101101
() => DenyApplicant(applicant),
102-
ShowPendingConsentToast);
102+
ShowPendingConsentToast,
103+
false,
104+
true);
103105
}
104106

105107
private static TelemetryApplicant[] ResolvePendingApplicants()

Ui/Toast/RitsuToastEntry.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public RitsuToastEntry()
3434
public void Configure(RitsuToastRequest request, RitsuToastVisualStyle style)
3535
{
3636
_request = request;
37+
MouseDefaultCursorShape = CursorShape.PointingHand;
3738
ApplyContent();
3839
ApplyStyle(style);
3940
_isExiting = false;
@@ -57,8 +58,8 @@ public Vector2 Measure(float width, float minHeight)
5758
public void ApplyStyle(RitsuToastVisualStyle style)
5859
{
5960
_style = style;
60-
_panelNormal = BuildPanel(style, style.Border);
61-
_panelHover = BuildPanel(style, style.AccentColor);
61+
_panelNormal = BuildPanel(style, style.Border, false);
62+
_panelHover = BuildPanel(style, style.AccentColor, true);
6263
ApplyHoverVisual(false);
6364
_titleLabel?.AddThemeColorOverride("font_color", style.TitleColor);
6465
_titleLabel?.AddThemeFontSizeOverride("font_size", style.TitleFontSize);
@@ -234,11 +235,11 @@ private void ApplyContent()
234235
_image.Visible = _request.Image != null;
235236
}
236237

237-
private static StyleBoxFlat BuildPanel(RitsuToastVisualStyle style, Color borderColor)
238+
private static StyleBoxFlat BuildPanel(RitsuToastVisualStyle style, Color borderColor, bool hovering)
238239
{
239240
return new()
240241
{
241-
BgColor = style.Background,
242+
BgColor = hovering ? style.Background.Lerp(style.AccentColor, 0.045f) : style.Background,
242243
BorderColor = borderColor,
243244
BorderWidthLeft = style.BorderWidth,
244245
BorderWidthTop = style.BorderWidth,
@@ -248,8 +249,9 @@ private static StyleBoxFlat BuildPanel(RitsuToastVisualStyle style, Color border
248249
CornerRadiusTopRight = style.CornerRadius,
249250
CornerRadiusBottomRight = style.CornerRadius,
250251
CornerRadiusBottomLeft = style.CornerRadius,
251-
ShadowColor = style.ShadowColor,
252-
ShadowSize = (int)Math.Round(style.ShadowSize, MidpointRounding.AwayFromZero),
252+
ShadowColor = hovering ? new(borderColor.R, borderColor.G, borderColor.B, 0.28f) : style.ShadowColor,
253+
ShadowSize = (int)Math.Round(hovering ? style.ShadowSize + 5f : style.ShadowSize,
254+
MidpointRounding.AwayFromZero),
253255
ContentMarginLeft = style.PaddingHorizontal,
254256
ContentMarginTop = style.PaddingVertical,
255257
ContentMarginRight = style.PaddingHorizontal,

0 commit comments

Comments
 (0)