From c0b653f506fd8f389d4cc2c762e41ddb45b02a80 Mon Sep 17 00:00:00 2001 From: Michael Aaron Murphy Date: Fri, 19 Apr 2024 11:20:20 +0200 Subject: [PATCH] fix(segmented-button): crash when context menu is unassigned --- src/widget/segmented_button/widget.rs | 32 ++++++++++++++------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/widget/segmented_button/widget.rs b/src/widget/segmented_button/widget.rs index 68e6dd76..6582b7a4 100644 --- a/src/widget/segmented_button/widget.rs +++ b/src/widget/segmented_button/widget.rs @@ -883,23 +883,25 @@ where } // Present a context menu on a right click event. - if let Some(on_context) = self.on_context.as_ref() { - if right_button_released(&event) - || (touch_lifted(&event) && fingers_pressed == 2) - { - state.show_context = Some(key); - state.context_cursor = - cursor_position.position().unwrap_or_default(); - state.focused = true; - state.focused_item = Item::Tab(key); + if self.context_menu.is_some() { + if let Some(on_context) = self.on_context.as_ref() { + if right_button_released(&event) + || (touch_lifted(&event) && fingers_pressed == 2) + { + state.show_context = Some(key); + state.context_cursor = + cursor_position.position().unwrap_or_default(); + state.focused = true; + state.focused_item = Item::Tab(key); - let menu_state = - tree.children[0].state.downcast_mut::(); - menu_state.open = true; - menu_state.view_cursor = cursor_position; + let menu_state = + tree.children[0].state.downcast_mut::(); + menu_state.open = true; + menu_state.view_cursor = cursor_position; - shell.publish(on_context(key)); - return event::Status::Captured; + shell.publish(on_context(key)); + return event::Status::Captured; + } } } }