Avalonia icon indicating copy to clipboard operation
Avalonia copied to clipboard

Make asset loader understand files tailored per scale, theme and possibly other

Open maxkatz6 opened this issue 1 year ago • 5 comments

Describe the solution you'd like

Usage: Create files:

\Assets\Images\logo.scale-100.png
\Assets\Images\logo.scale-200.png
\Assets\Images\logo.scale-400.png

Reference file in the XAML (or with AssetLoader):

<Image Source="\Assets\Images\logo.png"/>

Asset loader should automatically detect current scaling and choose the correct file.

At minimum should be supported:

  • scale
  • theme (dark, light, custom)
  • layout direction (ltr, rtl) Optional:
  • language, should it rely on .NET CurrentCulture?
  • device type

Describe alternatives you've considered

OnPlatform markup extension will be part of 11.0. Similarly, developers can define their own custom markup extensions. Media Queries also are planned to solve similar problem. Gladly, asset loader extension, won't conflict with these other features, and can be used together.

maxkatz6 avatar Nov 03 '22 19:11 maxkatz6

See https://github.com/AvaloniaUI/Avalonia/discussions/9291#discussioncomment-3991602

maxkatz6 avatar Nov 03 '22 19:11 maxkatz6

I'm not quite sure if that's a job of the asset loader. Especially since scaling can be changed by moving a window to a different monitor.

kekekeks avatar Nov 04 '22 05:11 kekekeks

I want to be able to disable or enable this feature. So if I have localized images for example, I want to decide when to show which one.

timunie avatar Nov 04 '22 05:11 timunie

Some of these features intersect the changes I made for #12107.

  1. Multi-resolution images: IconBitmap. The same technique can be applied to any collection of bitmaps, not just icons.
  2. Theme variant switching: BitmapResourceExtension and the existing theme variant resource system.

TomEdwardsEnscape avatar Jul 08 '23 13:07 TomEdwardsEnscape