Skip to content
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

Code Quality: Added ThemedIcon #15560

Closed
wants to merge 15 commits into from

Conversation

mdtauk
Copy link
Contributor

@mdtauk mdtauk commented Jun 6, 2024

Resolved / Related Issues
This is an ongoing project to try to work on a new ThemedIcon control

To prevent extra work, all changes to the Files codebase must link to an approved issue marked as Ready to build. Please insert the issue number following the hashtag with the issue number that this Pull Request resolves.

  • Closes #

Steps used to test these changes

Stability is a top priority for Files and all changes are required to go through testing before being merged into the repo. Please include a list of steps that you used to test this PR.

  1. Opened Files ...
  2. ...

@0x5bfa 0x5bfa self-assigned this Jun 6, 2024
@files-community-bot
Copy link
Contributor

✅ Successfully formatted XAML files.

@mdtauk mdtauk changed the title Feature: mdta - WIP Themed Icon Code Quality: Added ThemedIcon Jun 21, 2024
src/Files.App/App.xaml Outdated Show resolved Hide resolved
@yaira2 yaira2 force-pushed the mdta-ThemedIcon branch 2 times, most recently from fe394de to 9ab4575 Compare July 2, 2024 16:26
- ThemedIcon implementations
- Test UI for ThemedIcon
- MenuFlyoutItemEx
- All icons for ThemedIcon
0x5bfa and others added 9 commits July 3, 2024 05:42
Made "Accent" a specific IconColorType = this would be used for the Copying, Moving, Extracting actions in the Status Center - where we need outlined as well as filled icons, only displaying in the Accent Colour
Added a brush and visual state for Disabled while Toggled, using TextOnAccentDisabled brush
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@0x5bfa we're doing the final review on this PR. Can you please remove the enum to reduce confusion?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the future reference, we’ll make a test project and it’ll need this but we don’t want to make things complicated thus we might be going to create a source generator for it.


var windowId = MainWindow.Instance.AppWindow.Id;
ThemeSettings = ThemeSettings.CreateForWindowId(windowId);
ThemeSettings.Changed += (s, e) => { IsHighContrastChanged?.Invoke(this, s.HighContrast); };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be split onto separate lines? I'm fine with either way but I wanted to point this out just in case.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m fine either but I prefer this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand this was just added for testing, let's keep a copy but save it for the PR where we actually remove OpacityIcon and replace all instances with ThemedIcon.

Copy link
Member

@0x5bfa 0x5bfa Jul 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.
For the future reference, this control can be also used for bitmap images, and we’ll have to create an extension control also for AppBarButton (AppBarButtonEx).

@yaira2 yaira2 added the changes requested Changes are needed for this pull request label Jul 3, 2024
@@ -0,0 +1,4568 @@
<!-- Copyright (c) 2024 Files Community. Licensed under the MIT License. See the LICENSE. -->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From a maintenance perspective, a XAML file with 4500 lines is not ideal 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Splitting it can be done, but adding new icons would involve finding the right place to add it to.

We could use a merged dictionary for this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer a single file, but I'll follow your lead on this if you suggest a different approach.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer a single file, but I'll follow your lead on this if you suggest a different approach.

I am happy to split it up, if there is a need for smaller Xaml files - but I would like you to decide on how you would like to group them. My Xaml regions are just how I see them being grouped, but as I wont always be the one adding new icons in the future, the grouping should reflect your sorting @yaira2

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to split out the icons into a separate file and have the base template be its own file? That ways it's easier to spot where to find icons or the actual ThemeIcon control's code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can split the icons into separate Xaml, the base default control template is already separate.

Comment on lines +221 to +222
<Setter Target="PART_OutlinePath.Fill" Value="{ThemeResource ThemedIconHighContrastBrush}" />
<Setter Target="PART_FilledPath.Fill" Value="{ThemeResource ThemedIconHighContrastBrush}" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we doing this manually instead of all brushes just pointing to these two values in high contrast? That would allow us to not having to listening to the high contrast event.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have the option to always use High Contrast icons, for those users who don't like the use of the accent colour.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mdtauk Is this a use case we plan to support?
@marcelwgn does this affect performance or is there no harm in keeping it just in case?

Copy link
Contributor Author

@mdtauk mdtauk Jul 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mdtauk Is this a use case we plan to support?

I don't know, you will have to decide on that

@marcelwgn does this affect performance or is there no harm in keeping it just in case?

It is just a property UseContrast which works alongside the internal _isHighContrast bool which is set by the Theme Changed service

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those brushes are set when user set Windows high contrast on AND/OR when user make a preference on using high contrast icons (if we decide to support this). If we drop the second one’s support, we should define high contrast brush only in the HighContrast XAML key.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could differentiate between UseContrast and _isHighContrast so the HighContrast resources kick in, and the specific High Contrast brush we use is reserved only for the optional use.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My 0.02€: If we currently don't support the option to toggle high contrast on for Files regardless of the system settings, I would not go the length to support it now. I agree with @mdtauk that it's not much more to support, however event listeners aren't free either. And the ThemeIcon control might get rendered dozens of times so small costs might add up.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They way I see it, HighContrast based on the system rather than the control's "UseContrast" property. Still requires an event listener, so we can replace the Layered visual state with the outline.

The UseContrast setting basically also replaces the layered icon state with the Outlined icon - however we also have a separate brush resource, which makes the icons use the same brush as the text around it, ensuring it stands out clearer. (our base brush is closer to the TextSecondary brush so they don't feel too intrusive.)

Even if we were to remove the alternate brush choice, and the UseContrast property - and decide never to support it, or custom icon colours for the custom themes in Files - the HighContrast system event is still essential.

Copy link
Contributor Author

@mdtauk mdtauk Jul 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am happy to remove the UseContrast additional setting, if no purpose is seen in it.

I know some people use a grey Accent colour or may want to change the icon colour via a custom theme - but if there is no plan to implement that, then so be it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Olay, let's remove and if the need arises, we can refer to this PR and add it back.

@0x5bfa

This comment was marked as outdated.

@yaira2 yaira2 closed this Jul 10, 2024
@0x5bfa 0x5bfa deleted the mdta-ThemedIcon branch July 10, 2024 01:24
@0x5bfa
Copy link
Member

0x5bfa commented Jul 10, 2024

@marcelwgn as you suggested we decided to create a separate class library for controls (Files.App.Controls) and an unit test project (Files.App.UITests) for that project. To ease PR’s review work, we’ve splitter up work into three: adding template project for both, adding ThemedIcon implementation and its test and lastly replacing the old icons with this icon control. Thank you for reviewing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changes requested Changes are needed for this pull request needs - code review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants