tiles: Fix panels get item out of bound error when removed some panel. (#675)
This commit is contained in:
parent
9732c3b7e8
commit
76efa2715b
1 changed files with 27 additions and 23 deletions
|
|
@ -847,30 +847,14 @@ impl Tiles {
|
||||||
|
|
||||||
// Handle dragging
|
// Handle dragging
|
||||||
if let Some(index) = self.dragging_index {
|
if let Some(index) = self.dragging_index {
|
||||||
let initial_bounds = self.dragging_initial_bounds;
|
if let Some(item) = self.panels.get(index) {
|
||||||
let current_bounds = self.panels[index].bounds;
|
let initial_bounds = self.dragging_initial_bounds;
|
||||||
if initial_bounds.origin != current_bounds.origin
|
let current_bounds = item.bounds;
|
||||||
|| initial_bounds.size != current_bounds.size
|
if initial_bounds.origin != current_bounds.origin
|
||||||
{
|
|| initial_bounds.size != current_bounds.size
|
||||||
changes_to_push.push(TileChange {
|
{
|
||||||
tile_id: self.panels[index].panel.view().entity_id(),
|
|
||||||
old_bounds: Some(initial_bounds),
|
|
||||||
new_bounds: Some(current_bounds),
|
|
||||||
old_order: None,
|
|
||||||
new_order: None,
|
|
||||||
version: 0,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle resizing
|
|
||||||
if let Some(index) = self.resizing_index {
|
|
||||||
if let Some(drag_data) = &self.resizing_drag_data {
|
|
||||||
let initial_bounds = drag_data.last_bounds;
|
|
||||||
let current_bounds = self.panels[index].bounds;
|
|
||||||
if initial_bounds.size != current_bounds.size {
|
|
||||||
changes_to_push.push(TileChange {
|
changes_to_push.push(TileChange {
|
||||||
tile_id: self.panels[index].panel.view().entity_id(),
|
tile_id: item.panel.view().entity_id(),
|
||||||
old_bounds: Some(initial_bounds),
|
old_bounds: Some(initial_bounds),
|
||||||
new_bounds: Some(current_bounds),
|
new_bounds: Some(current_bounds),
|
||||||
old_order: None,
|
old_order: None,
|
||||||
|
|
@ -881,6 +865,26 @@ impl Tiles {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle resizing
|
||||||
|
if let Some(index) = self.resizing_index {
|
||||||
|
if let Some(drag_data) = &self.resizing_drag_data {
|
||||||
|
if let Some(item) = self.panels.get(index) {
|
||||||
|
let initial_bounds = drag_data.last_bounds;
|
||||||
|
let current_bounds = item.bounds;
|
||||||
|
if initial_bounds.size != current_bounds.size {
|
||||||
|
changes_to_push.push(TileChange {
|
||||||
|
tile_id: item.panel.view().entity_id(),
|
||||||
|
old_bounds: Some(initial_bounds),
|
||||||
|
new_bounds: Some(current_bounds),
|
||||||
|
old_order: None,
|
||||||
|
new_order: None,
|
||||||
|
version: 0,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Push changes to history if any
|
// Push changes to history if any
|
||||||
if !changes_to_push.is_empty() {
|
if !changes_to_push.is_empty() {
|
||||||
for change in changes_to_push {
|
for change in changes_to_push {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue