Skip to content

Commit

Permalink
updated imgui
Browse files Browse the repository at this point in the history
  • Loading branch information
jmorton06 committed Jul 5, 2023
1 parent 2842e65 commit ed6671a
Show file tree
Hide file tree
Showing 144 changed files with 17,445 additions and 9,324 deletions.
2 changes: 1 addition & 1 deletion Editor/Source/HierarchyPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ namespace Lumos

ImGuiTreeNodeFlags nodeFlags = ((m_Editor->IsSelected(node)) ? ImGuiTreeNodeFlags_Selected : 0);

nodeFlags |= ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_FramePadding | ImGuiTreeNodeFlags_AllowItemOverlap | ImGuiTreeNodeFlags_SpanAvailWidth;
nodeFlags |= ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_FramePadding | ImGuiTreeNodeFlags_AllowOverlap | ImGuiTreeNodeFlags_SpanAvailWidth;

if(noChildren)
{
Expand Down
96 changes: 79 additions & 17 deletions Editor/Source/ResourcePanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ namespace Lumos
m_Name = ICON_MDI_FOLDER_STAR " Resources###resources";
m_SimpleName = "Resources";

m_GridSize = 150.0f;
m_GridSize = 180.0f;
m_GridSize *= Application::Get().GetWindow()->GetDPIScale();
// TODO: Get Project path from editor
// #ifdef LUMOS_PLATFORM_IOS
Expand Down Expand Up @@ -201,7 +201,7 @@ namespace Lumos
directoryInfo->IsFile = true;
directoryInfo->Type = fileType;
directoryInfo->Name = directoryPath.filename().string();
directoryInfo->FileSize = StringUtilities::BytesToString(std::filesystem::file_size(directoryPath));
directoryInfo->FileSize = std::filesystem::exists(directoryPath) ? StringUtilities::BytesToString(std::filesystem::file_size(directoryPath)) : "";

std::string_view fileTypeString = s_FileTypesToString.at(FileType::Unknown);
const auto& fileStringTypeIt = s_FileTypesToString.find(fileType);
Expand Down Expand Up @@ -252,9 +252,15 @@ namespace Lumos
if(defaultOpen)
nodeFlags |= ImGuiTreeNodeFlags_DefaultOpen | ImGuiTreeNodeFlags_Leaf;

nodeFlags |= ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_AllowItemOverlap | ImGuiTreeNodeFlags_SpanAvailWidth;
nodeFlags |= ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_AllowOverlap | ImGuiTreeNodeFlags_SpanAvailWidth;

bool isOpen = ImGui::TreeNodeEx((void*)(intptr_t)(dirInfo.get()), nodeFlags, "");
if (ImGui::IsItemClicked())
{
m_PreviousDirectory = m_CurrentDir;
m_CurrentDir = dirInfo;
m_UpdateNavigationPath = true;
}

const char* folderIcon = ((isOpen && containsFolder) || m_CurrentDir == dirInfo) ? ICON_MDI_FOLDER_OPEN : ICON_MDI_FOLDER;
ImGui::SameLine();
Expand All @@ -266,12 +272,7 @@ namespace Lumos

ImVec2 verticalLineStart = ImGui::GetCursorScreenPos();

if(ImGui::IsItemClicked())
{
m_PreviousDirectory = m_CurrentDir;
m_CurrentDir = dirInfo;
m_UpdateNavigationPath = true;
}


if(isOpen && containsFolder)
{
Expand Down Expand Up @@ -579,7 +580,7 @@ namespace Lumos
const ImVec2 region = ImGui::GetContentRegionAvail();
ImGui::InvisibleButton("##DragDropTargetAssetPanelBody", region);

ImGui::SetItemAllowOverlap();
ImGui::SetNextItemAllowOverlap();
ImGui::SetCursorPos(cursorPos);

if(ImGui::BeginTable("BodyTable", columnCount, flags))
Expand Down Expand Up @@ -649,6 +650,45 @@ namespace Lumos

if(ImGui::BeginPopupContextWindow("AssetPanelHierarchyContextWindow", ImGuiPopupFlags_MouseButtonRight | ImGuiPopupFlags_NoOpenOverItems))
{
if(std::filesystem::exists(m_CopiedPath) && ImGui::Selectable("Paste"))
{
if(m_CutFile)
{
const std::filesystem::path& fullPath = m_CopiedPath;
std::string filename = fullPath.stem().string();
std::string extension = fullPath.extension().string();
std::filesystem::path destinationPath = m_BasePath / m_CurrentDir->FilePath / (filename + extension);

{
while (std::filesystem::exists(destinationPath))
{
filename += "_copy";
destinationPath = destinationPath.parent_path() / (filename + extension);
}
}
std::filesystem::rename(fullPath, destinationPath);
}
else
{
const std::filesystem::path& fullPath = m_CopiedPath;
std::string filename = fullPath.stem().string();
std::string extension = fullPath.extension().string();
std::filesystem::path destinationPath = m_BasePath / m_CurrentDir->FilePath / (filename + extension);

{
while (std::filesystem::exists(destinationPath))
{
filename += "_copy";
destinationPath = destinationPath.parent_path() / (filename + extension);
}
}
std::filesystem::copy(fullPath, destinationPath);
}
m_CopiedPath = "";
m_CutFile = false;
Refresh();
}

if(ImGui::Selectable("Open Location"))
{
auto fullPath = m_BasePath + "/" + m_CurrentDir->FilePath.string();
Expand Down Expand Up @@ -833,7 +873,7 @@ namespace Lumos
}

// Background button
bool const clicked = ImGuiUtilities::ToggleButton(ImGuiUtilities::GenerateID(), highlight, backgroundThumbnailSize, 0.0f, 1.0f, ImGuiButtonFlags_AllowItemOverlap);
bool const clicked = ImGuiUtilities::ToggleButton(ImGuiUtilities::GenerateID(), highlight, backgroundThumbnailSize, 0.0f, 1.0f, ImGuiButtonFlags_AllowOverlap);
if(clicked)
{
m_CurrentSelected = m_CurrentDir->Children[dirIndex];
Expand All @@ -842,10 +882,22 @@ namespace Lumos
if(ImGui::BeginPopupContextItem())
{
m_CurrentSelected = m_CurrentDir->Children[dirIndex];

if(ImGui::Selectable("Cut"))
{
m_CopiedPath = (m_BasePath / m_CurrentDir->Children[dirIndex]->FilePath).string();
m_CutFile = true;
}

if(ImGui::Selectable("Copy"))
{
m_CopiedPath = (m_BasePath / m_CurrentDir->Children[dirIndex]->FilePath).string();
m_CutFile = false;
}

if(ImGui::Selectable("Delete"))
{
auto fullPath = m_BasePath + "/" + m_CurrentDir->Children[dirIndex]->FilePath.string();
auto fullPath = (m_BasePath / m_CurrentDir->Children[dirIndex]->FilePath).string();

std::filesystem::remove_all(fullPath);
Refresh();
Expand All @@ -854,9 +906,19 @@ namespace Lumos
if(ImGui::Selectable("Duplicate"))
{
std::filesystem::path fullPath = m_BasePath + "/" + m_CurrentDir->Children[dirIndex]->FilePath.string();
std::filesystem::path copyPath = fullPath;
copyPath.replace_filename(fullPath.filename().string() + "(copy)");
std::filesystem::copy(fullPath, copyPath);
std::filesystem::path destinationPath = fullPath;

{
std::string filename = fullPath.stem().string();
std::string extension = fullPath.extension().string();

while (std::filesystem::exists(destinationPath))
{
filename += "_copy";
destinationPath = destinationPath.parent_path() / (filename + extension);
}
}
std::filesystem::copy(fullPath, destinationPath);
Refresh();
}

Expand Down Expand Up @@ -933,11 +995,11 @@ namespace Lumos
}

ImGui::SetCursorPos({ cursorPos.x + padding, cursorPos.y + padding });
ImGui::SetItemAllowOverlap();
ImGui::SetNextItemAllowOverlap();
ImGui::Image(reinterpret_cast<ImTextureID>(Graphics::Material::GetDefaultTexture()->GetHandle()), { backgroundThumbnailSize.x - padding * 2.0f, backgroundThumbnailSize.y - padding * 2.0f }, { 0, 0 }, { 1, 1 }, ImGui::GetStyleColorVec4(ImGuiCol_WindowBg) + ImVec4(0.04f, 0.04f, 0.04f, 0.04f));

ImGui::SetCursorPos({ cursorPos.x + thumbnailPadding * 0.75f, cursorPos.y + thumbnailPadding });
ImGui::SetItemAllowOverlap();
ImGui::SetNextItemAllowOverlap();
ImGui::Image(reinterpret_cast<ImTextureID>(textureId), { thumbnailSize, thumbnailSize }, ImVec2(0.0f, flipImage ? 1.0f : 0.0f), ImVec2(1.0f, flipImage ? 0.0f : 1.0f));

const ImVec2 typeColorFrameSize = { scaledThumbnailSizeX, scaledThumbnailSizeX * 0.03f };
Expand Down
5 changes: 4 additions & 1 deletion Editor/Source/ResourcePanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ namespace Lumos
bool m_UpdateBreadCrumbs;
bool m_ShowHiddenFiles;
int m_GridItemsPerRow;
float m_GridSize = 300.0f;
float m_GridSize = 360.0f;

ImGuiTextFilter m_Filter;

Expand All @@ -165,5 +165,8 @@ namespace Lumos
SharedPtr<DirectoryInformation> m_CurrentSelected;

Lumos::TextureLibrary m_TextureLibrary;

std::filesystem::path m_CopiedPath;
bool m_CutFile = false;
};
}
2 changes: 1 addition & 1 deletion Lumos/External/imgui/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2014-2022 Omar Cornut
Copyright (c) 2014-2023 Omar Cornut

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion Lumos/External/imgui/Plugins/ImFileBrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ inline void ImGui::FileBrowser::Display()

int escIdx = GetIO().KeyMap[ImGuiKey_Escape];
if(Button(cancel_.c_str()) || closeFlag_ ||
((flags_ & ImGuiFileBrowserFlags_CloseOnEsc) && IsWindowFocused(ImGuiFocusedFlags_RootAndChildWindows) && escIdx >= 0 && IsKeyPressed(escIdx)))
((flags_ & ImGuiFileBrowserFlags_CloseOnEsc) && IsWindowFocused(ImGuiFocusedFlags_RootAndChildWindows) && escIdx >= 0 && ImGui::IsKeyPressed(ImGuiKey_Escape)))
CloseCurrentPopup();

if(!statusStr_.empty() && !(flags_ & ImGuiFileBrowserFlags_NoStatusBar))
Expand Down
4 changes: 2 additions & 2 deletions Lumos/External/imgui/Plugins/imcmd_command_palette.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#define IMGUI_DEFINE_MATH_OPERATORS
#include "imcmd_command_palette.h"

#include "imcmd_fuzzy_search.h"

#include "imgui.h"
#include <algorithm>
#include <cstddef>
// NOTE: we try to use as much ImGui's helpers as possible, in order to reduce
Expand All @@ -12,7 +12,7 @@
#include <limits>
#include <utility>

#define IMGUI_DEFINE_MATH_OPERATORS
#include "imgui.h"
#include "imgui_internal.h"

namespace ImCmd
Expand Down
6 changes: 3 additions & 3 deletions Lumos/External/imgui/Plugins/implot/implot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1808,7 +1808,7 @@ bool UpdateInput(ImPlotPlot& plot) {

// BUTTON STATE -----------------------------------------------------------

const ImGuiButtonFlags plot_button_flags = ImGuiButtonFlags_AllowItemOverlap
const ImGuiButtonFlags plot_button_flags = ImGuiButtonFlags_AllowOverlap
| ImGuiButtonFlags_PressedOnClick
| ImGuiButtonFlags_PressedOnDoubleClick
| ImGuiButtonFlags_MouseButtonLeft
Expand Down Expand Up @@ -3397,7 +3397,7 @@ bool BeginSubplots(const char* title, int rows, int cols, const ImVec2& size, Im
ImGui::KeepAliveID(sep_id);
const ImRect sep_bb = ImRect(subplot.GridRect.Min.x, ypos-SUBPLOT_SPLITTER_HALF_THICKNESS, subplot.GridRect.Max.x, ypos+SUBPLOT_SPLITTER_HALF_THICKNESS);
bool sep_hov = false, sep_hld = false;
const bool sep_clk = ImGui::ButtonBehavior(sep_bb, sep_id, &sep_hov, &sep_hld, ImGuiButtonFlags_FlattenChildren | ImGuiButtonFlags_AllowItemOverlap | ImGuiButtonFlags_PressedOnClick | ImGuiButtonFlags_PressedOnDoubleClick);
const bool sep_clk = ImGui::ButtonBehavior(sep_bb, sep_id, &sep_hov, &sep_hld, ImGuiButtonFlags_FlattenChildren | ImGuiButtonFlags_AllowOverlap | ImGuiButtonFlags_PressedOnClick | ImGuiButtonFlags_PressedOnDoubleClick);
if ((sep_hov && G.HoveredIdTimer > SUBPLOT_SPLITTER_FEEDBACK_TIMER) || sep_hld) {
if (sep_clk && ImGui::IsMouseDoubleClicked(0)) {
float p = (subplot.RowRatios[r] + subplot.RowRatios[r+1])/2;
Expand Down Expand Up @@ -3427,7 +3427,7 @@ bool BeginSubplots(const char* title, int rows, int cols, const ImVec2& size, Im
ImGui::KeepAliveID(sep_id);
const ImRect sep_bb = ImRect(xpos-SUBPLOT_SPLITTER_HALF_THICKNESS, subplot.GridRect.Min.y, xpos+SUBPLOT_SPLITTER_HALF_THICKNESS, subplot.GridRect.Max.y);
bool sep_hov = false, sep_hld = false;
const bool sep_clk = ImGui::ButtonBehavior(sep_bb, sep_id, &sep_hov, &sep_hld, ImGuiButtonFlags_FlattenChildren | ImGuiButtonFlags_AllowItemOverlap | ImGuiButtonFlags_PressedOnClick | ImGuiButtonFlags_PressedOnDoubleClick);
const bool sep_clk = ImGui::ButtonBehavior(sep_bb, sep_id, &sep_hov, &sep_hld, ImGuiButtonFlags_FlattenChildren | ImGuiButtonFlags_AllowOverlap | ImGuiButtonFlags_PressedOnClick | ImGuiButtonFlags_PressedOnDoubleClick);
if ((sep_hov && G.HoveredIdTimer > SUBPLOT_SPLITTER_FEEDBACK_TIMER) || sep_hld) {
if (sep_clk && ImGui::IsMouseDoubleClicked(0)) {
float p = (subplot.ColRatios[c] + subplot.ColRatios[c+1])/2;
Expand Down
Loading

0 comments on commit ed6671a

Please sign in to comment.