adding materials, adding serialization for meshes and materials, random fixes
This commit is contained in:
28
editor/src/panels/content_browser.cpp
Normal file → Executable file
28
editor/src/panels/content_browser.cpp
Normal file → Executable file
@@ -15,8 +15,9 @@ namespace OpenEngine {
|
||||
ContentBrowserPanel::ContentBrowserPanel()
|
||||
: current_directory(assets_directory)
|
||||
{
|
||||
// TODO: Add file texture. Get free icons and add license
|
||||
folder_icon = Texture2D::Create("resources/textures/icons/folder.png");
|
||||
// TODO: Add license
|
||||
folder_icon = Texture2D::Create("resources/textures/icons/folder2.png");
|
||||
file_icon = Texture2D::Create("resources/textures/icons/file.png");
|
||||
}
|
||||
|
||||
void ContentBrowserPanel::OnImGuiRender()
|
||||
@@ -30,6 +31,16 @@ namespace OpenEngine {
|
||||
current_directory = current_directory.parent_path();
|
||||
|
||||
auto directory_it = std::filesystem::directory_iterator(current_directory);
|
||||
std::vector<std::filesystem::directory_entry> entries;
|
||||
|
||||
for (auto entry : directory_it)
|
||||
entries.emplace_back(entry);
|
||||
|
||||
std::sort(entries.begin(), entries.end(),
|
||||
[](const std::filesystem::directory_entry& a,
|
||||
const std::filesystem::directory_entry& b) {
|
||||
return (a.is_directory() && !b.is_directory());
|
||||
});
|
||||
|
||||
ImVec2 button_size = { 100, 100 };
|
||||
auto panel_width = ImGui::GetContentRegionAvail().x;
|
||||
@@ -42,9 +53,12 @@ namespace OpenEngine {
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, padding);
|
||||
|
||||
float margin = 20.0f;
|
||||
ImGui::Indent(margin);
|
||||
|
||||
if (ImGui::BeginTable("table1", table_columns, ImGuiTableFlags_SizingFixedSame))
|
||||
{
|
||||
for (auto& entry : directory_it) {
|
||||
for (auto& entry : entries) {
|
||||
auto file_name = entry.path().filename().string();
|
||||
|
||||
ImGui::PushID(file_name.c_str());
|
||||
@@ -56,17 +70,14 @@ namespace OpenEngine {
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, { 0.270f, 0.278f, 0.352f, 1.0f });
|
||||
|
||||
ImGui::BeginGroup();
|
||||
ImGui::ImageButton("##X", (ImTextureID)folder_icon->GetID(), button_size, { 0, 1 }, { 1, 0 });
|
||||
Ref<Texture2D> icon = entry.is_directory() ? folder_icon : file_icon;
|
||||
ImGui::ImageButton("##X", (ImTextureID)icon->GetID(), button_size, { 0, 1 }, { 1, 0 });
|
||||
if (entry.is_regular_file() && ImGui::BeginDragDropSource()) {
|
||||
const char* source = entry.path().c_str();
|
||||
ImGui::SetDragDropPayload("CONTENT_BROWSER_PAYLOAD", source, (strlen(source) + 1) * sizeof(char), ImGuiCond_Once);
|
||||
|
||||
ImGui::EndDragDropSource();
|
||||
}
|
||||
|
||||
float columnWidth = ImGui::GetColumnWidth();
|
||||
float textWidth = ImGui::CalcTextSize(file_name.c_str()).x;
|
||||
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + (columnWidth - textWidth) * 0.5f);
|
||||
ImGui::TextWrapped("%s", file_name.c_str());
|
||||
|
||||
ImGui::EndGroup();
|
||||
@@ -81,6 +92,7 @@ namespace OpenEngine {
|
||||
}
|
||||
ImGui::EndTable();
|
||||
}
|
||||
ImGui::Unindent();
|
||||
ImGui::PopStyleVar();
|
||||
|
||||
ImGui::End();
|
||||
|
||||
Reference in New Issue
Block a user