Skip to content

Commit

Permalink
Rework variable and switch picker to be more inline with database edi…
Browse files Browse the repository at this point in the history
…tors
  • Loading branch information
melody-rs committed Feb 9, 2024
1 parent 6e41bcc commit c340bf3
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 89 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions crates/core/src/modal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@ pub trait Modal: Sized {
data: &'m mut Self::Data,
update_state: &'m mut crate::UpdateState<'_>,
) -> impl egui::Widget + 'm;

fn reset(&mut self);
}
2 changes: 2 additions & 0 deletions crates/modals/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ luminol-data.workspace = true
luminol-components.workspace = true
luminol-filesystem.workspace = true
luminol-graphics.workspace = true

fuzzy-matcher = "0.3.7"
4 changes: 4 additions & 0 deletions crates/modals/src/event_graphic_picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ impl luminol_core::Modal for Modal {
button_response
}
}

fn reset(&mut self) {
todo!()
}
}

impl Modal {
Expand Down
4 changes: 4 additions & 0 deletions crates/modals/src/graphic_picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ impl luminol_core::Modal for Modal {
button_response
}
}

fn reset(&mut self) {
todo!()
}
}

impl Modal {
Expand Down
5 changes: 5 additions & 0 deletions crates/modals/src/sound_picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ impl luminol_core::Modal for Modal {
button_response
}
}

fn reset(&mut self) {
self.tab.audio_file.name = None;
self.open = false;
}
}

impl Modal {
Expand Down
59 changes: 22 additions & 37 deletions crates/modals/src/switch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@
// terms of the Steamworks API by Valve Corporation, the licensors of this
// Program grant you additional permission to convey the resulting work.

use luminol_components::UiExt;

#[derive(Default)]
/// The switch picker modal.
pub enum Modal {
#[default]
Closed,
Open {
switch_id_range: std::ops::Range<usize>,
search_text: String,
switch_id: usize,
},
Expand All @@ -44,15 +47,14 @@ impl luminol_core::Modal for Modal {
let button_text = if ui.is_enabled() {
let system = update_state.data.system();
*data = system.switches.len().min(*data);
format!("{data:0>3}: {}", system.switches[*data])
format!("{:0>3}: {}", *data + 1, system.switches[*data])
} else {
"...".to_string()
};
let button_response = ui.button(button_text);

if button_response.clicked() {
*self = Self::Open {
switch_id_range: *data..*data,
search_text: String::new(),
switch_id: *data,
};
Expand All @@ -64,6 +66,10 @@ impl luminol_core::Modal for Modal {
button_response
}
}

fn reset(&mut self) {
*self = Self::Closed;
}
}

impl Modal {
Expand All @@ -78,7 +84,6 @@ impl Modal {
let mut needs_save = false;

let Self::Open {
switch_id_range,
search_text,
switch_id,
} = self
Expand All @@ -92,53 +97,33 @@ impl Modal {
.show(ctx, |ui| {
let system = update_state.data.system();

let matcher = fuzzy_matcher::skim::SkimMatcherV2::default();

ui.group(|ui| {
egui::ScrollArea::vertical()
.auto_shrink([false, false])
.max_height(384.)
.show(ui, |ui| {
for (id, name) in
system.switches.iter().enumerate().filter(|(id, s)| {
(id + 1).to_string().contains(search_text.as_str())
|| s.contains(search_text.as_str())
})
{
let id = id + 1;
let mut text = egui::RichText::new(format!("{id}: {name}"));

if switch_id_range.start == id {
text = text.color(egui::Color32::YELLOW);
for (id, name) in system.switches.iter().enumerate() {
let text = format!("{:0>3}: {name}", id + 1);
if matcher.fuzzy(&text, search_text, false).is_none() {
continue;
}

let response = ui.selectable_value(switch_id, id, text);

if switch_id_range.end == id {
switch_id_range.end = usize::MAX;
switch_id_range.start = id;

response.scroll_to_me(None);
}

if response.double_clicked() {
keep_open = false;
needs_save = true;
}
ui.with_stripe(id % 2 == 0, |ui| {
let response = ui.selectable_value(switch_id, id, text);
if response.double_clicked() {
keep_open = false;
needs_save = true;
}
});
}
})
});

ui.horizontal(|ui| {
luminol_components::close_options_ui(ui, &mut keep_open, &mut needs_save);

if ui
.add(
egui::DragValue::new(&mut switch_id_range.start)
.clamp_range(0..=system.switches.len()),
)
.changed()
{
switch_id_range.end = switch_id_range.start;
};
egui::TextEdit::singleline(search_text)
.hint_text("Search 🔎")
.show(ui);
Expand Down
59 changes: 22 additions & 37 deletions crates/modals/src/variable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@
// terms of the Steamworks API by Valve Corporation, the licensors of this
// Program grant you additional permission to convey the resulting work.

use luminol_components::UiExt;

#[derive(Default)]
/// The variable picker modal.
pub enum Modal {
#[default]
Closed,
Open {
variable_id_range: std::ops::Range<usize>,
search_text: String,
variable_id: usize,
},
Expand All @@ -44,15 +47,14 @@ impl luminol_core::Modal for Modal {
let button_text = if ui.is_enabled() {
let system = update_state.data.system();
*data = system.variables.len().min(*data);
format!("{data:0>3}: {}", system.variables[*data])
format!("{:0>3}: {}", *data + 1, system.variables[*data])
} else {
"...".to_string()
};
let button_response = ui.button(button_text);

if button_response.clicked() {
*self = Self::Open {
variable_id_range: *data..*data,
search_text: String::new(),
variable_id: *data,
};
Expand All @@ -64,6 +66,10 @@ impl luminol_core::Modal for Modal {
button_response
}
}

fn reset(&mut self) {
*self = Self::Closed;
}
}

impl Modal {
Expand All @@ -78,7 +84,6 @@ impl Modal {
let mut needs_save = false;

let Self::Open {
variable_id_range,
search_text,
variable_id,
} = self
Expand All @@ -92,53 +97,33 @@ impl Modal {
.show(ctx, |ui| {
let system = update_state.data.system();

let matcher = fuzzy_matcher::skim::SkimMatcherV2::default();

ui.group(|ui| {
egui::ScrollArea::vertical()
.auto_shrink([false, false])
.max_height(384.)
.show(ui, |ui| {
for (id, name) in
system.variables.iter().enumerate().filter(|(id, s)| {
(id + 1).to_string().contains(search_text.as_str())
|| s.contains(search_text.as_str())
})
{
let id = id + 1;
let mut text = egui::RichText::new(format!("{id}: {name}"));

if variable_id_range.start == id {
text = text.color(egui::Color32::YELLOW);
for (id, name) in system.variables.iter().enumerate() {
let text = format!("{:0>3}: {name}", id + 1);
if matcher.fuzzy(&text, search_text, false).is_none() {
continue;
}

let response = ui.selectable_value(variable_id, id, text);

if variable_id_range.end == id {
variable_id_range.end = usize::MAX;
variable_id_range.start = id;

response.scroll_to_me(None);
}

if response.double_clicked() {
keep_open = false;
needs_save = true;
}
ui.with_stripe(id % 2 == 0, |ui| {
let response = ui.selectable_value(variable_id, id, text);
if response.double_clicked() {
keep_open = false;
needs_save = true;
}
});
}
})
});

ui.horizontal(|ui| {
luminol_components::close_options_ui(ui, &mut keep_open, &mut needs_save);

if ui
.add(
egui::DragValue::new(&mut variable_id_range.start)
.clamp_range(0..=system.variables.len()),
)
.changed()
{
variable_id_range.end = variable_id_range.start;
};
egui::TextEdit::singleline(search_text)
.hint_text("Search 🔎")
.show(ui);
Expand Down
Loading

0 comments on commit c340bf3

Please sign in to comment.