From 55a8f28e0a1e6def966202a200232e9ae77bb80d Mon Sep 17 00:00:00 2001 From: Malik Olivier Boussejra Date: Fri, 6 Dec 2019 11:15:57 +0900 Subject: [PATCH] Fix toggling of MenuItem and Selectable with build_with_ref Selectable or MenuItem should be toggled on click when called with build_with_ref. This is the behavior that is done in ImGui when `bool ImGui::MenuItem(const char* label, const char* shortcut, bool*p_selected, bool enabled)` is called. --- src/widget/menu.rs | 2 +- src/widget/selectable.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/widget/menu.rs b/src/widget/menu.rs index 9673dca..883e7cf 100644 --- a/src/widget/menu.rs +++ b/src/widget/menu.rs @@ -143,7 +143,7 @@ impl<'a> MenuItem<'a> { /// Builds the menu item using a mutable reference to selected state. pub fn build_with_ref(self, ui: &Ui, selected: &mut bool) -> bool { if self.selected(*selected).build(ui) { - *selected = true; + *selected = !*selected; true } else { false diff --git a/src/widget/selectable.rs b/src/widget/selectable.rs index c790823..9f3ce39 100644 --- a/src/widget/selectable.rs +++ b/src/widget/selectable.rs @@ -123,7 +123,7 @@ impl<'a> Selectable<'a> { /// Builds the selectable using a mutable reference to selected state. pub fn build_with_ref(self, ui: &Ui, selected: &mut bool) -> bool { if self.selected(*selected).build(ui) { - *selected = true; + *selected = !*selected; true } else { false