mirror of
https://github.com/antopilo/Nuake.git
synced 2026-09-15 20:08:54 +03:00
Improved filebrowser
This commit is contained in:
@@ -210,7 +210,7 @@ void FileBrowserWidget::Draw()
|
||||
if (child)
|
||||
{
|
||||
int width = availableSpace.x;
|
||||
ImVec2 buttonSize = ImVec2(80, 80);
|
||||
ImVec2 buttonSize = ImVec2(60, 60);
|
||||
int amount = (int)(width / 110);
|
||||
if (amount <= 0) amount = 1;
|
||||
|
||||
@@ -254,7 +254,7 @@ void FileBrowserWidget::Draw()
|
||||
{
|
||||
if (searchQuery.empty() || f->GetName().find(String::Sanitize(searchQuery)) != std::string::npos)
|
||||
{
|
||||
if (f->GetFileType() == FileType::Unknown || f->GetFileType() == FileType::Assembly)
|
||||
if (f->GetFileType() == FileType::Unknown || f->GetFileType() == FileType::Assembly)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -328,10 +328,12 @@ void FileBrowserWidget::DrawDirectory(Ref<Nuake::Directory> directory, uint32_t
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 4.0f);
|
||||
const char* icon = ICON_FA_FOLDER;
|
||||
const std::string id = std::string("##") + directory->Name;
|
||||
|
||||
const ImVec2 size = { 80, 80 };
|
||||
const ImVec2 headerSize = { size.x, 50 };
|
||||
const ImVec2 totalSize = { size.x, size.y + headerSize.y };
|
||||
ImVec2 prevCursor = ImGui::GetCursorPos();
|
||||
ImVec2 prevScreenPos = ImGui::GetCursorScreenPos();
|
||||
const bool selected = ImGui::Selectable(id.c_str(), editorContext.GetSelection().Directory == directory, ImGuiSelectableFlags_AllowOverlap | ImGuiSelectableFlags_AllowDoubleClick, ImVec2(100, 150));
|
||||
const bool selected = ImGui::Selectable(id.c_str(), editorContext.GetSelection().Directory == directory, ImGuiSelectableFlags_AllowOverlap | ImGuiSelectableFlags_AllowDoubleClick, totalSize);
|
||||
const std::string hoverMenuId = std::string("item_hover_menu") + std::to_string(drawId);
|
||||
if (ImGui::IsItemHovered() && ImGui::IsMouseReleased(1))
|
||||
{
|
||||
@@ -351,23 +353,20 @@ void FileBrowserWidget::DrawDirectory(Ref<Nuake::Directory> directory, uint32_t
|
||||
{
|
||||
currentDirectory = directory;
|
||||
}
|
||||
|
||||
//Editor->Selection = EditorSelection(directory);
|
||||
}
|
||||
|
||||
if (ImGui::IsItemHovered())
|
||||
ImGui::SetTooltip(directory->Name.c_str());
|
||||
|
||||
|
||||
ImGui::SetCursorPos(prevCursor);
|
||||
ImGui::Image((ImTextureID)TextureManager::Get()->GetTexture2("Resources/Images/folder_icon.png")->GetImGuiDescriptorSet(), ImVec2(100, 100), {0, 1}, {1, 0});
|
||||
ImGui::Image((ImTextureID)TextureManager::Get()->GetTexture2("Resources/Images/folder_icon.png")->GetImGuiDescriptorSet(), size, {0, 1}, {1, 0});
|
||||
|
||||
auto imguiStyle = ImGui::GetStyle();
|
||||
|
||||
ImVec2 startOffset = ImVec2(imguiStyle.CellPadding.x / 2.0f, 0);
|
||||
ImVec2 offsetEnd = ImVec2(startOffset.x, imguiStyle.CellPadding.y / 2.0f);
|
||||
ImU32 rectColor = IM_COL32(255, 255, 255, 16);
|
||||
ImGui::GetWindowDrawList()->AddRectFilled(prevScreenPos + ImVec2(0, 100) - startOffset, prevScreenPos + ImVec2(100, 150) + offsetEnd, rectColor, 1.0f);
|
||||
ImGui::GetWindowDrawList()->AddRectFilled(prevScreenPos + ImVec2(0, size.x) - startOffset, prevScreenPos + totalSize + offsetEnd, rectColor, 1.0f);
|
||||
std::string visibleName = directory->Name;
|
||||
const uint32_t MAX_CHAR_NAME = 34;
|
||||
if (directory->Name.size() > MAX_CHAR_NAME)
|
||||
@@ -377,7 +376,7 @@ void FileBrowserWidget::DrawDirectory(Ref<Nuake::Directory> directory, uint32_t
|
||||
|
||||
ImGui::TextWrapped(visibleName.c_str());
|
||||
|
||||
ImGui::SetCursorPosY(prevCursor.y + 150 - ImGui::GetTextLineHeight());
|
||||
ImGui::SetCursorPosY(prevCursor.y + totalSize.y - ImGui::GetTextLineHeight());
|
||||
ImGui::TextColored({ 1, 1, 1, 0.5f }, "Folder");
|
||||
|
||||
ImGui::PopStyleVar();
|
||||
@@ -471,10 +470,14 @@ void FileBrowserWidget::DrawFile(Ref<Nuake::File> file, uint32_t drawId)
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, { 0.f, 0.f });
|
||||
std::string fileExtension = file->GetExtension();
|
||||
|
||||
const ImVec2 size = { 80, 80 };
|
||||
const ImVec2 headerSize = { size.x, 50 };
|
||||
const ImVec2 totalSize = { size.x, size.y + headerSize.y };
|
||||
|
||||
ImVec2 prevCursor = ImGui::GetCursorPos();
|
||||
ImVec2 prevScreenPos = ImGui::GetCursorScreenPos();
|
||||
std::string id = std::string("##") + file->GetAbsolutePath();
|
||||
const bool selected = ImGui::Selectable(id.c_str(), editorContext.GetSelection().File == file, ImGuiSelectableFlags_AllowOverlap | ImGuiSelectableFlags_AllowDoubleClick, ImVec2(100, 150));
|
||||
const bool selected = ImGui::Selectable(id.c_str(), editorContext.GetSelection().File == file, ImGuiSelectableFlags_AllowOverlap | ImGuiSelectableFlags_AllowDoubleClick, totalSize);
|
||||
|
||||
const std::string hoverMenuId = std::string("item_hover_menu") + std::to_string(drawId);
|
||||
if (ImGui::IsItemHovered() && ImGui::IsMouseReleased(1))
|
||||
@@ -643,7 +646,7 @@ void FileBrowserWidget::DrawFile(Ref<Nuake::File> file, uint32_t drawId)
|
||||
}
|
||||
|
||||
ImGui::SetCursorPos(prevCursor);
|
||||
ImGui::Image(reinterpret_cast<ImTextureID>(textureImage->GetImGuiDescriptorSet()), ImVec2(100, 100), { 0, 1 }, { 1, 0 });
|
||||
ImGui::Image(reinterpret_cast<ImTextureID>(textureImage->GetImGuiDescriptorSet()), size, { 0, 1 }, { 1, 0 });
|
||||
ImGui::PopStyleVar();
|
||||
|
||||
auto& imguiStyle = ImGui::GetStyle();
|
||||
@@ -651,11 +654,11 @@ void FileBrowserWidget::DrawFile(Ref<Nuake::File> file, uint32_t drawId)
|
||||
ImVec2 startOffset = ImVec2(imguiStyle.CellPadding.x / 2.0f, 0);
|
||||
ImVec2 offsetEnd = ImVec2(startOffset.x, imguiStyle.CellPadding.y / 2.0f);
|
||||
ImU32 rectColor = IM_COL32(255, 255, 255, 16);
|
||||
ImGui::GetWindowDrawList()->AddRectFilled(prevScreenPos + ImVec2(0, 100) - startOffset, prevScreenPos + ImVec2(100, 150) + offsetEnd, rectColor, 1.0f);
|
||||
ImGui::GetWindowDrawList()->AddRectFilled(prevScreenPos + ImVec2(0, 80) - startOffset, prevScreenPos + totalSize + offsetEnd, rectColor, 1.0f);
|
||||
|
||||
ImU32 rectColor2 = UI::PrimaryCol;
|
||||
Color fileTypeColor = GetColorByFileType(file->GetFileType());
|
||||
ImGui::GetWindowDrawList()->AddRectFilled(prevScreenPos + ImVec2(0, 100) - startOffset, prevScreenPos + ImVec2(100, 101) + offsetEnd, IM_COL32(fileTypeColor.r * 255.f, fileTypeColor.g * 255.f, fileTypeColor.b * 255.f, fileTypeColor.a * 255.f), 0.0f);
|
||||
ImGui::GetWindowDrawList()->AddRectFilled(prevScreenPos + ImVec2(0, 80) - startOffset, prevScreenPos + ImVec2(80, 101) + offsetEnd, IM_COL32(fileTypeColor.r * 255.f, fileTypeColor.g * 255.f, fileTypeColor.b * 255.f, fileTypeColor.a * 255.f), 0.0f);
|
||||
|
||||
std::string visibleName = file->GetName();
|
||||
const uint32_t MAX_CHAR_NAME = 32;
|
||||
@@ -666,7 +669,7 @@ void FileBrowserWidget::DrawFile(Ref<Nuake::File> file, uint32_t drawId)
|
||||
|
||||
ImGui::TextWrapped(visibleName.c_str());
|
||||
|
||||
ImGui::SetCursorPosY(prevCursor.y + 150 - ImGui::GetTextLineHeight());
|
||||
ImGui::SetCursorPosY(prevCursor.y + totalSize.y - ImGui::GetTextLineHeight());
|
||||
ImGui::TextColored({ 1, 1, 1, 0.5f }, file->GetFileTypeAsString().c_str());
|
||||
|
||||
//if (fileExtension == ".png" || fileExtension == ".jpg")
|
||||
|
||||
Reference in New Issue
Block a user