Skip to content

Commit 749bf03

Browse files
committed
fix vgui corner radius
1 parent 787fa19 commit 749bf03

10 files changed

Lines changed: 167 additions & 372 deletions

File tree

src/PleasantUI.ToolKit/Controls/CrashReportDialog/CrashReportDialog.cs

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -535,45 +535,6 @@ public string UserMessagePlaceholder
535535
// Tab items — built once and reused.
536536
private readonly List<string> _tabs = new();
537537

538-
static CrashReportDialog()
539-
{
540-
CornerRadiusProperty.Changed.AddClassHandler<CrashReportDialog>((x, e) => x.OnCornerRadiusChanged(e));
541-
}
542-
543-
private void OnCornerRadiusChanged(AvaloniaPropertyChangedEventArgs e)
544-
{
545-
try
546-
{
547-
if (IsVGUIActive())
548-
{
549-
System.Diagnostics.Debug.WriteLine("[CrashReportDialog] VGUI theme active, setting CornerRadius to 0");
550-
SetValue(CornerRadiusProperty, new CornerRadius(0));
551-
}
552-
}
553-
catch (Exception ex)
554-
{
555-
System.Diagnostics.Debug.WriteLine($"[CrashReportDialog] Error in OnCornerRadiusChanged: {ex.Message}");
556-
}
557-
}
558-
559-
/// <summary>
560-
/// Checks if the VGUI theme is currently active.
561-
/// </summary>
562-
protected static bool IsVGUIActive()
563-
{
564-
try
565-
{
566-
var isActive = PleasantUI.Core.PleasantSettings.Current?.Theme == "VGUI";
567-
System.Diagnostics.Debug.WriteLine($"[CrashReportDialog] IsVGUIActive: {isActive}");
568-
return isActive;
569-
}
570-
catch (Exception ex)
571-
{
572-
System.Diagnostics.Debug.WriteLine($"[CrashReportDialog] Error checking VGUI status: {ex.Message}");
573-
return false;
574-
}
575-
}
576-
577538
// ── Convenience factory ───────────────────────────────────────────────────
578539

579540
/// <summary>
@@ -610,19 +571,6 @@ protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
610571
{
611572
base.OnApplyTemplate(e);
612573

613-
try
614-
{
615-
if (IsVGUIActive())
616-
{
617-
System.Diagnostics.Debug.WriteLine("[CrashReportDialog] OnApplyTemplate: VGUI theme active, setting CornerRadius to 0");
618-
CornerRadius = new CornerRadius(0);
619-
}
620-
}
621-
catch (Exception ex)
622-
{
623-
System.Diagnostics.Debug.WriteLine($"[CrashReportDialog] Error in OnApplyTemplate: {ex.Message}");
624-
}
625-
626574
DetachHandlers();
627575

628576
_sendButton = e.NameScope.Find<Button>(PART_SendButton);

src/PleasantUI.ToolKit/Controls/StepDialog/StepDialog.cs

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -164,69 +164,17 @@ public Animation? CloseAnimation
164164

165165
// ── Constructor ───────────────────────────────────────────────────────────
166166

167-
static StepDialog()
168-
{
169-
CornerRadiusProperty.Changed.AddClassHandler<StepDialog>((x, e) => x.OnCornerRadiusChanged(e));
170-
}
171-
172167
public StepDialog()
173168
{
174169
Steps.CollectionChanged += OnStepsChanged;
175170
}
176171

177-
private void OnCornerRadiusChanged(AvaloniaPropertyChangedEventArgs e)
178-
{
179-
try
180-
{
181-
if (IsVGUIActive())
182-
{
183-
System.Diagnostics.Debug.WriteLine("[StepDialog] VGUI theme active, setting CornerRadius to 0");
184-
SetValue(CornerRadiusProperty, new CornerRadius(0));
185-
}
186-
}
187-
catch (Exception ex)
188-
{
189-
System.Diagnostics.Debug.WriteLine($"[StepDialog] Error in OnCornerRadiusChanged: {ex.Message}");
190-
}
191-
}
192-
193-
/// <summary>
194-
/// Checks if the VGUI theme is currently active.
195-
/// </summary>
196-
protected static bool IsVGUIActive()
197-
{
198-
try
199-
{
200-
var isActive = PleasantUI.Core.PleasantSettings.Current?.Theme == "VGUI";
201-
System.Diagnostics.Debug.WriteLine($"[StepDialog] IsVGUIActive: {isActive}");
202-
return isActive;
203-
}
204-
catch (Exception ex)
205-
{
206-
System.Diagnostics.Debug.WriteLine($"[StepDialog] Error checking VGUI status: {ex.Message}");
207-
return false;
208-
}
209-
}
210-
211172
// ── Template ──────────────────────────────────────────────────────────────
212173

213174
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
214175
{
215176
base.OnApplyTemplate(e);
216177

217-
try
218-
{
219-
if (IsVGUIActive())
220-
{
221-
System.Diagnostics.Debug.WriteLine("[StepDialog] OnApplyTemplate: VGUI theme active, setting CornerRadius to 0");
222-
CornerRadius = new CornerRadius(0);
223-
}
224-
}
225-
catch (Exception ex)
226-
{
227-
System.Diagnostics.Debug.WriteLine($"[StepDialog] Error in OnApplyTemplate: {ex.Message}");
228-
}
229-
230178
DetachHandlers();
231179

232180
_closeButton = e.NameScope.Find<Button>(PART_CloseButton);

src/PleasantUI.ToolKit/PleasantUIToolKit.axaml.cs

Lines changed: 107 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Avalonia.Markup.Xaml;
44
using Avalonia.Markup.Xaml.Styling;
55
using Avalonia.Styling;
6+
using PleasantUI.Core;
67

78
namespace PleasantUI.ToolKit;
89

@@ -13,6 +14,7 @@ public class PleasantUIToolKit : ResourceDictionary
1314
{
1415
private static PleasantUIToolKit? _instance;
1516
private StyleInclude? _vguiStyleInclude;
17+
private bool _listenerAdded = false;
1618

1719
/// <summary>
1820
/// Gets the singleton instance of PleasantUIToolKit
@@ -26,6 +28,109 @@ public PleasantUIToolKit()
2628
{
2729
_instance = this;
2830
AvaloniaXamlLoader.Load(this);
31+
32+
TryAddListener();
33+
}
34+
35+
private void TryAddListener()
36+
{
37+
if (_listenerAdded) return;
38+
39+
if (PleasantSettings.Current is not null)
40+
{
41+
PleasantSettings.Current.PropertyChanged += OnPleasantSettingsChanged;
42+
_listenerAdded = true;
43+
// Check if VGUI is already active
44+
UpdateVGUIStyle(PleasantSettings.Current.Theme == "VGUI");
45+
System.Diagnostics.Debug.WriteLine("[PleasantUIToolKit] Listener added, checking VGUI status");
46+
}
47+
else
48+
{
49+
System.Diagnostics.Debug.WriteLine("[PleasantUIToolKit] PleasantSettings.Current is null, will retry later");
50+
// Retry after a delay
51+
System.Threading.Tasks.Task.Delay(100).ContinueWith(_ =>
52+
{
53+
Avalonia.Threading.Dispatcher.UIThread.Post(TryAddListener);
54+
});
55+
}
56+
}
57+
58+
private void OnPleasantSettingsChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
59+
{
60+
if (e.PropertyName == nameof(PleasantSettings.Current.Theme))
61+
{
62+
UpdateVGUIStyle(PleasantSettings.Current?.Theme == "VGUI");
63+
}
64+
}
65+
66+
/// <summary>
67+
/// Manually triggers VGUI style update (called from PleasantTheme via reflection)
68+
/// </summary>
69+
public static void UpdateVGUIStyleManually(bool isVGUI)
70+
{
71+
System.Diagnostics.Debug.WriteLine($"[PleasantUIToolKit] UpdateVGUIStyleManually called with isVGUI={isVGUI}");
72+
73+
if (Avalonia.Application.Current?.Resources is null)
74+
{
75+
System.Diagnostics.Debug.WriteLine("[PleasantUIToolKit] Application.Current.Resources is null");
76+
return;
77+
}
78+
79+
System.Diagnostics.Debug.WriteLine($"[PleasantUIToolKit] Application.Current.Resources.MergedDictionaries count: {Avalonia.Application.Current.Resources.MergedDictionaries.Count}");
80+
81+
// Log all resources to debug
82+
int index = 0;
83+
foreach (var resource in Avalonia.Application.Current.Resources.MergedDictionaries)
84+
{
85+
string resourceInfo = resource?.GetType().FullName ?? "null";
86+
if (resource is Avalonia.Markup.Xaml.Styling.ResourceInclude ri)
87+
{
88+
resourceInfo += $" (Source: {ri.Source})";
89+
}
90+
System.Diagnostics.Debug.WriteLine($"[PleasantUIToolKit] Resource [{index}]: {resourceInfo}");
91+
index++;
92+
}
93+
94+
// Find PleasantUIToolKit in MergedDictionaries
95+
PleasantUIToolKit? toolKit = null;
96+
foreach (var resource in Avalonia.Application.Current.Resources.MergedDictionaries)
97+
{
98+
if (resource is PleasantUIToolKit tk)
99+
{
100+
toolKit = tk;
101+
break;
102+
}
103+
}
104+
105+
if (toolKit is not null)
106+
{
107+
toolKit.UpdateVGUIStyle(isVGUI);
108+
}
109+
else
110+
{
111+
System.Diagnostics.Debug.WriteLine("[PleasantUIToolKit] PleasantUIToolKit not found in Application.Resources.MergedDictionaries");
112+
// Try to find it recursively in nested MergedDictionaries
113+
FindRecursive(Avalonia.Application.Current.Resources, 0);
114+
}
115+
}
116+
117+
private static void FindRecursive(IResourceDictionary dict, int depth)
118+
{
119+
string indent = new string(' ', depth * 2);
120+
System.Diagnostics.Debug.WriteLine($"{indent}Checking dictionary: {dict?.GetType().FullName}");
121+
122+
if (dict is PleasantUIToolKit)
123+
{
124+
System.Diagnostics.Debug.WriteLine($"{indent}FOUND PleasantUIToolKit!");
125+
}
126+
127+
foreach (var resource in dict.MergedDictionaries)
128+
{
129+
if (resource is IResourceDictionary rd)
130+
{
131+
FindRecursive(rd, depth + 1);
132+
}
133+
}
29134
}
30135

31136
/// <summary>
@@ -35,6 +140,7 @@ public PleasantUIToolKit()
35140
public void UpdateVGUIStyle(bool isVGUI)
36141
{
37142
System.Diagnostics.Debug.WriteLine($"[PleasantUIToolKit] UpdateVGUIStyle called with isVGUI={isVGUI}");
143+
System.Diagnostics.Debug.WriteLine($"[PleasantUIToolKit] MergedDictionaries count before: {MergedDictionaries.Count}");
38144

39145
if (isVGUI)
40146
{
@@ -48,7 +154,7 @@ public void UpdateVGUIStyle(bool isVGUI)
48154
Source = new Uri("avares://PleasantUI.ToolKit/Styling/VGUIControlThemes.axaml")
49155
};
50156
MergedDictionaries.Add(_vguiStyleInclude);
51-
System.Diagnostics.Debug.WriteLine("[PleasantUIToolKit] VGUIControlThemes.axaml added successfully");
157+
System.Diagnostics.Debug.WriteLine($"[PleasantUIToolKit] VGUIControlThemes.axaml added successfully, MergedDictionaries count after: {MergedDictionaries.Count}");
52158
}
53159
catch (Exception ex)
54160
{

src/PleasantUI.ToolKit/Styling/ControlThemes/PleasantToolKitControls/CrashReportDialog.axaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
<Setter Property="Opacity" Value="0" />
5858
<Setter Property="MinWidth" Value="560" />
5959
<Setter Property="MaxWidth" Value="680" />
60+
<Setter Property="CornerRadius" Value="{DynamicResource ControlCornerRadius}" />
6061

6162
<Setter Property="OpenAnimation">
6263
<Animation Duration="0:0:0.22" FillMode="Both" Easing="CubicEaseOut">
@@ -90,14 +91,14 @@
9091

9192
<Setter Property="Template">
9293
<ControlTemplate>
93-
<ShadowBorder CornerRadius="{DynamicResource ControlCornerRadius}"
94+
<ShadowBorder CornerRadius="{TemplateBinding CornerRadius}"
9495
BlurRadius="50"
9596
ShadowColor="#6E000000"
9697
Offset="0 8">
9798
<Border Background="{DynamicResource BackgroundColor1}"
9899
BorderBrush="{DynamicResource ControlBorderColor}"
99100
BorderThickness="{DynamicResource ControlBorderThickness}"
100-
CornerRadius="{DynamicResource ControlCornerRadius}"
101+
CornerRadius="{TemplateBinding CornerRadius}"
101102
ClipToBounds="True">
102103
<Grid RowDefinitions="Auto,Auto,*,Auto">
103104

src/PleasantUI.ToolKit/Styling/ControlThemes/PleasantToolKitControls/StepDialog.axaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
<Setter Property="HorizontalAlignment" Value="Center" />
8989
<Setter Property="VerticalAlignment" Value="Center" />
9090
<Setter Property="Opacity" Value="0" />
91+
<Setter Property="CornerRadius" Value="{DynamicResource ControlCornerRadius}" />
9192

9293
<Setter Property="OpenAnimation">
9394
<Animation Duration="0:0:0.2" FillMode="Both" Easing="CubicEaseOut">
@@ -121,14 +122,14 @@
121122

122123
<Setter Property="Template">
123124
<ControlTemplate>
124-
<ShadowBorder CornerRadius="{DynamicResource ControlCornerRadius}"
125+
<ShadowBorder CornerRadius="{TemplateBinding CornerRadius}"
125126
BlurRadius="40"
126127
ShadowColor="#5A000000"
127128
Offset="0 8">
128129
<Border Background="{DynamicResource BackgroundColor1}"
129130
BorderBrush="{DynamicResource ControlBorderColor}"
130131
BorderThickness="{DynamicResource ControlBorderThickness}"
131-
CornerRadius="{DynamicResource ControlCornerRadius}"
132+
CornerRadius="{TemplateBinding CornerRadius}"
132133
MinWidth="{TemplateBinding MinDialogWidth}"
133134
ClipToBounds="True">
134135
<Grid RowDefinitions="Auto,*,Auto">

0 commit comments

Comments
 (0)