impr: Don't reconstruct toolbar items list every frame
This commit is contained in:
parent
de24453fb9
commit
c6a569ed88
@ -774,6 +774,7 @@ namespace hex {
|
||||
const std::multimap<u32, MainMenuItem>& getMainMenuItems();
|
||||
|
||||
const std::multimap<u32, MenuItem>& getMenuItems();
|
||||
const std::vector<MenuItem*>& getToolbarMenuItems();
|
||||
std::multimap<u32, MenuItem>& getMenuItemsMutable();
|
||||
|
||||
const std::vector<DrawCallback>& getWelcomeScreenEntries();
|
||||
@ -916,6 +917,11 @@ namespace hex {
|
||||
*/
|
||||
void addMenuItemToToolbar(const UnlocalizedString &unlocalizedName, ImGuiCustomCol color);
|
||||
|
||||
/**
|
||||
* @brief Reconstructs the toolbar items list after they have been modified
|
||||
*/
|
||||
void updateToolbarItems();
|
||||
|
||||
/**
|
||||
* @brief Adds a new sidebar item
|
||||
* @param icon The icon to use for the item
|
||||
|
@ -821,6 +821,12 @@ namespace hex {
|
||||
return *s_menuItems;
|
||||
}
|
||||
|
||||
static AutoReset<std::vector<MenuItem*>> s_toolbarMenuItems;
|
||||
const std::vector<MenuItem*>& getToolbarMenuItems() {
|
||||
return s_toolbarMenuItems;
|
||||
}
|
||||
|
||||
|
||||
std::multimap<u32, MenuItem>& getMenuItemsMutable() {
|
||||
return *s_menuItems;
|
||||
}
|
||||
@ -930,11 +936,35 @@ namespace hex {
|
||||
if (menuItem.unlocalizedNames.back() == unlocalizedName) {
|
||||
menuItem.toolbarIndex = maxIndex + 1;
|
||||
menuItem.icon.color = color;
|
||||
updateToolbarItems();
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct MenuItemSorter {
|
||||
bool operator()(const auto *a, const auto *b) const {
|
||||
return a->toolbarIndex < b->toolbarIndex;
|
||||
}
|
||||
};
|
||||
|
||||
void updateToolbarItems() {
|
||||
std::set<ContentRegistry::Interface::impl::MenuItem*, MenuItemSorter> menuItems;
|
||||
|
||||
for (auto &[priority, menuItem] : impl::getMenuItemsMutable()) {
|
||||
if (menuItem.toolbarIndex != -1) {
|
||||
menuItems.insert(&menuItem);
|
||||
}
|
||||
}
|
||||
|
||||
impl::s_toolbarMenuItems->clear();
|
||||
for (auto menuItem : menuItems) {
|
||||
impl::s_toolbarMenuItems->push_back(menuItem);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void addSidebarItem(const std::string &icon, const impl::DrawCallback &function, const impl::EnabledCallback &enabledCallback) {
|
||||
impl::s_sidebarItems->push_back({ icon, function, enabledCallback });
|
||||
|
@ -644,6 +644,12 @@ namespace hex::plugin::builtin {
|
||||
|
||||
static void createHelpMenu() {
|
||||
ContentRegistry::Interface::registerMainMenuItem("hex.builtin.menu.help", 6000);
|
||||
|
||||
ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.help", "Interactive Help"}, 10000, Shortcut::None, []{
|
||||
TutorialManager::startHelpHover();
|
||||
});
|
||||
|
||||
TutorialManager::addInteractiveHelpLink({ View::toWindowName("hex.builtin.view.pattern_data.name") }, "https://google.com");
|
||||
}
|
||||
|
||||
|
||||
|
@ -572,6 +572,10 @@ namespace hex::plugin::builtin {
|
||||
ImGui::EndTable();
|
||||
}
|
||||
|
||||
if (changed) {
|
||||
ContentRegistry::Interface::updateToolbarItems();
|
||||
}
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
@ -609,6 +613,8 @@ namespace hex::plugin::builtin {
|
||||
}
|
||||
|
||||
m_currIndex = toolbarItems.size();
|
||||
|
||||
ContentRegistry::Interface::updateToolbarItems();
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -328,12 +328,6 @@ namespace hex::plugin::builtin {
|
||||
}
|
||||
}
|
||||
|
||||
struct MenuItemSorter {
|
||||
bool operator()(const auto *a, const auto *b) const {
|
||||
return a->toolbarIndex < b->toolbarIndex;
|
||||
}
|
||||
};
|
||||
|
||||
void drawProviderTooltip(const prv::Provider *provider) {
|
||||
if (ImGuiExt::InfoTooltip()) {
|
||||
ImGui::BeginTooltip();
|
||||
@ -416,16 +410,8 @@ namespace hex::plugin::builtin {
|
||||
|
||||
// Toolbar items
|
||||
ContentRegistry::Interface::addToolbarItem([] {
|
||||
// TODO: Optimize this
|
||||
std::set<const ContentRegistry::Interface::impl::MenuItem*, MenuItemSorter> menuItems;
|
||||
|
||||
for (const auto &[priority, menuItem] : ContentRegistry::Interface::impl::getMenuItems()) {
|
||||
if (menuItem.toolbarIndex != -1) {
|
||||
menuItems.insert(&menuItem);
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto &menuItem : menuItems) {
|
||||
for (const auto &menuItem : ContentRegistry::Interface::impl::getToolbarMenuItems()) {
|
||||
if (menuItem->unlocalizedNames.back().get() == ContentRegistry::Interface::impl::SeparatorValue) {
|
||||
ImGui::SeparatorEx(ImGuiSeparatorFlags_Vertical);
|
||||
continue;
|
||||
|
Loading…
Reference in New Issue
Block a user