diff --git a/src/modules/custom/button.rs b/src/modules/custom/button.rs index 540cf27..433be01 100644 --- a/src/modules/custom/button.rs +++ b/src/modules/custom/button.rs @@ -43,7 +43,7 @@ impl CustomWidget for ButtonWidget { ExecEvent { cmd: exec.clone(), args: None, - id: button.popup_id(), + id: button.try_popup_id().unwrap_or(usize::MAX), // may not be a popup button } ); }); diff --git a/src/modules/mod.rs b/src/modules/mod.rs index 0f6faec..e1031ac 100644 --- a/src/modules/mod.rs +++ b/src/modules/mod.rs @@ -115,17 +115,24 @@ impl ModulePopup for Option { } pub trait PopupButton { + fn try_popup_id(&self) -> Option; fn popup_id(&self) -> usize; } impl PopupButton for Button { + /// Gets the popup ID associated with this button, if there is one. + /// Will return `None` if this is not a popup button. + fn try_popup_id(&self) -> Option { + self.get_tag("popup-id").copied() + } + /// Gets the popup ID associated with this button. /// This should only be called on buttons which are known to be associated with popups. /// /// # Panics /// Will panic if an ID has not been set. fn popup_id(&self) -> usize { - *self.get_tag("popup-id").expect("data to exist") + self.try_popup_id().expect("id to exist") } }