Skip to content

Commit 7e730c6

Browse files
committed
Simplified ThemedIcon infra
1 parent 6316fe1 commit 7e730c6

File tree

3 files changed

+133
-212
lines changed

3 files changed

+133
-212
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Copyright (c) 2024 Files Community
2+
// Licensed under the MIT License. See the LICENSE.
3+
4+
using Microsoft.UI.Xaml;
5+
using Microsoft.UI.Xaml.Controls;
6+
using CommunityToolkit.WinUI.UI;
7+
using Microsoft.UI.Xaml.Controls.Primitives;
8+
9+
namespace Files.App.Controls
10+
{
11+
public partial class ThemedIcon
12+
{
13+
private bool _isOwnerToggled;
14+
private bool _isOwnerEnabled;
15+
16+
private Control? ownerControl = null;
17+
private ToggleButton? ownerToggleButton = null;
18+
19+
private void FindOwnerControlStates()
20+
{
21+
if (this.FindAscendant<ToggleButton>() is ToggleButton toggleButton)
22+
{
23+
ownerToggleButton = toggleButton;
24+
25+
// IsChecked/IsToggled change aware
26+
ownerToggleButton.Checked += OwnerControl_IsCheckedChanged;
27+
ownerToggleButton.Unchecked += OwnerControl_IsCheckedChanged;
28+
_isOwnerToggled = ownerToggleButton.IsChecked is true;
29+
}
30+
31+
if (this.FindAscendant<Control>() is Control control)
32+
{
33+
ownerControl = control;
34+
35+
// IsEnabled change aware
36+
ownerControl.IsEnabledChanged += OwnerControl_IsEnabledChanged;
37+
_isOwnerEnabled = ownerControl.IsEnabled;
38+
39+
UpdateVisualStates();
40+
}
41+
}
42+
43+
private void OwnerControl_IsCheckedChanged(object sender, RoutedEventArgs e)
44+
{
45+
if (ownerToggleButton is null)
46+
return;
47+
48+
_isOwnerToggled = ownerToggleButton.IsChecked is true;
49+
UpdateVisualStates();
50+
51+
}
52+
53+
private void OwnerControl_IsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e)
54+
{
55+
if (ownerControl is null)
56+
return;
57+
58+
_isOwnerEnabled = ownerControl.IsEnabled;
59+
UpdateVisualStates();
60+
}
61+
}
62+
}

src/Files.App.Controls/ThemedIcon/ThemedIcon.Properties.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -234,61 +234,61 @@ public object Layers
234234

235235
protected virtual void OnFilledIconPropertyChanged(string oldValue, string newValue)
236236
{
237-
UpdateFilledIconPath();
237+
OnFilledIconChanged();
238238
}
239239

240240
protected virtual void OnOutlineIconPropertyChanged(string oldValue, string newValue)
241241
{
242-
UpdateOutlineIconPath();
242+
OnOutlineIconChanged();
243243
}
244244

245245
// Color changed events
246246
protected virtual void OnColorPropertyChanged(Brush oldValue, Brush newValue)
247247
{
248-
UpdateIconTypeStates();
248+
OnIconTypeChanged();
249249
}
250250

251251
// Enum changed events
252252

253253
protected virtual void OnIconTypePropertyChanged(ThemedIconTypes oldValue, ThemedIconTypes newValue)
254254
{
255-
UpdateIconTypeStates();
255+
OnIconTypeChanged();
256256
}
257257

258258
protected virtual void OnIconColorTypePropertyChanged(ThemedIconColorType oldValue, ThemedIconColorType newValue)
259259
{
260-
UpdateIconColorTypeStates();
260+
OnIconColorTypeChanged();
261261
}
262262

263263
// Double changed events
264264

265265
protected virtual void OnIconSizePropertyChanged(double oldValue, double newValue)
266266
{
267-
IconSizePropertyChanged();
267+
UpdateVisualStates();
268268
}
269269

270270
// Boolean changed events
271271

272272
protected virtual void OnToggleBehaviorPropertyChanged(ToggleBehaviors oldValue, ToggleBehaviors newValue)
273273
{
274-
ToggleBehaviorChanged();
274+
UpdateVisualStates();
275275
}
276276

277277
protected virtual void OnIsFilledPropertyChanged(bool oldValue, bool newValue)
278278
{
279-
FilledChanged();
279+
UpdateVisualStates();
280280
}
281281

282282
protected virtual void OnIsHighContrastPropertyChanged(bool oldValue, bool newValue)
283283
{
284-
HighContrastChanged();
284+
UpdateVisualStates();
285285
}
286286

287287
// Object changed events
288288

289289
protected virtual void OnLayersPropertyChanged(object oldValue, object newValue)
290290
{
291-
UpdateLayeredIconContent();
291+
OnLayeredIconChanged();
292292
}
293293

294294
#endregion

0 commit comments

Comments
 (0)