From ceea9bf0d99a12c1d1d3479c1ec80320d54fcc32 Mon Sep 17 00:00:00 2001 From: Melody Madeline Lyons Date: Sun, 30 Jun 2024 09:09:48 -0700 Subject: [PATCH] Re-add stripes to graphic picker --- crates/components/src/sound_tab.rs | 59 +++++++------- crates/modals/src/event_graphic_picker.rs | 94 ++++++++++++----------- 2 files changed, 83 insertions(+), 70 deletions(-) diff --git a/crates/components/src/sound_tab.rs b/crates/components/src/sound_tab.rs index 2337bb78..db7e0098 100644 --- a/crates/components/src/sound_tab.rs +++ b/crates/components/src/sound_tab.rs @@ -22,6 +22,8 @@ // terms of the Steamworks API by Valve Corporation, the licensors of this // Program grant you additional permission to convey the resulting work. +use crate::UiExt; + pub struct SoundTab { /// The source for this tab. pub source: luminol_audio::Source, @@ -165,34 +167,39 @@ impl SoundTab { row_height, self.filtered_children.len() + 1, // +1 for (None) |ui, mut row_range| { - // we really want to only show (None) if it's in range, we can collapse this but itd rely on short circuiting - #[allow(clippy::collapsible_if)] - if row_range.contains(&0) { - if ui - .selectable_value(&mut self.audio_file.name, None, "(None)") - .double_clicked() - { - self.play(update_state); + ui.with_cross_justify(|ui| { + // we really want to only show (None) if it's in range, we can collapse this but itd rely on short circuiting + #[allow(clippy::collapsible_if)] + if row_range.contains(&0) { + if ui + .selectable_value(&mut self.audio_file.name, None, "(None)") + .double_clicked() + { + self.play(update_state); + } } - } - // subtract 1 to account for (None) - row_range.start = row_range.start.saturating_sub(1); - row_range.end = row_range.end.saturating_sub(1); - // FIXME display stripes somehow - for entry in &self.filtered_children[row_range] { - // Did the user double click a sound? - if ui - .selectable_value( - &mut self.audio_file.name, - Some(entry.file_name().into()), - entry.file_name(), - ) - .double_clicked() + // subtract 1 to account for (None) + row_range.start = row_range.start.saturating_sub(1); + row_range.end = row_range.end.saturating_sub(1); + for (i, entry) in + self.filtered_children[row_range.clone()].iter().enumerate() { - // Play it if they did. - self.play(update_state); - }; - } + let faint = (i + row_range.start) % 2 == 0; + let res = ui.with_stripe(faint, |ui| { + ui.selectable_value( + &mut self.audio_file.name, + Some(entry.file_name().into()), + entry.file_name(), + ) + }); + // need to move this out because the borrow checker isn't smart enough + // Did the user double click a sound? + if res.inner.double_clicked() { + // Play it if they did. + self.play(update_state); + }; + } + }); }, ); }); diff --git a/crates/modals/src/event_graphic_picker.rs b/crates/modals/src/event_graphic_picker.rs index b75cbc66..8c57206c 100644 --- a/crates/modals/src/event_graphic_picker.rs +++ b/crates/modals/src/event_graphic_picker.rs @@ -24,6 +24,7 @@ use color_eyre::eyre::Context; use egui::Widget; +use luminol_components::UiExt; use luminol_core::prelude::*; pub struct Modal { @@ -71,6 +72,7 @@ enum Selected { }, } +// FIXME DEAR GOD THE FORMATTING impl Modal { pub fn new( update_state: &UpdateState<'_>, @@ -321,57 +323,61 @@ impl Modal { // Get row height. let row_height = ui.text_style_height(&egui::TextStyle::Body); // i do not trust this - // FIXME show stripes! // FIXME scroll to selected on first open - egui::ScrollArea::vertical() - .auto_shrink([false, true]) - .show_rows( - ui, - row_height, - self.filtered_entries.len() + 2, - |ui, mut rows| { - if rows.contains(&0) { - let res = ui.selectable_label(matches!(self.selected, Selected::None), "(None)"); - if res.clicked() && !matches!(self.selected, Selected::None) { - self.selected = Selected::None; + ui.with_cross_justify(|ui| { + egui::ScrollArea::vertical() + .auto_shrink([false, true]) + .show_rows( + ui, + row_height, + self.filtered_entries.len() + 2, + |ui, mut rows| { + if rows.contains(&0) { + let res = ui.selectable_label(matches!(self.selected, Selected::None), "(None)"); + if res.clicked() && !matches!(self.selected, Selected::None) { + self.selected = Selected::None; + } } - } - if rows.contains(&1) { - let checked = matches!(self.selected, Selected::Tile(_)); - let res = ui.selectable_label( - checked, - "(Tileset)", - ); - if res.clicked() && !checked { - self.selected = Selected::Tile(384); + if rows.contains(&1) { + let checked = matches!(self.selected, Selected::Tile(_)); + ui.with_stripe(true, |ui| { + let res = ui.selectable_label(checked, "(Tileset)"); + if res.clicked() && !checked { + self.selected = Selected::Tile(384); + } + }); } - } - // subtract 2 to account for (None) and (Tileset) - rows.start = rows.start.saturating_sub(2); - rows.end = rows.end.saturating_sub(2); - - for Entry { path: entry ,invalid} in self.filtered_entries[rows].iter_mut() { - let checked = - matches!(self.selected, Selected::Graphic { ref path, .. } if path == entry); - let mut text = egui::RichText::new(entry.as_str()); - if *invalid { - text = text.color(egui::Color32::LIGHT_RED); - } - let res = ui.add_enabled(!*invalid, egui::SelectableLabel::new(checked, text)); - if res.clicked() { - let sprite = match Self::load_preview_sprite(update_state, entry, self.hue, self.opacity) { - Ok(sprite) => sprite, - Err(e) => { - luminol_core::error!(update_state.toasts, e); - *invalid = true; // FIXME update non-filtered entry too - return; + // subtract 2 to account for (None) and (Tileset) + rows.start = rows.start.saturating_sub(2); + rows.end = rows.end.saturating_sub(2); + + for (i, Entry { path: entry ,invalid}) in self.filtered_entries[rows.clone()].iter_mut().enumerate() { + let checked = + matches!(self.selected, Selected::Graphic { ref path, .. } if path == entry); + let mut text = egui::RichText::new(entry.as_str()); + if *invalid { + text = text.color(egui::Color32::LIGHT_RED); + } + let faint = (i + rows.start) % 2 == 1; + ui.with_stripe(faint, |ui| { + let res = ui.add_enabled(!*invalid, egui::SelectableLabel::new(checked, text)); + + if res.clicked() { + let sprite = match Self::load_preview_sprite(update_state, entry, self.hue, self.opacity) { + Ok(sprite) => sprite, + Err(e) => { + luminol_core::error!(update_state.toasts, e); + *invalid = true; // FIXME update non-filtered entry too + return; + } + }; + self.selected = Selected::Graphic { path: entry.clone(), direction: 2, pattern: 0, sprite }; } - }; - self.selected = Selected::Graphic { path: entry.clone(), direction: 2, pattern: 0, sprite }; + }); } - } + }); }); });