-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Code Quality: ThemedIcon, Changed IsToggle to ToggleBehavior #15948
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
yaira2
merged 7 commits into
files-community:main
from
mdtauk:mdta-ThemedIcon-ToggleFix
Oct 28, 2024
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2224cb1
Init
mdtauk 64c8c30
Updated code as requested
mdtauk 7aca790
Merge remote-tracking branch 'upstream/main' into mdta-ThemedIcon-Tog…
0x5bfa 5af1e90
Update ThemedIcon.Properties.cs
0x5bfa 1c65f91
Format C# & use SG
0x5bfa 2dfc2a2
Update ThemedIconLayer.Properties.cs
0x5bfa 384a14c
Update ThemedIcon.Properties.cs
0x5bfa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
src/Files.App.Controls/ThemedIcon/Data/ThemedIconColorType.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright (c) 2024 Files Community | ||
// Licensed under the MIT License. See the LICENSE. | ||
|
||
namespace Files.App.Controls | ||
{ | ||
/// <summary> | ||
/// Defines the IconColorTypes for <see cref="ThemedIcon"/> which sets the visual state | ||
/// to use the correct brush values which match system signal colors. | ||
/// </summary> | ||
public enum ThemedIconColorType | ||
{ | ||
None, | ||
|
||
/// <summary> | ||
/// Icon color type of <see cref="ThemedIcon"/> is Normal. Default Value. | ||
/// </summary> | ||
Normal, | ||
|
||
/// <summary> | ||
/// Icon color type of <see cref="ThemedIcon"/> is Critical. | ||
/// </summary> | ||
Critical, | ||
|
||
/// <summary> | ||
/// Icon color type of <see cref="ThemedIcon"/> is Caution. | ||
/// </summary> | ||
Caution, | ||
|
||
/// <summary> | ||
/// Icon color type of <see cref="ThemedIcon"/> is Success. | ||
/// </summary> | ||
Success, | ||
|
||
/// <summary> | ||
/// Icon color type of <see cref="ThemedIcon"/> is Neutral. | ||
/// </summary> | ||
Neutral, | ||
|
||
/// <summary> | ||
/// Icon color type of <see cref="ThemedIcon"/> is Accent. | ||
/// </summary> | ||
Accent, | ||
|
||
/// <summary> | ||
/// Icon color type of <see cref="ThemedIcon"/> is Custom. Used in combination | ||
/// with the IconColor and Foreground brushes. | ||
/// </summary> | ||
Custom | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/Files.App.Controls/ThemedIcon/Data/ThemedIconLayerType.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright (c) 2024 Files Community | ||
// Licensed under the MIT License. See the LICENSE. | ||
|
||
namespace Files.App.Controls | ||
{ | ||
/// <summary> | ||
/// Defines LayerTypes for <see cref="ThemedIcon"/>. | ||
/// </summary> | ||
public enum ThemedIconLayerType | ||
{ | ||
/// <summary> | ||
/// The LayerType uses the Base color. Default state. | ||
/// </summary> | ||
Base, | ||
/// <summary> | ||
/// The LayerType uses the Alt color. | ||
/// </summary> | ||
Alt, | ||
/// <summary> | ||
/// The LayerType uses an Accented color. | ||
/// </summary> | ||
Accent, | ||
/// <summary> | ||
/// The LayerType uses a contrasting color for the Accented color. | ||
/// </summary> | ||
AccentContrast, | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/Files.App.Controls/ThemedIcon/Data/ThemedIconLayers.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Copyright (c) 2024 Files Community | ||
// Licensed under the MIT License. See the LICENSE. | ||
|
||
namespace Files.App.Controls | ||
{ | ||
/// <summary> | ||
/// A collection of Layers for the ThemedIcon's Layered IconType | ||
/// </summary> | ||
public sealed class ThemedIconLayers : List<ThemedIconLayer> | ||
{ | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/Files.App.Controls/ThemedIcon/Data/ThemedIconToggleBehaviors.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright (c) 2024 Files Community | ||
// Licensed under the MIT License. See the LICENSE. | ||
|
||
namespace Files.App.Controls | ||
{ | ||
/// <summary> | ||
/// Defines IconTypes for <see cref="ThemedIcon"/>. | ||
/// </summary> | ||
public enum ToggleBehaviors | ||
{ | ||
/// <summary> | ||
/// Auto enables the ThemedIcon to listen to owner control states. | ||
/// </summary> | ||
Auto, | ||
|
||
/// <summary> | ||
/// On will always use the ThemedIcon's Toggle state | ||
/// </summary> | ||
On, | ||
|
||
/// <summary> | ||
/// Off will not use the ThemedIcon's Toggle state | ||
/// </summary> | ||
Off, | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright (c) 2024 Files Community | ||
// Licensed under the MIT License. See the LICENSE. | ||
|
||
namespace Files.App.Controls | ||
{ | ||
/// <summary> | ||
/// Defines IconTypes for <see cref="ThemedIcon"/>. | ||
/// </summary> | ||
public enum ThemedIconTypes | ||
{ | ||
/// <summary> | ||
/// Icon type of <see cref="ThemedIcon"/> is Outline. | ||
/// </summary> | ||
Outline, | ||
|
||
/// <summary> | ||
/// Icon type of <see cref="ThemedIcon"/> is Layered. | ||
/// </summary> | ||
Layered, | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright (c) 2024 Files Community | ||
mdtauk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Licensed under the MIT License. See the LICENSE. | ||
|
||
using CommunityToolkit.WinUI.UI; | ||
using Microsoft.UI.Xaml; | ||
using Microsoft.UI.Xaml.Controls; | ||
using Microsoft.UI.Xaml.Controls.Primitives; | ||
|
||
namespace Files.App.Controls | ||
{ | ||
public partial class ThemedIcon | ||
{ | ||
private bool _isOwnerToggled; | ||
private bool _isOwnerEnabled; | ||
|
||
private Control? ownerControl = null; | ||
private ToggleButton? ownerToggleButton = null; | ||
|
||
private void FindOwnerControlStates() | ||
{ | ||
if (this.FindAscendant<ToggleButton>() is ToggleButton toggleButton) | ||
{ | ||
ownerToggleButton = toggleButton; | ||
|
||
// IsChecked/IsToggled change aware | ||
ownerToggleButton.Checked += OwnerControl_IsCheckedChanged; | ||
ownerToggleButton.Unchecked += OwnerControl_IsCheckedChanged; | ||
_isOwnerToggled = ownerToggleButton.IsChecked is true; | ||
} | ||
|
||
if (this.FindAscendant<Control>() is Control control) | ||
{ | ||
ownerControl = control; | ||
|
||
// IsEnabled change aware | ||
ownerControl.IsEnabledChanged += OwnerControl_IsEnabledChanged; | ||
_isOwnerEnabled = ownerControl.IsEnabled; | ||
|
||
UpdateVisualStates(); | ||
} | ||
} | ||
|
||
private void OwnerControl_IsCheckedChanged(object sender, RoutedEventArgs e) | ||
{ | ||
if (ownerToggleButton is null) | ||
return; | ||
|
||
_isOwnerToggled = ownerToggleButton.IsChecked is true; | ||
UpdateVisualStates(); | ||
|
||
} | ||
|
||
private void OwnerControl_IsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e) | ||
{ | ||
if (ownerControl is null) | ||
return; | ||
|
||
_isOwnerEnabled = ownerControl.IsEnabled; | ||
UpdateVisualStates(); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.