Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice
  2. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  3. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

Feedback Deleted the post about introducing a dark title bar without warning, and did not tell where the prob

Discussion in '2023.1 Beta' started by Shompinice, Dec 13, 2022.

  1. Shompinice

    Shompinice

    Joined:
    May 7, 2022
    Posts:
    19
    The original article is quite long, so I've attached the complete code that introduces a dark title bar for legacy Win32 apps with a simple improvement. This is to simplify the developer's job.

    But the administrator directly deleted the post and told that it was off topic. If you want to delete the post, please lock the post first and allow me to copy the content of the post to the local first.

    You should then inform where feedback on this issue is required

    Instead of directly deleting the post rudely.
     
  2. runner78

    runner78

    Joined:
    Mar 14, 2015
    Posts:
    799
    I don't think the developers need a guide. Basically, it's as if a construction worker on a foreign construction site wants to explain to the workers there what they should do.
     
  3. Shompinice

    Shompinice

    Joined:
    May 7, 2022
    Posts:
    19
    If they've introduced dark title bars for Unity (Windows), then I'd agree with you. If they haven't done this, I can only assume they need a guide.
     
  4. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,701
    I've attached your post for reference purposes. In any case this hasn't been done because that doesn't affect the menu bar which remains white and defeats the whole purpose of it.

    I appreciate you taking the time to write up a detailed post about it but unfortunately it doesn't help.
     

    Attached Files:

  5. Shompinice

    Shompinice

    Joined:
    May 7, 2022
    Posts:
    19
    https://forum.unity.com/threads/dark-mode-menu-bar.746315/#post-8650989

    There has been this discussion since 2019.

    Regarding the menu bar, I hate to underestimate your skill level. If you are unwilling to migrate to Windows App SDK or use XAML island considering cross-platform compatibility, I assume that the menu bar control is based on WPF or WinForms, then you can get a black menu bar and menu with simple appearance customization.

    https://stackoverflow.com/questions...ackground-of-the-menuitem-on-mouseover-in-wpf
     
  6. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,414
    LooperVFX likes this.
  7. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,701
    Unity is based on the old Win32 API. In any case migrating to a different UI framework would be a lot of work so this hasn't been a priority.
     
  8. Shompinice

    Shompinice

    Joined:
    May 7, 2022
    Posts:
    19
    Because it is based on Win32 API, I pointed out in the post that you don't need to migrate to WindowsAppSDK or XAML island, you only need

    • This method is exactly for Win32 applications

    • This method is fully compatible with earlier versions of Windows (although you claim to have ended support for it. But even so, for Windows 8, or earlier versions of Windows, the API will not work without any compatibility issues, This change will be ignored.

    • This method also does not require complex customization of the window border, and only needs to add a few lines of code to run perfectly.

    • This approach also eliminates the need to migrate to the Windows App SDK or use a XAML island, which is currently the cheapest approach.

    • This is Microsoft's official method for Win32 applications to adapt to dark title bars.

    To enable the dark title bar, call a Desktop Windows Manager (DWM) function called DwmSetWindowAttribute on your top-level window, using the window attribute DWMWA_USE_IMMERSIVE_DARK_MODE. (DWM renders attributes for a window.)

    The following examples assume you have a window with with a standard title bar, like the one created by this code.

    Code (CSharp):
    1. BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
    2. {
    3.    hInst = hInstance; // Store instance handle in our global variable
    4.  
    5.    HWND hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,CW_USEDEFAULT, 0,
    6.      CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr);
    7.  
    8.    if (!hWnd)
    9.    {
    10.       return FALSE;
    11.    }
    12.  
    13.    ShowWindow(hWnd, nCmdShow);
    14.    UpdateWindow(hWnd);
    15.  
    16.    return TRUE;
    17. }
    First, you need to import the DWM API, like this.

    Code (CSharp):
    1. #include <dwmapi.h>
    After passing hWnd (the handle to the window you want to change) as your first parameter, you need to pass in DWMA_USE_IMMERSIVE_DARK_MODE as the dwAttribute parameter. This is a constant in the DWM API that lets the Windows frame be drawn in Dark mode colors when the Dark mode system setting is enabled. If you switch to Light mode, you will have to change DWMA_USE_IMMERSIVE_DARK_MODE from 20 to 0 for the title bar to be drawn in light mode colors.

    The pvAttribute parameter points to a value of type BOOL (which is why you made the BOOL value earlier). You need pvAttribute to be TRUE to honor Dark mode for the window. If pvAttribute is FALSE, the window will use Light Mode.

    Code (CSharp):
    1. #ifndef DWMWA_USE_IMMERSIVE_DARK_MODE
    2. #define DWMWA_USE_IMMERSIVE_DARK_MODE 20
    3. #endif
    4.  
    5.  
    6. BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
    7. {
    8.    hInst = hInstance; // Store instance handle in our global variable
    9.  
    10.    HWND hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
    11.       CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr);
    12.  
    13.    BOOL value = TRUE;
    14.    ::DwmSetWindowAttribute(hWnd, DWMWA_USE_IMMERSIVE_DARK_MODE, &value, sizeof(value));
    15.  
    16.    if (!hWnd)
    17.    {
    18.       return FALSE;
    19.    }
    20.  
    21.    ShowWindow(hWnd, nCmdShow);
    22.    UpdateWindow(hWnd);
    23.  
    24.    return TRUE;
    25. }
    Lastly, cbAttribute needs to have the size of the attribute being set in pvAttribute. To do easily do this, we pass in sizeof(value).

    Your code to draw a dark windows title bar should look like this.

    More Document:
    https://learn.microsoft.com/en-us/windows/apps/desktop/modernize/apply-windows-themes

     
    Last edited: Dec 14, 2022
  9. runner78

    runner78

    Joined:
    Mar 14, 2015
    Posts:
    799
    The light main menu bothers me more than the light title bar.
    Most other legacy UI programs that use their own color scheme completely reimplement the title bar.

    The main menu could implement unity with their own UIT, like the rest of the UI. The reason why Unity use the native UI menu for this is probably that it works differently in different OSs. But I saw that Jetbrain recently switched its main menu, at least in the Mac version, to its own main menu within the window.
     
  10. Shompinice

    Shompinice

    Joined:
    May 7, 2022
    Posts:
    19
  11. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,701
    As I mentioned, that doesn't make the menu dark:

    upload_2022-12-14_13-45-15.png

    You can try it out yourself with the attached script.

    Also accessibility. The OS native menu bar provides a lot of functionality that's not trivial to replicate.
     

    Attached Files:

  12. Shompinice

    Shompinice

    Joined:
    May 7, 2022
    Posts:
    19
    Amazing!
    I know, I mean exactly the system's native menu, I'm not sure which framework the menu uses, WPF? Or WinForms?
     
    Last edited: Dec 15, 2022
  13. runner78

    runner78

    Joined:
    Mar 14, 2015
    Posts:
    799
    Probably neither, but directly Win32 C++ API, or C# binding as in the dark mode file excample.
     
  14. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,701
  15. Shompinice

    Shompinice

    Joined:
    May 7, 2022
    Posts:
    19
    Ideally, their colors are specified by the user's msstyle file

    This makes it quite difficult to customize the color. Have you considered using a framework such as MFC or WinForms?
     
  16. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,701
    MFC doesn't help, as far as I know (although I'm far from an expert at MFC), it doesn't have any controls around menu color.

    WinForms/WPF are not viable for us. Not only that'd require rewriting all UI logic, they are both only supported on .NET Framework/.NET Core and Unity uses Mono, which doesn't support them. Also, having a low level UI framework in C# doesn't really work because it would not survive domain reloads.

    Ideally, Microsoft just added support for customizing menu color without having to rewrite how we create windows/pump messages. There's a lot of complicated code there and it'd take multiple man work years to switch to something else.
     
  17. Shompinice

    Shompinice

    Joined:
    May 7, 2022
    Posts:
    19
    https://learn.microsoft.com/en-us/windows/apps/desktop/modernize/using-the-xaml-hosting-api

    https://github.com/microsoft/Xaml-Islands-Samples/blob/master/Samples/Win32/ReadMe.md

    will you consider that using XAML island to build the menu bar? only menu bar
     
  18. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,701
    We might consider it. Given that we dropped support for Windows 7 and earlier Windows 10 versions opens up the possibility of doing it. That said, it isn't without downsides: XAML runtime is huge and using it just for the menu bar might be overkill.

    That said, as far as I know, this isn't on the roadmap. And I am not on the team working on this stuff. There have been talks internally about prioritizing it but so far it didn't make the list.
     
  19. runner78

    runner78

    Joined:
    Mar 14, 2015
    Posts:
    799
    I would say that in the end it's easier in windows to omit the native menu and create the menu using the editor UI, that would also fit better with the rest of the editor. As I said, Jetbrain has at least done that with PHPStorm, let the other editors like Rider do the same, but I only have PHPStorm on the Mac, so I noticed that the menu bar had changed. I suspect Jetbrain already had both variants, custom menubar in Window and native menubar on Mac. Their editor on Window is completely the same color scheme, title bar and menu bar.
     
  20. Shompinice

    Shompinice

    Joined:
    May 7, 2022
    Posts:
    19
    Yes they are huge。

    Could you please ask your colleagues to come and reply to this thread?
     
  21. Shompinice

    Shompinice

    Joined:
    May 7, 2022
    Posts:
    19
    This is a possible solution, though, I'd still like the Windows version to have native menus as well, based on XAML island, WinUI3 or the Windows App SDK.
     
  22. Onigiri

    Onigiri

    Joined:
    Aug 10, 2014
    Posts:
    490
    I would love to see title bar and menu bar to be merged in future (if possible) similar to how it's done in vs code.
     
  23. Shompinice

    Shompinice

    Joined:
    May 7, 2022
    Posts:
    19
    Is the team working on this in the forum, could you please @ him?
     
  24. Slashbot64

    Slashbot64

    Joined:
    Jun 15, 2020
    Posts:
    339
    On this subject of menu's.. I would love to see a redesign of it all not just to get rid of the massive white bar in darkmode and having matching dark/transparent blur glass like menu's...aesthetically better.. but really I just want rid of this white menu background... with some useful feature like making them tear-off like Maya has done for decades... being able to rip a menu off into a popup including submenu's is absolutely great when you are using plenty of things from within those menu's especially from third party assets or your own tools that are all dumped into them menus.

    Reducing that massive white strip at the top of Unity even by ~30px is better than nothing, its only software I use now that still has this issue... The darkmode.cs script should be built in and used for darkmode already, it makes a small improvement to the issue. Also it adheres to windows classic active/inactive colors better.
     
  25. Shompinice

    Shompinice

    Joined:
    May 7, 2022
    Posts:
    19
    https://github.com/microsoft/WindowsAppSDK/issues/2943

    Code (CSharp):
    1. [DllImport(UxTheme, EntryPoint = "#135")]
    2. public static extern PreferredAppMode SetPreferredAppMode(PreferredAppMode PreferredAppMode);
    This is the way to get win32 C++ dark menu background,it is used in File Explorer
     
  26. Kamyker

    Kamyker

    Joined:
    May 14, 2013
    Posts:
    1,092
    I have an idea. Couldn't whole menu bar and title bar be removed completely and simply replaced with Unity IMGUI/UI Toolkit? That way you don't have to care about making every change crossplatform. I guess that what Unreal does:


    Additionally, notice how title bar is removed completely for them to make editor larger. Project name is in top right corner instead:
     
    DoctorShinobi likes this.
  27. runner78

    runner78

    Joined:
    Mar 14, 2015
    Posts:
    799
    I already suggested that above.

    Here's Rider and Photoshop, they do it that way too. Menu-photoshop.png Menu-rider.png
     
    Kamyker and SooNice like this.
  28. Kamyker

    Kamyker

    Joined:
    May 14, 2013
    Posts:
    1,092
    Made a shortcut to hide it with calls to windows api.
    If someone could make menu bar UI with dropdowns (preferably in UI Toolkit) I can plug the rest of the code and simulate clicks with Window's SendMessage. It's a bit funny that this whole issue can be resolved in 3 days.
     
  29. sacb0y

    sacb0y

    Joined:
    May 9, 2016
    Posts:
    932
    I would assume it's mouse input is archaic too, it's a shame how many programs have aweful track pad support due to being based on such an old framework.

    You don't know what you're missing until you try Blender's latest version that finally makes the track pad support modern.
     
  30. Ox7c13

    Ox7c13

    Joined:
    May 26, 2019
    Posts:
    19