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

Porting Fluent Design Styles and Controls #3950

Closed
hez2010 opened this issue May 16, 2020 · 37 comments
Closed

Porting Fluent Design Styles and Controls #3950

hez2010 opened this issue May 16, 2020 · 37 comments
Projects

Comments

@hez2010
Copy link
Contributor

hez2010 commented May 16, 2020

WinUI 3.0 is a major update of WinUI 2.0 that will greatly expand the scope of WinUI to include the full Windows 10 native UI platform, which will now be fully decoupled from the UWP SDK.
Therefore, it will allow WPF, WinForms, MFC, traditional Win32 and many other GUI stacks to consume WinUI 3.0 libraries.

I hope that Avalonia can also add support for consuming WinUI 3.0.
I hope that Avalonia can port WinUI 3.0 Fluent Design Styles and Controls.

@JamRemco
Copy link
Contributor

WinUi is not crossplatform en avalonia is crossplatform so i dont think that wil work

What is what you want to use from WinUI?

Regards,

Remco

@Gillibald
Copy link
Contributor

We already have the ItemsRepeater ported to Avalonia. This shows porting controls from Winui is possible. Contributions are welcome.

@JamRemco
Copy link
Contributor

Porting yes, copying the look ,feel and styles also possible.
The OP asked for consuming WinUI, and that is an other story.

Actually, i am making styles for avalonia controls right now. Wich includes WinUi styles for example...
A Tooglebutton with WinUi toggleswitch style
image

Remco

@kekekeks
Copy link
Member

Consuming WinUI would be possible via native window embedding. There is no much point in doing that though, since it will only work on Windows.

@danwalmsley
Copy link
Member

Porting yes, copying the look ,feel and styles also possible.
The OP asked for consuming WinUI, and that is an other story.

Actually, i am making styles for avalonia controls right now. Wich includes WinUi styles for example...
A Tooglebutton with WinUi toggleswitch style
image

Remco

@JamRemco an effort to update the official theme / templates to match WinUI is about to start, maybe we can collaborate.

@JamRemco
Copy link
Contributor

JamRemco commented May 19, 2020

@danwalmsley Sounds like a plan

The template have a lot of hardcoded properties like fonts and such
This need to be changed to make it more templateable.
We need more template naming/parts such as PART_header for example

Regards,

Remco

@hez2010 hez2010 changed the title Support for consuming WinUI 3.0 Porting WinUI 3.0 Fluent Design Styles and Controls May 19, 2020
@hez2010
Copy link
Contributor Author

hez2010 commented May 19, 2020

WinUi is not crossplatform en avalonia is crossplatform so i dont think that wil work

I've updated the issue.

@danwalmsley
Copy link
Member

@danwalmsley Sounds like a plan

The template have a lot of hardcoded properties like fonts and such
This need to be changed to make it more templateable.
We need more template naming/parts such as PART_header for example

Regards,

Remco

I think we can get hold of the actual templates for UWP / WinUI using visual studio and at least the UWP ones are public, not sure about winui but im guessing they will be.

It seems Avalonia will need theme support before we can start however, will discuss with @kekekeks what needs doing first.

@amwx
Copy link
Contributor

amwx commented May 20, 2020

Just to add here, you can get the full UWP base templates & themes from the themeresources.xaml & generic.xaml files from the Windows SDK:
C:\Program Files (x86)\Windows Kits\10\DesignTime\CommonConfiguration\Neutral\UAP\ {version number, e.g. 10.0.18362.0} \Generic
They're like 100,000 line xaml files since MS designates a brush/color for EVERYTHING, but all styles & colors are there, most theme brushes are redundant StaticResources to a base set of colors that change by Light/Dark/High Contrast theme.

And if you really want to get fancy and get the user's current Accent Color & color setting preferences, you can p/invoke uxtheme.dll to get it (note: not my own discovery, though I can't remember the source where I got this from). These are undocumented APIs, but google is helpful. Also, not sure how far back in Win10 versions these go
uxtheme functions for accent color (these I believe trace back to Win 8)

[DllImport("uxtheme.dll", EntryPoint = "#95")]
public static extern uint GetImmersiveColorFromColorSetEx(uint dwImmersiveColorSet, uint dwImmersiveColorType, bool bIgnoreHighContrast, uint dwHighContrastCacheMode);
[DllImport("uxtheme.dll", EntryPoint = "#96")]
public static extern uint GetImmersiveColorTypeFromName(IntPtr pName);
[DllImport("uxtheme.dll", EntryPoint = "#98")]
public static extern int GetImmersiveUserColorSetPreference(bool bForceCheckRegistry, bool bSkipCheckOnFail);

Check if dark mode is requested (these I believe are recent Win10 only)

[DllImport("uxtheme.dll", EntryPoint = "#132")] //Win 10 1809+ ?
public static extern bool fnShouldAppsUseDarkMode();
[DllImport("uxtheme.dll", EntryPoint = "#138")] //Win 10 1903+ ?
public static extern bool fnShouldSystemUseDarkMode();

Helper to get ImmersiveColor

public static Avalonia.Media.Color GetThemeColorRef(string h)
 {
        var colorSetEx = GetImmersiveColorFromColorSetEx(
            (uint)GetImmersiveUserColorSetPreference(false, false),
            GetImmersiveColorTypeFromName(Marshal.StringToHGlobalUni(h)),
            false, 0);

        var a = 0xFFFFFF & colorSetEx >> 24;
        var r = (0xFFFFFF & colorSetEx);
        var g = (0xFFFFFF & colorSetEx) >> 8;
        var b = (0xFFFFFF & colorSetEx) >> 16;

        var colour = Avalonia.Media.Color.FromArgb((byte)a, (byte)r, (byte)g, (byte)b);

        return colour;
}

Get Accent Color(s)

var themeAccent = GetThemeColorRef("ImmersiveSystemAccent");
var themeAccentLight1 = GetThemeColorRef("ImmersiveSystemAccentLight1");
var themeAccentLight2 = GetThemeColorRef("ImmersiveSystemAccentLight2");
var themeAccentLight3 = GetThemeColorRef("ImmersiveSystemAccentLight3");
var themeAccentDark1 = GetThemeColorRef("ImmersiveSystemAccentDark1");
var themeAccentDark2 = GetThemeColorRef("ImmersiveSystemAccentDark2");
var themeAccentDark3 = GetThemeColorRef("ImmersiveSystemAccentDark3");

@robloo
Copy link
Contributor

robloo commented May 21, 2020

@danwalmsley @amwx @JamRemco
Like the idea of using the latest control styles/templates from WinUI/UWP in Avalonia. That would be really cool. It might also be a good idea to take the ideas from Uno Platform and provide Native styles for each platform -- native control designs for MacOS and Linux GTK/QT. I realize that's a big task but would allow for 'native' look and feel on all platforms.

That said, do NOT get the latest styles from the generic.xaml that ships with Windows (the huge file). The WinUI library currently has the latest XAML styles including rounded corners for nearly all controls. The current style inheritance for UWP apps is:

  1. Windows default styles that ship with the framework -- this is the huge monolithic generic.xaml file
  2. The WinUI 'fluent' styles that override the default styles for all WinUI library apps. This is the latest design and will become the base for Win UI 3.0 (when 1 and 2 get merged together).

You'll want to get the XAML from each control folder (they are already separated out instead of one big XAML file) here: https://github.com/microsoft/microsoft-ui-xaml/tree/master/dev

You'll definitely want to finish #2769 before doing this though.

@danwalmsley
Copy link
Member

@amrx what is immersive color?

@amwx
Copy link
Contributor

amwx commented May 21, 2020

@robloo Good catch on that (re WinUI templates). I forgot about that.
@danwalmsley Immersive color is just what MS called the API (at least that's my guess), but it's just the theme colors as laid out in uxtheme, and set from the user color preferences

image

@danwalmsley
Copy link
Member

@robloo native themes are a great idea, however something that should be provided by some kind of Avalonia Community Toolkit and built be community. If someone makes good in roads in this area we can probably adopt a community toolkit repo into AvaloniaUI organisation, provided there are people to maintain it.

@JamRemco
Copy link
Contributor

Agree with the above, but the thing is : what is native look. there are 10 diverent *Nix looks (if not more) and win 10 cant make up its mind how to dress ;).
Eg
image
Or
image
or
image

Righ now there are some "isues" with the templates. if that is fixed. we can make first a "Avalonia Style" out of the box which not mimics anything perse.
And writing styles an classes on top of that.

Some of the "Modern Desig" is old wine in new bottles.

Regard,

Remco

@robloo
Copy link
Contributor

robloo commented May 22, 2020

@JamRemco

but the thing is : what is native look. there are 10 diverent *Nix looks (if not more) and win 10 cant make up its mind how to dress ;).

There are many different styles in windows because there are a lot of different pieces of technology involved. However, there is no confusion on what the latest/current UI style is. Therefore, I have to disagree with you here.

Per the title of this issue, the latest styles are "WinUI 3.0 Fluent Design" which is only available right now in the WinUI library and will be the default styles shipping with WinUI 3.0 which is in preview now.

@JamRemco
Copy link
Contributor

@robloo
So. WinUI = Native Windows.
Thats what i asked right ;).
admitted the discusion did got a bit sidetracked.

regards,

Recmo

@seanocali
Copy link

seanocali commented May 23, 2020

@danwalmsley
Copy link
Member

@robloo which is only available right now in the WinUI library and will be the default styles shipping with WinUI 3.0 which is in preview now.

There is a web implementation also and a mac implementation too.

@JamRemco thats the great thing fluent ui isn't a framework or a native style, its just a set of design styles and concepts that anyone is allowed to implement.

@JamRemco
Copy link
Contributor

@danwalmsley Yeay i know and i agree with most of it.

I saw you are bussy with the "acrilic" stuff. from what i saw that looked great.
I am a bit more of a "old scool" developer but i getting better every day, or at least i pretend to.
I have make ui frameworks in GDI+, its kinda the same but also a lot different.

Looking forward to contribute and make this the best crossplatform UI

Fingers crossed,

Remco

@danwalmsley
Copy link
Member

Acrylic stuff is just experimenting around, to see how far we can get. Seem that we need to implement a compositor to make it work correctly. So it won't be here anytime soon. Except maybe background acrylic.

The rest of the controls and styling can be done immediately though.

@danwalmsley danwalmsley added this to To do in 0.10.0 May 25, 2020
@danwalmsley
Copy link
Member

@JamRemco @robloo @seanocali @amwx @hez2010

Porting has begun, if any of you are able to lend an hand, please get in touch with me ASAP on gitter.

@JamRemco you mentioned earlier about styles for ToggleSwitch, realised Avalonia doesnt have that control, a PR to implement that should be reasonable easy... let me know what you have done.

@JamRemco
Copy link
Contributor

@danwalmsley

What i did is made a style for Togglebutton (as you know the backing control for checkbox and radiobutton)
In WinUi/Uwp it is an other control. At the time i feld it is not worth it to make a control for something wich is in essence the same as a togglebutton.
The colors are "hardcoded" because coloranimation doesnt work with resources for some reason. however it can be done (Kinda) with a workaround eg:
From white to blue having two shapes - 1 white and one blue - and animate the Opacity of one shape.
However this is not inplemented yet, but easely done

Although i am realy bussy this weekend, i am stil like to help somehow
I'll check later whatsUpp @ Glitter

Remco

@danwalmsley
Copy link
Member

@danwalmsley

What i did is made a style for Togglebutton (as you know the backing control for checkbox and radiobutton)
In WinUi/Uwp it is an other control. At the time i feld it is not worth it to make a control for something wich is in essence the same as a togglebutton.
The colors are "hardcoded" because coloranimation doesnt work with resources for some reason. however it can be done (Kinda) with a workaround eg:
From white to blue having two shapes - 1 white and one blue - and animate the Opacity of one shape.
However this is not inplemented yet, but easely done

Although i am realy bussy this weekend, i am stil like to help somehow
I'll check later whatsUpp @ Glitter

Remco

@jmacato might be able to solve the color animation issues...

please open a PR when your free again and we can take a look even if its just a draft.

@maxkatz6
Copy link
Member

maxkatz6 commented Jun 2, 2020

@danwalmsley
I have looked at some controls in Avalonia, which isn't yet updated with Fluent. As reference I used UWP, WinUI and (WCT) Windows Community Toolkit (I will name all of them as "UWP controls" below).

I hope I didn't forgot about anything. Controls like Image or TextBlock doesn't have special styles, so we don't need to do anything here. However there are some missed features out of current scope.

@robloo
Copy link
Contributor

robloo commented Jun 16, 2020

The style updates are looking really good based on the screenshots I've seen 👍

@maxkatz6
Also, I recently made a comparison of WPF/UWP that includes a section on controls. It might be useful to see which Controls are missing from Avalonia. (I notice this issue is comparing controls as well as styling)

https://github.com/robloo/PublicDocs/blob/master/UWPvsWPF.md#Controls

@danwalmsley danwalmsley moved this from To do to In Progress in 0.10.0 Jun 18, 2020
@danwalmsley danwalmsley moved this from In Progress to Done in 0.10.0 Jun 30, 2020
@greatawesome
Copy link

I wonder if Uno would make it possible to consume WinUI in Avalonia, now that they have a Linux/Skia backend?

@maxkatz6
Copy link
Member

@greatawesome probably some level of interop could be possible, but it's not on the roadmap.

@maxkatz6
Copy link
Member

With 0.10.0 released I believe this issue can be closed. We now have "Fluent" theme which was ported from WinUI.
If someone needs embeding of native control, it should be possible to do with WinForms/WPF interop.

@robloo
Copy link
Contributor

robloo commented Jul 17, 2021

@maxkatz6 Should this actually be re-opened with the new Fluent Version 2.0 Style? Or should a new issue be created?

I expect WinUI3 is going to actually debut with version 2 of Fluent that is for Windows 11.

@jmacato
Copy link
Member

jmacato commented Jul 17, 2021

@robloo have they finalized the design yet? i cant seem to find any resources for it yet

@amwx
Copy link
Contributor

amwx commented Jul 17, 2021

I think most of the design has been finalized, but they're still tinkering with it. But the resources are in the WinUI repo now (basically any file not marked with "_v1.xaml" is the new WinUI styles, v1 is the old styles), and I've been bringing them into my FluentAvalonia repo (most are already there, but not all). It's probably worth waiting until ~Win11/actual release and they stop making little changes.
Though really before and if Avalonia brings them in, #5768 needs to be addressed because there's some brushes that use a -1 ScaleY transform, so I'm hoping this comes with the new composition engine.
This also might reignite the #5593 discussion, as it may be best to make this an "addon" to reduce confusion between fluent theme version, and keep the core size down.

@robloo
Copy link
Contributor

robloo commented Jul 17, 2021

Yea, as mentioned this has been released in WinUI 2.6 as Fluent version 2.0. They keep adjusting things and will do so for Windows 11. However, it is ready to bring over into other frameworks like Avalonia now.

https://docs.microsoft.com/en-us/windows/apps/winui/winui2/winui-2.6#visual-style-updates

This also might reignite the #5593 discussion, as it may be best to make this an "addon" to reduce confusion between fluent theme version

I dont think Avalonia should have Fluent theme versions really. Fluent in Avalonia should always try to be latest. Version 2 supercedes version 1 and should probably be entirely replaced. Otherwise maintaining all versions going forward is going to get real difficult even if its split into separate packages.

@jmacato
Copy link
Member

jmacato commented Jul 17, 2021

Fluent in Avalonia should always try to be latest.

I agree. theme versioning would make things needlessly complicated maintenance-wise.

@maxkatz6
Copy link
Member

Still, we need keep in mind, that developers already build their applications and custom styles on top of Fluent v1. We either need to do theme versioning. Or move Fluent theme to separated NuGet package (another breaking change, but it still makes sense to do anyway), and inform developers, that they can update Avalonia version, but keep Fluent version older in order to avoid breaking their theming.

Somehow, I would prefer second option, even though it makes more headache for everybody.

@maxkatz6 maxkatz6 reopened this Jul 18, 2021
@maxkatz6
Copy link
Member

Actually, it's better to create new issue. This one is already over discussed with unrelated to Fluent v2 topics.

@maxkatz6 maxkatz6 changed the title Porting WinUI 3.0 Fluent Design Styles and Controls Porting Fluent Design Styles and Controls Jul 18, 2021
@maxkatz6
Copy link
Member

#6269

@cesarchefinho
Copy link

have you see

https://amwx.github.io/FluentAvaloniaDocs/ ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
0.10.0
  
Done
Development

No branches or pull requests