On Sat, 7 Jun 2025 01:47:15 GMT, Cormac Redmond <d...@openjdk.org> wrote:
> Just something to consider regarding this "dark" mode reliance on a Scene's > fill property. > > As far as I know, a Scene's fill property cannot be set via CSS. > > I have a light and dark theme (two css files), and the user can pick "light" > or "dark", for example. A few well-known apps have quite a few themes to > choose from, like AtlantaFX-based apps. Other apps allow users to supply > custom CSS files, such as JabRef. > > In order for the window icons to appear correctly, one must programmatically > call Scene.setFill(), setting it to something appropriate anytime a user > changes theme, at runtime -- it seems to defeat the purpose of stylesheets a > little to need to "know" how to set a scene's fill. In the future, separate stylesheets for light and dark modes might not be required. PR #1655 proposes media feature queries that includes a scene-specific property `Scene.Preferences.colorScheme`, which can be queried in stylesheets. So when we get that feature, we could have the default header buttons adapt to the scene's color scheme instead of its fill color. And instead of swapping out stylesheets to toggle dark mode, you would only toggle the scene's color scheme property. > Would it be more flexible to check the background colour of the HeaderBar > instead, and base the isDarkBackground() check off that? Runtime stylesheet > changes would also be picked up by HeaderButtonOverlay which would > automatically adjust the window icons, and the developer doesn't need to call > any code. Let the developer decide the background colour of the HeaderBar > (which can be via CSS). > > Would also cover the case where users might want a dark menu/header bar, but > a otherwise "white" scene, or vica-versa. This would be the most flexible option, but it's also more difficult to implement. Consider the case where you have two header bars side by side (this is a supported configuration). Do we take the average background color of both header bars? Do we pick one of them? (And if so, how? Do we inspect the scene graph under the header buttons?) Can this behavior be overridden if it doesn't produce a good result in a specific use case? There are many questions to solve... ------------- PR Comment: https://git.openjdk.org/jfx/pull/1605#issuecomment-2951538997