mono / xwt

A cross-platform UI toolkit for creating desktop applications with .NET and Mono
MIT License
1.37k stars 241 forks source link

Make ThemedImage style selection less unpredictable #1021

Closed sevoku closed 4 years ago

sevoku commented 4 years ago

GetImage is optimized for performace and therefore just loops over the images and selects the first best matching one based on given styles. The result is not predictable if the image list is not sorted and several alternatives match different global and explicit styles. Since we want to prioritize explicit styles first, we need to make sure that we don't select an image with a given global style but without an explicit match first. The simplest approach without slowing down rendering by a sophisticated lookup is to sort images matching global styles last, so that GetImage would always select an alternative with an explicit rather than a global style.

High contrast Mode Example from MonoDevelop

We use two problematic/conflicting styles:

The sel mode is always explicitely requested if the control state changes, while the contrast style is global.

Given we have these two icons for the different modes:

It is not well defined which one would be rendered, if both styles are set. Currently this depends only on the order in which the icon alternatives have been loaded from disk. With this change we'll always select the explicit and not the global style, which is sel in this case.

without the fix:

grafik

with the fix:

grafik
slluis commented 4 years ago

I'd like to suggest a slightly different approach to avoid the event subscription. Have a global counter that is increased when there is a change in the global styles. Store a copy of the current value of the counter in the themed image when it is created. Before rendering an image, check if the counter changed since last draw, and in that case resort the images before rendering.