Skip to content

Commit

Permalink
[Waddy] CTRL for multi select & SHIFT for multi select by range (#15)
Browse files Browse the repository at this point in the history
* waddy: select multiple with ctrl

* waddy: range selection with shift
  • Loading branch information
G2Pavon authored Sep 20, 2024
1 parent 6d46ae9 commit 60b6fe5
Showing 1 changed file with 31 additions and 7 deletions.
38 changes: 31 additions & 7 deletions src/gui/programs/waddy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,15 +396,39 @@ impl WaddyGui {

// if left clicked, add to the list of selected
if clickable_image.clicked() {
if is_selected {
let unselect_idx = self.instances[instance_index]
.selected
.iter()
.position(|&idx| idx == texture_tile_index)
.unwrap();
let input_modifiers = ui.input(|i| i.modifiers);

if input_modifiers.ctrl {
if is_selected {
let unselect_idx = self.instances[instance_index]
.selected
.iter()
.position(|&idx| idx == texture_tile_index)
.unwrap();

self.instances[instance_index].selected.remove(unselect_idx);
self.instances[instance_index].selected.remove(unselect_idx);
} else {
self.instances[instance_index]
.selected
.push(texture_tile_index);
}
} else if input_modifiers.shift {
if let Some(&last_index) = self.instances[instance_index].selected.last() {
let range_start = last_index.min(texture_tile_index);
let range_end = last_index.max(texture_tile_index);

for idx in range_start..=range_end {
if !self.instances[instance_index].selected.contains(&idx) {
self.instances[instance_index].selected.push(idx);
}
}
} else {
self.instances[instance_index]
.selected
.push(texture_tile_index);
}
} else {
self.instances[instance_index].selected.clear();
self.instances[instance_index]
.selected
.push(texture_tile_index);
Expand Down

0 comments on commit 60b6fe5

Please sign in to comment.