ui/api: Added sidebar
This commit is contained in:
parent
d5d1577b43
commit
4e047beabb
@ -232,6 +232,11 @@ namespace hex {
|
|||||||
DrawCallback callback;
|
DrawCallback callback;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct SidebarItem {
|
||||||
|
std::string icon;
|
||||||
|
DrawCallback callback;
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 getDockSpaceId();
|
u32 getDockSpaceId();
|
||||||
@ -240,6 +245,7 @@ namespace hex {
|
|||||||
void addWelcomeScreenEntry(const impl::DrawCallback &function);
|
void addWelcomeScreenEntry(const impl::DrawCallback &function);
|
||||||
void addFooterItem(const impl::DrawCallback &function);
|
void addFooterItem(const impl::DrawCallback &function);
|
||||||
void addToolbarItem(const impl::DrawCallback &function);
|
void addToolbarItem(const impl::DrawCallback &function);
|
||||||
|
void addSidebarItem(const std::string &icon, const impl::DrawCallback &function);
|
||||||
|
|
||||||
void addLayout(const std::string &unlocalizedName, const impl::LayoutFunction &function);
|
void addLayout(const std::string &unlocalizedName, const impl::LayoutFunction &function);
|
||||||
|
|
||||||
@ -247,6 +253,7 @@ namespace hex {
|
|||||||
std::vector<impl::DrawCallback>& getWelcomeScreenEntries();
|
std::vector<impl::DrawCallback>& getWelcomeScreenEntries();
|
||||||
std::vector<impl::DrawCallback>& getFooterItems();
|
std::vector<impl::DrawCallback>& getFooterItems();
|
||||||
std::vector<impl::DrawCallback>& getToolbarItems();
|
std::vector<impl::DrawCallback>& getToolbarItems();
|
||||||
|
std::vector<impl::SidebarItem>& getSidebarItems();
|
||||||
|
|
||||||
std::vector<impl::Layout>& getLayouts();
|
std::vector<impl::Layout>& getLayouts();
|
||||||
}
|
}
|
||||||
|
@ -81,6 +81,7 @@ namespace hex {
|
|||||||
static std::vector<ContentRegistry::Interface::impl::DrawCallback> welcomeScreenEntries;
|
static std::vector<ContentRegistry::Interface::impl::DrawCallback> welcomeScreenEntries;
|
||||||
static std::vector<ContentRegistry::Interface::impl::DrawCallback> footerItems;
|
static std::vector<ContentRegistry::Interface::impl::DrawCallback> footerItems;
|
||||||
static std::vector<ContentRegistry::Interface::impl::DrawCallback> toolbarItems;
|
static std::vector<ContentRegistry::Interface::impl::DrawCallback> toolbarItems;
|
||||||
|
static std::vector<ContentRegistry::Interface::impl::SidebarItem> sidebarItems;
|
||||||
static std::vector<ContentRegistry::Interface::impl::Layout> layouts;
|
static std::vector<ContentRegistry::Interface::impl::Layout> layouts;
|
||||||
|
|
||||||
static std::map<Shortcut, std::function<void()>> globalShortcuts;
|
static std::map<Shortcut, std::function<void()>> globalShortcuts;
|
||||||
|
@ -312,6 +312,10 @@ namespace hex {
|
|||||||
getToolbarItems().push_back(function);
|
getToolbarItems().push_back(function);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ContentRegistry::Interface::addSidebarItem(const std::string &icon, const impl::DrawCallback &function) {
|
||||||
|
getSidebarItems().push_back({ icon, function });
|
||||||
|
}
|
||||||
|
|
||||||
void ContentRegistry::Interface::addLayout(const std::string &unlocalizedName, const impl::LayoutFunction &function) {
|
void ContentRegistry::Interface::addLayout(const std::string &unlocalizedName, const impl::LayoutFunction &function) {
|
||||||
log::info("Added new layout: {}", unlocalizedName);
|
log::info("Added new layout: {}", unlocalizedName);
|
||||||
|
|
||||||
@ -332,6 +336,9 @@ namespace hex {
|
|||||||
std::vector<ContentRegistry::Interface::impl::DrawCallback>& ContentRegistry::Interface::getToolbarItems() {
|
std::vector<ContentRegistry::Interface::impl::DrawCallback>& ContentRegistry::Interface::getToolbarItems() {
|
||||||
return SharedData::toolbarItems;
|
return SharedData::toolbarItems;
|
||||||
}
|
}
|
||||||
|
std::vector<ContentRegistry::Interface::impl::SidebarItem>& ContentRegistry::Interface::getSidebarItems() {
|
||||||
|
return SharedData::sidebarItems;
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<ContentRegistry::Interface::impl::Layout>& ContentRegistry::Interface::getLayouts() {
|
std::vector<ContentRegistry::Interface::impl::Layout>& ContentRegistry::Interface::getLayouts() {
|
||||||
return SharedData::layouts;
|
return SharedData::layouts;
|
||||||
|
@ -30,6 +30,7 @@ namespace hex {
|
|||||||
std::vector<ContentRegistry::Interface::impl::MainMenuItem> SharedData::mainMenuItems;
|
std::vector<ContentRegistry::Interface::impl::MainMenuItem> SharedData::mainMenuItems;
|
||||||
std::vector<ContentRegistry::Interface::impl::DrawCallback> SharedData::welcomeScreenEntries;
|
std::vector<ContentRegistry::Interface::impl::DrawCallback> SharedData::welcomeScreenEntries;
|
||||||
std::vector<ContentRegistry::Interface::impl::DrawCallback> SharedData::footerItems;
|
std::vector<ContentRegistry::Interface::impl::DrawCallback> SharedData::footerItems;
|
||||||
|
std::vector<ContentRegistry::Interface::impl::SidebarItem> SharedData::sidebarItems;
|
||||||
std::vector<ContentRegistry::Interface::impl::DrawCallback> SharedData::toolbarItems;
|
std::vector<ContentRegistry::Interface::impl::DrawCallback> SharedData::toolbarItems;
|
||||||
std::vector<ContentRegistry::Interface::impl::Layout> SharedData::layouts;
|
std::vector<ContentRegistry::Interface::impl::Layout> SharedData::layouts;
|
||||||
|
|
||||||
|
@ -349,15 +349,26 @@ namespace hex {
|
|||||||
ImGui::GetIO().ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
|
ImGui::GetIO().ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
|
||||||
|
|
||||||
if (ImGui::Begin("DockSpace", nullptr, windowFlags)) {
|
if (ImGui::Begin("DockSpace", nullptr, windowFlags)) {
|
||||||
|
auto drawList = ImGui::GetWindowDrawList();
|
||||||
ImGui::PopStyleVar();
|
ImGui::PopStyleVar();
|
||||||
SharedData::dockSpaceId = ImGui::DockSpace(ImGui::GetID("MainDock"), ImVec2(0.0f, ImGui::GetContentRegionAvail().y - ImGui::GetTextLineHeightWithSpacing() - ImGui::GetStyle().FramePadding.y * 2 - 1));
|
auto sidebarPos = ImGui::GetCursorPos();
|
||||||
|
auto sidebarWidth = ContentRegistry::Interface::getSidebarItems().empty() ? 0 : 30_scaled;
|
||||||
|
|
||||||
|
ImGui::SetCursorPosX(sidebarWidth);
|
||||||
|
|
||||||
|
auto footerHeight = ImGui::GetTextLineHeightWithSpacing() + ImGui::GetStyle().FramePadding.y * 2 + 1_scaled;
|
||||||
|
auto dockSpaceSize = ImVec2(SharedData::windowSize.x - sidebarWidth, ImGui::GetContentRegionAvail().y - footerHeight);
|
||||||
|
|
||||||
|
SharedData::dockSpaceId = ImGui::DockSpace(ImGui::GetID("MainDock"), dockSpaceSize);
|
||||||
|
|
||||||
|
drawList->AddRectFilled(ImGui::GetWindowPos(), ImGui::GetWindowPos() + ImGui::GetWindowSize() - ImVec2(dockSpaceSize.x, footerHeight - ImGui::GetStyle().FramePadding.y - 1_scaled), ImGui::GetColorU32(ImGuiCol_MenuBarBg));
|
||||||
|
|
||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
ImGui::SetCursorPosX(8);
|
ImGui::SetCursorPosX(8);
|
||||||
for (const auto &callback : ContentRegistry::Interface::getFooterItems()) {
|
for (const auto &callback : ContentRegistry::Interface::getFooterItems()) {
|
||||||
auto prevIdx = ImGui::GetWindowDrawList()->_VtxCurrentIdx;
|
auto prevIdx = drawList->_VtxCurrentIdx;
|
||||||
callback();
|
callback();
|
||||||
auto currIdx = ImGui::GetWindowDrawList()->_VtxCurrentIdx;
|
auto currIdx = drawList->_VtxCurrentIdx;
|
||||||
|
|
||||||
// Only draw separator if something was actually drawn
|
// Only draw separator if something was actually drawn
|
||||||
if (prevIdx != currIdx) {
|
if (prevIdx != currIdx) {
|
||||||
@ -367,6 +378,51 @@ namespace hex {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
ImGui::SetCursorPos(sidebarPos);
|
||||||
|
|
||||||
|
static s32 openWindow = -1;
|
||||||
|
u32 index = 0;
|
||||||
|
ImGui::PushID("SideBarWindows");
|
||||||
|
for (const auto &[icon, callback] : ContentRegistry::Interface::getSidebarItems()) {
|
||||||
|
ImGui::SetCursorPosY(sidebarPos.y + sidebarWidth * index);
|
||||||
|
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_Button, ImGui::GetColorU32(ImGuiCol_MenuBarBg));
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImGui::GetColorU32(ImGuiCol_ScrollbarGrabActive));
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImGui::GetColorU32(ImGuiCol_ScrollbarGrabHovered));
|
||||||
|
|
||||||
|
ImGui::BeginDisabled(!ImHexApi::Provider::isValid());
|
||||||
|
{
|
||||||
|
if (ImGui::Button(icon.c_str(), ImVec2(sidebarWidth, sidebarWidth))) {
|
||||||
|
if (openWindow == index)
|
||||||
|
openWindow = -1;
|
||||||
|
else
|
||||||
|
openWindow = index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ImGui::EndDisabled();
|
||||||
|
|
||||||
|
ImGui::PopStyleColor(3);
|
||||||
|
|
||||||
|
bool open = openWindow == index;
|
||||||
|
if (open) {
|
||||||
|
ImGui::SetNextWindowPos(ImGui::GetWindowPos() + sidebarPos + ImVec2(sidebarWidth - 2_scaled, 0));
|
||||||
|
ImGui::SetNextWindowSize(ImVec2(250_scaled, dockSpaceSize.y + ImGui::GetStyle().FramePadding.y + 2_scaled));
|
||||||
|
|
||||||
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 1);
|
||||||
|
if (ImGui::Begin("Window", &open, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoTitleBar)) {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
ImGui::End();
|
||||||
|
ImGui::PopStyleVar();
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::NewLine();
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
ImGui::PopID();
|
||||||
|
}
|
||||||
|
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
|
||||||
if (ImGui::BeginMainMenuBar()) {
|
if (ImGui::BeginMainMenuBar()) {
|
||||||
|
|
||||||
@ -420,6 +476,9 @@ namespace hex {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this->beginNativeWindowFrame();
|
this->beginNativeWindowFrame();
|
||||||
|
|
||||||
|
drawList->AddLine(ImGui::GetWindowPos() + ImVec2(sidebarWidth - 2, 0), ImGui::GetWindowPos() + ImGui::GetWindowSize() - ImVec2(dockSpaceSize.x + 2, footerHeight - ImGui::GetStyle().FramePadding.y - 2), ImGui::GetColorU32(ImGuiCol_Separator));
|
||||||
|
drawList->AddLine(ImGui::GetWindowPos() + ImVec2(sidebarWidth, ImGui::GetCurrentWindow()->MenuBarHeight()), ImGui::GetWindowPos() + ImVec2(ImGui::GetWindowSize().x, ImGui::GetCurrentWindow()->MenuBarHeight()), ImGui::GetColorU32(ImGuiCol_Separator));
|
||||||
}
|
}
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
ImGui::PopStyleVar(2);
|
ImGui::PopStyleVar(2);
|
||||||
|
Loading…
Reference in New Issue
Block a user