feat: 添加Project面板拖拽功能
This commit is contained in:
@@ -16,6 +16,13 @@ void ProjectPanel::Initialize(const std::string& projectPath) {
|
||||
}
|
||||
|
||||
void ProjectPanel::Render() {
|
||||
const ImGuiPayload* payload = ImGui::GetDragDropPayload();
|
||||
if (payload && payload->IsDataType(DRAG_DROP_TYPE)) {
|
||||
m_draggingPath = (const char*)payload->Data;
|
||||
} else if (!ImGui::IsMouseDown(0)) {
|
||||
m_draggingPath.clear();
|
||||
}
|
||||
|
||||
ImGui::Begin(m_name.c_str(), nullptr, ImGuiWindowFlags_None);
|
||||
|
||||
auto& manager = ProjectManager::Get();
|
||||
@@ -74,6 +81,10 @@ void ProjectPanel::Render() {
|
||||
|
||||
ImGui::PopStyleVar();
|
||||
|
||||
if (ImGui::IsWindowHovered() && ImGui::IsMouseClicked(0) && !ImGui::IsAnyItemHovered()) {
|
||||
manager.SetSelectedIndex(-1);
|
||||
}
|
||||
|
||||
if (ImGui::BeginPopup("ItemContextMenu")) {
|
||||
if (m_contextMenuIndex >= 0 && m_contextMenuIndex < (int)items.size()) {
|
||||
auto& item = items[m_contextMenuIndex];
|
||||
@@ -137,6 +148,9 @@ void ProjectPanel::RenderAssetItem(const AssetItemPtr& item, int index) {
|
||||
|
||||
if (isSelected) {
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.40f, 0.40f, 0.40f, 0.50f));
|
||||
} else {
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0, 0, 0, 0));
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.30f, 0.30f, 0.30f, 0.40f));
|
||||
}
|
||||
|
||||
ImVec2 buttonSize(80.0f, 90.0f);
|
||||
@@ -159,11 +173,18 @@ void ProjectPanel::RenderAssetItem(const AssetItemPtr& item, int index) {
|
||||
|
||||
if (isSelected) {
|
||||
ImGui::PopStyleColor();
|
||||
} else {
|
||||
ImGui::PopStyleColor(2);
|
||||
}
|
||||
|
||||
ImVec2 min = ImGui::GetItemRectMin();
|
||||
ImVec2 max = ImVec2(min.x + buttonSize.x, min.y + buttonSize.y);
|
||||
ImDrawList* drawList = ImGui::GetWindowDrawList();
|
||||
|
||||
if (!m_draggingPath.empty() && item->fullPath == m_draggingPath) {
|
||||
drawList->AddRectFilled(min, max, IM_COL32(0, 0, 0, 60), 0.0f);
|
||||
}
|
||||
|
||||
ImU32 iconColor;
|
||||
if (item->isFolder) {
|
||||
iconColor = IM_COL32(200, 180, 100, 255);
|
||||
|
||||
@@ -20,6 +20,7 @@ private:
|
||||
bool m_showCreateFolderPopup = false;
|
||||
char m_newFolderName[256] = "NewFolder";
|
||||
int m_contextMenuIndex = -1;
|
||||
std::string m_draggingPath;
|
||||
};
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user