Skip to content

Commit

Permalink
Re-add stripes to graphic picker
Browse files Browse the repository at this point in the history
  • Loading branch information
melody-rs committed Jun 30, 2024
1 parent 8898e21 commit ceea9bf
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 70 deletions.
59 changes: 33 additions & 26 deletions crates/components/src/sound_tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
};
}
});
},
);
});
Expand Down
94 changes: 50 additions & 44 deletions crates/modals/src/event_graphic_picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

use color_eyre::eyre::Context;
use egui::Widget;
use luminol_components::UiExt;
use luminol_core::prelude::*;

pub struct Modal {
Expand Down Expand Up @@ -71,6 +72,7 @@ enum Selected {
},
}

// FIXME DEAR GOD THE FORMATTING
impl Modal {
pub fn new(
update_state: &UpdateState<'_>,
Expand Down Expand Up @@ -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 };
});
}
}
});
});
});

Expand Down

0 comments on commit ceea9bf

Please sign in to comment.