From 22767c9cfbcfecd67502d5e0162dadac24077dae Mon Sep 17 00:00:00 2001 From: Max833 <53529402+Max833@users.noreply.github.com> Date: Sun, 11 Jul 2021 17:48:22 +0200 Subject: [PATCH] Update menu-bar.cpp --- hiro/windows/menu-bar.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/hiro/windows/menu-bar.cpp b/hiro/windows/menu-bar.cpp index fc2c5bc5..39fc9560 100644 --- a/hiro/windows/menu-bar.cpp +++ b/hiro/windows/menu-bar.cpp @@ -7,6 +7,7 @@ auto pMenuBar::construct() -> void { } auto pMenuBar::destruct() -> void { + pApplication::state().staleMenus.removeByValue(this); if(hmenu) { DestroyMenu(hmenu); hmenu = nullptr; } if(auto parent = _parent()) { SetMenu(parent->hwnd, nullptr); @@ -44,6 +45,20 @@ auto pMenuBar::_parent() -> maybe { } auto pMenuBar::_update() -> void { + bool updateNow = false; + if(auto parent = _parent()) { + updateNow = GetMenu(parent->hwnd) == nullptr; + } + + if (updateNow) { + _updateDeferred(); + } else { + pApplication::state().staleMenus.removeByValue(this); + pApplication::state().staleMenus.append(this); + } +} + +auto pMenuBar::_updateDeferred() -> void { if(hmenu) DestroyMenu(hmenu); hmenu = CreateMenu();