impr: Add command palette button to the title bar
This commit is contained in:
parent
e0264a3459
commit
375c74abe5
@ -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
|
||||
|
@ -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,6 +502,7 @@ namespace hex {
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
|
||||
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))) {
|
||||
@ -493,6 +515,17 @@ namespace hex {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
this->drawTitleBar();
|
||||
|
||||
|
@ -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() {
|
||||
|
Loading…
Reference in New Issue
Block a user