Added render_arrow_color.

`generate_enum_property_mod` now generates `as_str` taking a value.
This commit is contained in:
Filipe Rodrigues 2021-05-15 11:18:20 +01:00
parent fc03e1c5c0
commit 51e2c7ebbf
2 changed files with 14 additions and 10 deletions

View File

@ -404,15 +404,7 @@ fn render_digimon_card(
ui.group(|ui| {
ui.label("Effect arrow color");
ui.horizontal(|ui| {
for arrow_color in std::iter::once(None).chain(ArrowColor::ALL.iter().map(Some)) {
let text = match arrow_color {
Some(arrow_color) => arrow_color.as_str(),
None => "None",
};
ui.radio_value(&mut digimon.effect_arrow_color, arrow_color.copied(), text);
}
});
self::render_arrow_color(ui, &mut digimon.effect_arrow_color);
});
ui.group(|ui| {
@ -823,6 +815,18 @@ fn render_level(ui: &mut egui::Ui, cur_level: &mut Level) {
});
}
/// Displays an arrow color
fn render_arrow_color(ui: &mut egui::Ui, cur_color: &mut Option<ArrowColor>) {
let to_str = |color: Option<ArrowColor>| color.map_or("None", ArrowColor::as_str);
egui::ComboBox::from_id_source(cur_color as *const _)
.selected_text(to_str(*cur_color))
.show_ui(ui, |ui| {
for color in ArrowColor::ALL.iter().copied().map(Some).chain(std::iter::once(None)) {
ui.selectable_value(cur_color, color, to_str(color));
}
});
}
/// Displays a move
fn render_move(ui: &mut egui::Ui, name: &str, mv: &mut Move, mv_name: &mut String) {
ui.group(|ui| {

View File

@ -131,7 +131,7 @@ macro_rules! generate_enum_property_mod
];
/// Returns a string representing this
pub fn as_str(&self) -> &'static str {
pub fn as_str(self) -> &'static str {
match self {
$(
<$enum_name>::$enum_variant_name => $enum_variant_rename,