Set width of soundtrack menu to longest

This commit is contained in:
dawnDus 2022-02-10 18:37:08 -05:00
parent 2e3245c654
commit 8cd22b932b
No known key found for this signature in database
GPG Key ID: 972AABDE81848F21
1 changed files with 9 additions and 2 deletions

View File

@ -126,10 +126,17 @@ impl SettingsMenu {
soundtrack_entries.sort();
for soundtrack in soundtrack_entries {
self.soundtrack.push_entry(MenuEntry::Active(soundtrack));
for soundtrack in &soundtrack_entries {
self.soundtrack.push_entry(MenuEntry::Active(soundtrack.to_string()));
}
self.soundtrack.width = soundtrack_entries
.into_iter()
.map(|str| state.font.text_width(str.chars(), &state.constants))
.max_by(|a, b| a.abs().partial_cmp(&b.abs()).unwrap())
.unwrap_or(self.soundtrack.width as f32) as u16
+ 32;
self.soundtrack.push_entry(MenuEntry::Active("< Back".to_owned()));
self.update_sizes(state);