ltk::theme::assets

Function branding_raster

Source
pub fn branding_raster(name: &str, sw: u32, sh: u32) -> Option<PathBuf>
Expand description

Resolve a raster variant of a branded asset for the given surface dimensions. Looks under branding/{mode}/{name}/ (with the standard mode → opposite-mode → no-mode fallback chain on the directory), parses each filename as WIDTHxHEIGHT.<ext> where <ext> is webp, png, jpg, or jpeg. Returns the best match in the first existing directory:

  • If one or more entries cover the surface (W ≥ sw && H ≥ sh), returns the smallest such by area — the smallest raster that fits without upscaling.
  • Otherwise returns the largest entry available — better to upscale a fast-decoding raster than to fall back to the comparatively expensive SVG rasterisation.

Ties on area are broken by (width, height) lexicographic order for determinism.

(sw, sh) of (0, 0) means “give me the smallest available raster” — every entry trivially covers a zero-sized surface, so the smallest by area wins. Useful at startup before the surface-configure event has reported the real dimensions.

Returns None only when no directory in the fallback chain contains any parseable raster file.

Note: only the first existing mode-directory in the chain is considered. If branding/{active_mode}/{name}/ has any raster, the loader uses it; it does not cross over to the opposite-mode directory. Cross-mode fallback happens at the SVG layer through branding_asset, where a colour-wrong raster would be more jarring than a colour-correct vector.