Hi, I am in the process of converting my UI from egui to bevy's own, and I'm getting anxious about the mess that is my sidebar at the moment. It would be ideal if there was a way for the sidebar to "refresh" itself taking the values it needs, but I can't get my head around it for some reason. This is a minimal example of what I have came up with at the moment, is there a better way? Does anyone have examples of something similar? Thanks in advance.
#[derive(Clone, Component, Copy)]
pub (super) enum SidebarSections {
Clock,
// ...
}
pub (super) fn sidebar_setup (
parent: &mut ChildBuilder,
asset_server: &Res<AssetServer>,
) {
let sidebar_entries = IndexMap::from([
("Clock placeholder", Some(SidebarSections::Clock)),
("------------------", None),
// ...
]);
for (text, marker_maybe) in sidebar_entries.iter() {
let section = TextBundle::from_section(
text.to_string(),
TextStyle {
font: asset_server.load(settings::UI_FONT),
font_size: settings::UI_TEXT_SIZE,
color: settings::UI_TEXT_COLOR
}
);
if let Some(marker) = marker_maybe {
parent.spawn((section, *marker));
} else {
parent.spawn(section);
}
}
}
pub (super) fn sidebar_update (
clock: Res<time::clock::Clock>,
mut text_query: Query<(&mut Text, &SidebarSections)>,
) {
for (mut text, section) in &mut text_query {
match section {
SidebarSections::Clock => {
text.sections[0].value = format!("{}\n", clock.military_time());
},
},
// ...
}
}