In the last days, I tried to update my Bevy chess GUI from Bevy 0.14 to 0.16, and so I had to study a few of the recent Bevy examples codes. One is Text which has the code segment below. I wonder if there is really no more compact method available for the optional font field?
if cfg!(feature = "default_font") {
(
TextFont {
font_size: 33.0,
// If no font is specified, the default font (a minimal subset of FiraMono) will be used.
..default()
},
TextColor(GOLD.into()),
)
} else {
(
// "default_font" feature is unavailable, load a font to use instead.
TextFont {
font: asset_server.load("fonts/FiraMono-Medium.ttf"),
font_size: 33.0,
..Default::default()
},
TextColor(GOLD.into()),
)
},
The difference is that this uses the value of the font field from TextFont::default(), whereas yours will use the value produced by Handle::<Font>::default(). These happen to be the same in Bevy 0.16, but for an arbitrary choice of struct, they may be different values.
Thanks. That was my assumption initially, but GPT-5 first said it would not work, with a strange explanation. When I told it its explanation makes not much sense, it suggested
This is for latest Rust 1.89 -- my own earlier attempts for such conditional compilation most of the time failed, I assume because of my own stupid syntax errors.