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.
This commit is contained in:
Malik Olivier Boussejra 2019-12-06 11:15:57 +09:00
parent ffff82d5e4
commit 55a8f28e0a
2 changed files with 2 additions and 2 deletions

View File

@ -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

View File

@ -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