1
0
mirror of synced 2024-11-24 07:40:17 +01:00

impr: Add command palette button to the title bar

This commit is contained in:
WerWolv 2023-11-14 00:03:22 +01:00
parent e0264a3459
commit 375c74abe5
3 changed files with 52 additions and 12 deletions

View File

@ -237,6 +237,7 @@ namespace hex {
EVENT_DEF(EventStoreContentRemoved, const std::fs::path&);
EVENT_DEF(EventImHexClosing);
EVENT_DEF(EventAchievementUnlocked, const Achievement&);
EVENT_DEF(EventSearchBoxClicked);
/**
* @brief Called when a project has been loaded

View File

@ -245,7 +245,6 @@ namespace hex {
}
void Window::drawTitleBarBorderless() const {
auto startX = ImGui::GetCursorPosX();
auto titleBarHeight = ImGui::GetCurrentWindow()->MenuBarHeight();
auto buttonSize = ImVec2(titleBarHeight * 1.5F, titleBarHeight - 1);
@ -292,8 +291,30 @@ namespace hex {
ImGui::PopStyleColor(5);
ImGui::PopStyleVar();
ImGui::SetCursorPosX(std::max(startX, (ImGui::GetWindowWidth() - ImGui::CalcTextSize(this->m_windowTitle.c_str()).x) / 2));
ImGui::TextUnformatted(this->m_windowTitle.c_str());
{
const auto windowSize = ImHexApi::System::getMainWindowSize();
const auto searchBoxSize = ImVec2(std::sqrt(windowSize.x) * 14_scaled, titleBarHeight - 3_scaled);
const auto searchBoxPos = ImVec2((windowSize / 2 - searchBoxSize / 2).x, 3_scaled);
const auto buttonColor = [](float alpha) {
return ImU32(ImColor(ImGui::GetStyleColorVec4(ImGuiCol_DockingEmptyBg) * ImVec4(1, 1, 1, alpha)));
};
ImGui::PushStyleColor(ImGuiCol_Button, buttonColor(0.5F));
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, buttonColor(0.7F));
ImGui::PushStyleColor(ImGuiCol_ButtonActive, buttonColor(0.9F));
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.0_scaled);
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 4_scaled);
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, scaled({ 1, 1 }));
ImGui::SetCursorPos(searchBoxPos);
if (ImGui::Button(this->m_windowTitle.c_str(), searchBoxSize)) {
EventManager::post<EventSearchBoxClicked>();
}
ImGui::PopStyleVar(3);
ImGui::PopStyleColor(3);
}
}
void Window::drawTitleBarBorder() {
@ -481,17 +502,29 @@ namespace hex {
ImGui::EndPopup();
}
for (const auto &[priority, menuItem] : ContentRegistry::Interface::impl::getMainMenuItems()) {
ImGui::GetStyle().TouchExtraPadding = scaled(ImVec2(0, 2));
if (ImGui::BeginMenu(LangEntry(menuItem.unlocalizedName))) {
const static auto drawMenu = [] {
for (const auto &[priority, menuItem] : ContentRegistry::Interface::impl::getMainMenuItems()) {
ImGui::GetStyle().TouchExtraPadding = scaled(ImVec2(0, 2));
if (ImGui::BeginMenu(LangEntry(menuItem.unlocalizedName))) {
ImGui::EndMenu();
}
ImGui::GetStyle().TouchExtraPadding = ImVec2(0, 0);
}
for (auto &[priority, menuItem] : ContentRegistry::Interface::impl::getMenuItems()) {
const auto &[unlocalizedNames, shortcut, callback, enabledCallback] = menuItem;
createNestedMenu(unlocalizedNames, shortcut, callback, enabledCallback);
}
};
const auto windowWidth = ImHexApi::System::getMainWindowSize().x;
if (windowWidth > 1200_scaled) {
drawMenu();
} else {
if (ImGui::BeginMenu(ICON_VS_MENU)) {
drawMenu();
ImGui::EndMenu();
}
ImGui::GetStyle().TouchExtraPadding = ImVec2(0, 0);
}
for (auto &[priority, menuItem] : ContentRegistry::Interface::impl::getMenuItems()) {
const auto &[unlocalizedNames, shortcut, callback, enabledCallback] = menuItem;
createNestedMenu(unlocalizedNames, shortcut, callback, enabledCallback);
}
this->drawTitleBar();

View File

@ -12,6 +12,12 @@ namespace hex::plugin::builtin {
this->m_commandPaletteOpen = true;
this->m_justOpened = true;
});
EventManager::subscribe<EventSearchBoxClicked>([this] {
EventManager::post<RequestOpenPopup>("hex.builtin.view.command_palette.name"_lang);
this->m_commandPaletteOpen = true;
this->m_justOpened = true;
});
}
void ViewCommandPalette::drawContent() {