1
0
mirror of synced 2024-09-24 11:38:26 +02:00

Added Footer and API for it and the welcome screen

This commit is contained in:
WerWolv 2021-02-18 12:09:19 +01:00
parent a251c7325a
commit 0e00555703
7 changed files with 87 additions and 23 deletions

View File

@ -107,7 +107,7 @@ namespace ImGui {
ImGui::PushStyleVar(ImGuiStyleVar_ButtonTextAlign, ImVec2(0.0, 0.5)); ImGui::PushStyleVar(ImGuiStyleVar_ButtonTextAlign, ImVec2(0.0, 0.5));
// Render // Render
const ImU32 col = GetColorU32((held && hovered) ? ImGuiCol_ScrollbarBg : hovered ? ImGuiCol_WindowBg : ImGuiCol_PopupBg); const ImU32 col = GetColorU32((held && hovered) ? ImGuiCol_TableHeaderBg : hovered ? ImGuiCol_TableBorderLight : ImGuiCol_TableBorderStrong);
RenderNavHighlight(bb, id); RenderNavHighlight(bb, id);
RenderFrame(bb.Min, bb.Max, col, true, style.FrameRounding); RenderFrame(bb.Min, bb.Max, col, true, style.FrameRounding);
PushStyleColor(ImGuiCol_Text, GetColorU32(ImGuiCol_ButtonActive)); PushStyleColor(ImGuiCol_Text, GetColorU32(ImGuiCol_ButtonActive));

View File

@ -37,6 +37,7 @@ namespace hex::plugin::builtin {
{ "hex.welcome.learn.plugins.title", "Plugins API\"" }, { "hex.welcome.learn.plugins.title", "Plugins API\"" },
{ "hex.welcome.learn.plugins.desc", "Extend ImHex with additional features using plugins" }, { "hex.welcome.learn.plugins.desc", "Extend ImHex with additional features using plugins" },
{ "hex.welcome.learn.plugins.link", "https://github.com/WerWolv/ImHex/wiki/Plugins-Development-Guide" }, { "hex.welcome.learn.plugins.link", "https://github.com/WerWolv/ImHex/wiki/Plugins-Development-Guide" },
{ "hex.welcome.header.various", "Various" },
{ "hex.common.little_endian", "Little Endian" }, { "hex.common.little_endian", "Little Endian" },
{ "hex.common.big_endian", "Big Endian" }, { "hex.common.big_endian", "Big Endian" },

View File

@ -183,6 +183,16 @@ namespace hex {
static std::map<std::string, std::string>& getLanguages(); static std::map<std::string, std::string>& getLanguages();
static std::map<std::string, std::vector<LanguageDefinition>>& getLanguageDefinitions(); static std::map<std::string, std::vector<LanguageDefinition>>& getLanguageDefinitions();
}; };
struct Interface {
using DrawCallback = std::function<void()>;
static void addWelcomeScreenEntry(const DrawCallback &function);
static void addFooterItem(const DrawCallback &function);
static std::vector<DrawCallback>& getWelcomeScreenEntries();
static std::vector<DrawCallback>& getFooterItems();
};
}; };
} }

View File

@ -68,6 +68,9 @@ namespace hex {
static std::map<std::string, std::vector<LanguageDefinition>> languageDefinitions; static std::map<std::string, std::vector<LanguageDefinition>> languageDefinitions;
static std::map<std::string, std::string> loadedLanguageStrings; static std::map<std::string, std::string> loadedLanguageStrings;
static std::vector<ContentRegistry::Interface::DrawCallback> welcomeScreenEntries;
static std::vector<ContentRegistry::Interface::DrawCallback> footerItems;
static imgui_addons::ImGuiFileBrowser fileBrowser; static imgui_addons::ImGuiFileBrowser fileBrowser;
static imgui_addons::ImGuiFileBrowser::DialogMode fileBrowserDialogMode; static imgui_addons::ImGuiFileBrowser::DialogMode fileBrowserDialogMode;
static std::string fileBrowserTitle; static std::string fileBrowserTitle;

View File

@ -225,4 +225,21 @@ namespace hex {
std::map<std::string, std::vector<LanguageDefinition>>& ContentRegistry::Language::getLanguageDefinitions() { std::map<std::string, std::vector<LanguageDefinition>>& ContentRegistry::Language::getLanguageDefinitions() {
return SharedData::languageDefinitions; return SharedData::languageDefinitions;
} }
void ContentRegistry::Interface::addWelcomeScreenEntry(const ContentRegistry::Interface::DrawCallback &function) {
getWelcomeScreenEntries().push_back(function);
}
void ContentRegistry::Interface::addFooterItem(const ContentRegistry::Interface::DrawCallback &function){
getFooterItems().push_back(function);
}
std::vector<ContentRegistry::Interface::DrawCallback>& ContentRegistry::Interface::getWelcomeScreenEntries() {
return SharedData::welcomeScreenEntries;
}
std::vector<ContentRegistry::Interface::DrawCallback>& ContentRegistry::Interface::getFooterItems() {
return SharedData::footerItems;
}
} }

View File

@ -22,6 +22,9 @@ namespace hex {
std::map<std::string, std::vector<LanguageDefinition>> SharedData::languageDefinitions; std::map<std::string, std::vector<LanguageDefinition>> SharedData::languageDefinitions;
std::map<std::string, std::string> SharedData::loadedLanguageStrings; std::map<std::string, std::string> SharedData::loadedLanguageStrings;
std::vector<ContentRegistry::Interface::DrawCallback> SharedData::welcomeScreenEntries;
std::vector<ContentRegistry::Interface::DrawCallback> SharedData::footerItems;
imgui_addons::ImGuiFileBrowser SharedData::fileBrowser; imgui_addons::ImGuiFileBrowser SharedData::fileBrowser;
imgui_addons::ImGuiFileBrowser::DialogMode SharedData::fileBrowserDialogMode; imgui_addons::ImGuiFileBrowser::DialogMode SharedData::fileBrowserDialogMode;
std::string SharedData::fileBrowserTitle; std::string SharedData::fileBrowserTitle;

View File

@ -131,6 +131,9 @@ namespace hex {
for (const auto &path : ContentRegistry::Settings::read("hex.builtin.setting.imhex", "hex.builtin.setting.imhex.recent_files")) for (const auto &path : ContentRegistry::Settings::read("hex.builtin.setting.imhex", "hex.builtin.setting.imhex.recent_files"))
this->m_recentFiles.push_back(path); this->m_recentFiles.push_back(path);
ContentRegistry::Interface::addFooterItem([]{ ImGui::TextUnformatted("ImHex"); });
ContentRegistry::Interface::addFooterItem([]{ ImGui::ProgressBar(0.69, ImVec2(200, 25)); });
} }
Window::~Window() { Window::~Window() {
@ -233,19 +236,33 @@ namespace hex {
ImGuiWindowFlags windowFlags = ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDocking ImGuiWindowFlags windowFlags = ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDocking
| ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse
| ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize
| ImGuiWindowFlags_NoNavFocus | ImGuiWindowFlags_NoBringToFrontOnFocus; | ImGuiWindowFlags_NoNavFocus | ImGuiWindowFlags_NoBringToFrontOnFocus
| ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse;
ImGui::GetIO().ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; ImGui::GetIO().ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
if (ImGui::Begin("DockSpace", nullptr, windowFlags)) { if (ImGui::Begin("DockSpace", nullptr, windowFlags)) {
ImGui::PopStyleVar(2); ImGui::PopStyleVar(2);
ImGui::DockSpace(ImGui::GetID("MainDock"), ImVec2(0.0f, 0.0f));
ImGui::DockSpace(ImGui::GetID("MainDock"), ImVec2(0.0f, ImGui::GetContentRegionAvail().y - ImGui::GetTextLineHeightWithSpacing() - 1));
ImGui::Separator();
for (const auto &callback : ContentRegistry::Interface::getFooterItems()) {
auto prevIdx = ImGui::GetWindowDrawList()->_VtxCurrentIdx;
callback();
auto currIdx = ImGui::GetWindowDrawList()->_VtxCurrentIdx;
// Only draw separator if something was actually drawn
if (prevIdx != currIdx) {
ImGui::SameLine();
ImGui::SeparatorEx(ImGuiSeparatorFlags_Vertical);
ImGui::SameLine();
}
}
if (ImGui::BeginMenuBar()) { if (ImGui::BeginMenuBar()) {
auto MenuBarItems = { "hex.menu.file"_lang, "hex.menu.edit"_lang, "hex.menu.view"_lang, "hex.menu.help"_lang }; for (const auto& menu : { "hex.menu.file"_lang, "hex.menu.edit"_lang, "hex.menu.view"_lang, "hex.menu.help"_lang })
for (auto menu : MenuBarItems)
if (ImGui::BeginMenu(menu)) ImGui::EndMenu(); if (ImGui::BeginMenu(menu)) ImGui::EndMenu();
if (ImGui::BeginMenu("hex.menu.view"_lang)) { if (ImGui::BeginMenu("hex.menu.view"_lang)) {
@ -332,26 +349,27 @@ namespace hex {
} }
void Window::drawWelcomeScreen() { void Window::drawWelcomeScreen() {
ImGui::UnderlinedText("hex.welcome.header.main"_lang, ImGui::GetStyleColorVec4(ImGuiCol_HeaderActive)); ImGui::UnderlinedText("hex.welcome.header.main"_lang, ImGui::GetStyleColorVec4(ImGuiCol_Text));
ImGui::NewLine(); ImGui::NewLine();
auto availableSpace = ImGui::GetContentRegionAvail(); const auto availableSpace = ImGui::GetContentRegionAvail();
const auto rowHeight = ImGui::GetTextLineHeightWithSpacing() * 6;
ImGui::Indent(); ImGui::Indent();
if (ImGui::BeginTable("Welcome Left", 1, ImGuiTableFlags_NoBordersInBody, ImVec2(availableSpace.x / 2, availableSpace.y))) { if (ImGui::BeginTable("Welcome Left", 1, ImGuiTableFlags_NoBordersInBody, ImVec2(availableSpace.x / 2, availableSpace.y))) {
ImGui::TableNextRow(ImGuiTableRowFlags_None, 100); ImGui::TableNextRow(ImGuiTableRowFlags_None, rowHeight);
ImGui::TableNextColumn(); ImGui::TableNextColumn();
ImGui::Text("hex.welcome.header.start"_lang); ImGui::TextUnformatted("hex.welcome.header.start"_lang);
{ {
if (ImGui::BulletHyperlink("hex.welcome.start.open_file"_lang)) if (ImGui::BulletHyperlink("hex.welcome.start.open_file"_lang))
EventManager::post(Events::OpenWindow, "Open File"); EventManager::post(Events::OpenWindow, "Open File");
if (ImGui::BulletHyperlink("hex.welcome.start.open_project"_lang)) if (ImGui::BulletHyperlink("hex.welcome.start.open_project"_lang))
EventManager::post(Events::OpenWindow, "Open Project"); EventManager::post(Events::OpenWindow, "Open Project");
} }
ImGui::TableNextRow(ImGuiTableRowFlags_None, 100); ImGui::TableNextRow(ImGuiTableRowFlags_None, rowHeight);
ImGui::TableNextColumn(); ImGui::TableNextColumn();
ImGui::Text("hex.welcome.start.recent"_lang); ImGui::TextUnformatted("hex.welcome.start.recent"_lang);
{ {
if (!this->m_recentFiles.empty()) { if (!this->m_recentFiles.empty()) {
for (auto &path : this->m_recentFiles) { for (auto &path : this->m_recentFiles) {
@ -362,9 +380,9 @@ namespace hex {
} }
} }
} }
ImGui::TableNextRow(ImGuiTableRowFlags_None, 100); ImGui::TableNextRow(ImGuiTableRowFlags_None, rowHeight);
ImGui::TableNextColumn(); ImGui::TableNextColumn();
ImGui::Text("hex.welcome.header.help"_lang); ImGui::TextUnformatted("hex.welcome.header.help"_lang);
{ {
if (ImGui::BulletHyperlink("hex.welcome.help.repo"_lang)) hex::openWebpage("hex.welcome.help.repo.link"_lang); if (ImGui::BulletHyperlink("hex.welcome.help.repo"_lang)) hex::openWebpage("hex.welcome.help.repo.link"_lang);
if (ImGui::BulletHyperlink("hex.welcome.help.gethelp"_lang)) hex::openWebpage("hex.welcome.help.gethelp.link"_lang); if (ImGui::BulletHyperlink("hex.welcome.help.gethelp"_lang)) hex::openWebpage("hex.welcome.help.gethelp.link"_lang);
@ -374,25 +392,37 @@ namespace hex {
} }
ImGui::SameLine(); ImGui::SameLine();
if (ImGui::BeginTable("Welcome Right", 1, ImGuiTableFlags_NoBordersInBody, ImVec2(availableSpace.x / 2, availableSpace.y))) { if (ImGui::BeginTable("Welcome Right", 1, ImGuiTableFlags_NoBordersInBody, ImVec2(availableSpace.x / 2, availableSpace.y))) {
ImGui::TableNextRow(ImGuiTableRowFlags_None, 100); ImGui::TableNextRow(ImGuiTableRowFlags_None, rowHeight);
ImGui::TableNextColumn(); ImGui::TableNextColumn();
ImGui::Text("hex.welcome.header.customize"_lang); ImGui::TextUnformatted("hex.welcome.header.customize"_lang);
{ {
if (ImGui::DescriptionButton("hex.welcome.customize.settings.title"_lang, "hex.welcome.customize.settings.desc"_lang, ImVec2(ImGui::GetContentRegionAvail().x * 0.8f, 0))) if (ImGui::DescriptionButton("hex.welcome.customize.settings.title"_lang, "hex.welcome.customize.settings.desc"_lang, ImVec2(ImGui::GetContentRegionAvail().x * 0.8F, 0)))
EventManager::post(Events::OpenWindow, "hex.view.settings.title"); EventManager::post(Events::OpenWindow, "hex.view.settings.title");
} }
ImGui::TableNextRow(ImGuiTableRowFlags_None, 100); ImGui::TableNextRow(ImGuiTableRowFlags_None, rowHeight);
ImGui::TableNextColumn(); ImGui::TableNextColumn();
ImGui::Text("hex.welcome.header.learn"_lang); ImGui::TextUnformatted("hex.welcome.header.learn"_lang);
{ {
if (ImGui::DescriptionButton("hex.welcome.learn.latest.title"_lang, "hex.welcome.learn.latest.desc"_lang, ImVec2(ImGui::GetContentRegionAvail().x * 0.8, 0))) if (ImGui::DescriptionButton("hex.welcome.learn.latest.title"_lang, "hex.welcome.learn.latest.desc"_lang, ImVec2(ImGui::GetContentRegionAvail().x * 0.8F, 0)))
hex::openWebpage("hex.welcome.learn.latest.link"_lang); hex::openWebpage("hex.welcome.learn.latest.link"_lang);
if (ImGui::DescriptionButton("hex.welcome.learn.pattern.title"_lang, "hex.welcome.learn.pattern.desc"_lang, ImVec2(ImGui::GetContentRegionAvail().x * 0.8, 0))) if (ImGui::DescriptionButton("hex.welcome.learn.pattern.title"_lang, "hex.welcome.learn.pattern.desc"_lang, ImVec2(ImGui::GetContentRegionAvail().x * 0.8F, 0)))
hex::openWebpage("hex.welcome.learn.pattern.link"_lang); hex::openWebpage("hex.welcome.learn.pattern.link"_lang);
if (ImGui::DescriptionButton("hex.welcome.learn.plugins.title"_lang, "hex.welcome.learn.plugins.desc"_lang, ImVec2(ImGui::GetContentRegionAvail().x * 0.8, 0))) if (ImGui::DescriptionButton("hex.welcome.learn.plugins.title"_lang, "hex.welcome.learn.plugins.desc"_lang, ImVec2(ImGui::GetContentRegionAvail().x * 0.8F, 0)))
hex::openWebpage("hex.welcome.learn.plugins.link"_lang); hex::openWebpage("hex.welcome.learn.plugins.link"_lang);
} }
auto extraWelcomeScreenEntries = ContentRegistry::Interface::getWelcomeScreenEntries();
if (!extraWelcomeScreenEntries.empty()) {
ImGui::TableNextRow(ImGuiTableRowFlags_None, rowHeight);
ImGui::TableNextColumn();
ImGui::TextUnformatted("hex.welcome.header.various"_lang);
{
for (const auto &callback : extraWelcomeScreenEntries)
callback();
}
}
ImGui::EndTable(); ImGui::EndTable();
} }
} }
@ -498,7 +528,7 @@ namespace hex {
ImGuiStyle& style = ImGui::GetStyle(); ImGuiStyle& style = ImGui::GetStyle();
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable | ImGuiConfigFlags_ViewportsEnable | ImGuiConfigFlags_NavEnableKeyboard; io.ConfigFlags |= ImGuiConfigFlags_DockingEnable | ImGuiConfigFlags_ViewportsEnable | ImGuiConfigFlags_NavEnableKeyboard;
io.ConfigViewportsNoTaskBarIcon = true; io.ConfigViewportsNoTaskBarIcon = false;
io.KeyMap[ImGuiKey_Tab] = GLFW_KEY_TAB; io.KeyMap[ImGuiKey_Tab] = GLFW_KEY_TAB;
io.KeyMap[ImGuiKey_LeftArrow] = GLFW_KEY_LEFT; io.KeyMap[ImGuiKey_LeftArrow] = GLFW_KEY_LEFT;
io.KeyMap[ImGuiKey_RightArrow] = GLFW_KEY_RIGHT; io.KeyMap[ImGuiKey_RightArrow] = GLFW_KEY_RIGHT;