mirror of
https://github.com/bkaradzic/bgfx.git
synced 2026-02-18 04:53:06 +01:00
Added basic file list ImGui widget.
This commit is contained in:
1
3rdparty/ocornut-imgui/imgui_user.h
vendored
1
3rdparty/ocornut-imgui/imgui_user.h
vendored
@@ -15,4 +15,5 @@ namespace ImGui
|
||||
|
||||
} // namespace ImGui
|
||||
|
||||
#include "widgets/file_list.h"
|
||||
#include "widgets/memory_editor.h"
|
||||
|
||||
1
3rdparty/ocornut-imgui/imgui_user.inl
vendored
1
3rdparty/ocornut-imgui/imgui_user.inl
vendored
@@ -1 +1,2 @@
|
||||
#include "widgets/file_list.inl"
|
||||
#include "widgets/memory_editor.inl"
|
||||
|
||||
30
3rdparty/ocornut-imgui/widgets/file_list.h
vendored
Normal file
30
3rdparty/ocornut-imgui/widgets/file_list.h
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
#include <stdint.h>
|
||||
|
||||
namespace ImGui
|
||||
{
|
||||
struct ImFileInfo
|
||||
{
|
||||
ImFileInfo(const char* name, int64_t size);
|
||||
~ImFileInfo();
|
||||
ImFileInfo& operator=(const ImFileInfo& rhs);
|
||||
|
||||
char* Name;
|
||||
int64_t Size;
|
||||
};
|
||||
|
||||
struct ImFileList
|
||||
{
|
||||
ImVector<ImFileInfo> FileList;
|
||||
int Pos;
|
||||
|
||||
ImFileList(const char* path = ".")
|
||||
: Pos(0)
|
||||
{
|
||||
ChDir(path);
|
||||
}
|
||||
|
||||
void ChDir(const char* path);
|
||||
void Draw();
|
||||
};
|
||||
|
||||
} // namespace ImGui
|
||||
135
3rdparty/ocornut-imgui/widgets/file_list.inl
vendored
Normal file
135
3rdparty/ocornut-imgui/widgets/file_list.inl
vendored
Normal file
@@ -0,0 +1,135 @@
|
||||
#include <dirent.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
namespace ImGui
|
||||
{
|
||||
ImFileInfo::ImFileInfo(const char* name, int64_t size)
|
||||
{
|
||||
Name = ImStrdup(name);
|
||||
Size = size;
|
||||
}
|
||||
|
||||
ImFileInfo::~ImFileInfo()
|
||||
{
|
||||
MemFree(Name);
|
||||
Name = NULL;
|
||||
}
|
||||
|
||||
ImFileInfo& ImFileInfo::operator=(const ImFileInfo& rhs)
|
||||
{
|
||||
if (this != &rhs)
|
||||
{
|
||||
Name = ImStrdup(rhs.Name);
|
||||
Size = rhs.Size;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void ImFileList::ChDir(const char* path)
|
||||
{
|
||||
DIR* dir = opendir(path);
|
||||
if (NULL != dir)
|
||||
{
|
||||
FileList.clear();
|
||||
|
||||
for (dirent* item = readdir(dir); NULL != item; item = readdir(dir) )
|
||||
{
|
||||
if (0 == ImStricmp(item->d_name, "..") )
|
||||
{
|
||||
FileList.push_back(ImFileInfo(item->d_name, -1) );
|
||||
}
|
||||
else if (0 != ImStricmp(item->d_name, ".") )
|
||||
{
|
||||
if (item->d_type & DT_DIR)
|
||||
{
|
||||
FileList.push_back(ImFileInfo(item->d_name, -1) );
|
||||
}
|
||||
else
|
||||
{
|
||||
struct stat statbuf;
|
||||
stat(item->d_name, &statbuf);
|
||||
FileList.push_back(ImFileInfo(item->d_name, statbuf.st_size) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
closedir(dir);
|
||||
}
|
||||
}
|
||||
|
||||
void ImFileList::Draw()
|
||||
{
|
||||
BeginChild("##file_list", ImVec2(0.0f, 0.0f) );
|
||||
PushFont(Font::Mono);
|
||||
|
||||
PushItemWidth(-1);
|
||||
if (ListBoxHeader("##empty", ImVec2(0.0f, 0.0f) ) )
|
||||
{
|
||||
const float lineHeight = GetTextLineHeightWithSpacing();
|
||||
|
||||
char* chdir = NULL;
|
||||
|
||||
int pos = 0;
|
||||
ImGuiListClipper clipper(FileList.size(), lineHeight);
|
||||
for (ImVector<ImFileInfo>::const_iterator it = FileList.begin(), itEnd = FileList.end()
|
||||
; it != itEnd
|
||||
; ++it
|
||||
)
|
||||
{
|
||||
if (pos >= clipper.DisplayStart
|
||||
&& pos < clipper.DisplayEnd)
|
||||
{
|
||||
PushID(pos);
|
||||
|
||||
const bool isDir = -1 == it->Size;
|
||||
bool isSelected = Pos == pos;
|
||||
|
||||
bool clicked = Selectable(it->Name, &isSelected, 0, ImVec2(150.0f, 0.0f) );
|
||||
SameLine();
|
||||
if (isDir)
|
||||
{
|
||||
Text("%10s", "<DIR>");
|
||||
}
|
||||
else
|
||||
{
|
||||
Text("%10d", it->Size);
|
||||
}
|
||||
|
||||
if (clicked)
|
||||
{
|
||||
if (0 == ImStricmp(it->Name, "..") )
|
||||
{
|
||||
MemFree(chdir);
|
||||
chdir = ImStrdup(it->Name);
|
||||
}
|
||||
|
||||
Pos = pos;
|
||||
|
||||
if (isDir)
|
||||
{
|
||||
MemFree(chdir);
|
||||
chdir = ImStrdup(it->Name);
|
||||
}
|
||||
}
|
||||
|
||||
PopID();
|
||||
}
|
||||
++pos;
|
||||
}
|
||||
clipper.End();
|
||||
|
||||
ListBoxFooter();
|
||||
|
||||
if (NULL != chdir)
|
||||
{
|
||||
ChDir(chdir);
|
||||
MemFree(chdir);
|
||||
}
|
||||
}
|
||||
|
||||
PopFont();
|
||||
EndChild();
|
||||
}
|
||||
|
||||
} // namespace ImGui
|
||||
Reference in New Issue
Block a user