dock: Fix toggle button check will stack overflow bug. (#312)
Continue #297 #309 ``` thread 'main' has overflowed its stack fatal runtime error: stack overflow [1] 45068 abort cargo run ```
This commit is contained in:
parent
3df75566b3
commit
e1e66e8f07
2 changed files with 28 additions and 8 deletions
|
|
@ -279,25 +279,37 @@ impl StackPanel {
|
|||
}
|
||||
|
||||
/// Check if the given panel is at the first top left in the stack.
|
||||
pub(super) fn is_top_left_panel(&self, panel: View<TabPanel>, cx: &AppContext) -> bool {
|
||||
pub(super) fn is_top_left_panel(
|
||||
&self,
|
||||
panel: View<TabPanel>,
|
||||
check_parent: bool,
|
||||
cx: &AppContext,
|
||||
) -> bool {
|
||||
let first_panel = self.panels.first();
|
||||
|
||||
if let Some(parent) = &self.parent {
|
||||
return parent.read(cx).is_top_left_panel(panel, cx);
|
||||
if check_parent {
|
||||
return parent.read(cx).is_top_left_panel(panel, true, cx);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(view) = first_panel {
|
||||
if let Ok(view) = view.view().downcast::<TabPanel>() {
|
||||
return view.entity_id() == panel.entity_id();
|
||||
} else if let Ok(view) = view.view().downcast::<Self>() {
|
||||
return view.read(cx).is_top_left_panel(panel, cx);
|
||||
return view.read(cx).is_top_left_panel(panel, false, cx);
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
/// Check if the given panel is at the first top right in the stack.
|
||||
pub(super) fn is_top_right_panel(&self, panel: View<TabPanel>, cx: &AppContext) -> bool {
|
||||
pub(super) fn is_top_right_panel(
|
||||
&self,
|
||||
panel: View<TabPanel>,
|
||||
check_parent: bool,
|
||||
cx: &AppContext,
|
||||
) -> bool {
|
||||
let first_panel = if self.axis.is_vertical() {
|
||||
self.panels.first()
|
||||
} else {
|
||||
|
|
@ -305,14 +317,16 @@ impl StackPanel {
|
|||
};
|
||||
|
||||
if let Some(parent) = &self.parent {
|
||||
return parent.read(cx).is_top_right_panel(panel, cx);
|
||||
if check_parent {
|
||||
return parent.read(cx).is_top_right_panel(panel, true, cx);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(view) = first_panel {
|
||||
if let Ok(view) = view.view().downcast::<TabPanel>() {
|
||||
return view.entity_id() == panel.entity_id();
|
||||
} else if let Ok(view) = view.view().downcast::<Self>() {
|
||||
return view.read(cx).is_top_right_panel(panel, cx);
|
||||
return view.read(cx).is_top_right_panel(panel, false, cx);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -366,7 +366,10 @@ impl TabPanel {
|
|||
}
|
||||
|
||||
if let Some(parent) = self.stack_panel.as_ref() {
|
||||
if !parent.read(cx).is_top_left_panel(cx.view().clone(), cx) {
|
||||
if !parent
|
||||
.read(cx)
|
||||
.is_top_left_panel(cx.view().clone(), true, cx)
|
||||
{
|
||||
return None;
|
||||
}
|
||||
}
|
||||
|
|
@ -381,7 +384,10 @@ impl TabPanel {
|
|||
}
|
||||
|
||||
if let Some(parent) = self.stack_panel.as_ref() {
|
||||
if !parent.read(cx).is_top_right_panel(cx.view().clone(), cx) {
|
||||
if !parent
|
||||
.read(cx)
|
||||
.is_top_right_panel(cx.view().clone(), true, cx)
|
||||
{
|
||||
return None;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue