Thanks to visit codestin.com
Credit goes to github.com

Skip to content

samuelvenable/ImFileDialog

 
 

Repository files navigation

ImFileDialog

A simple file dialog library for Dear ImGui.

This library supports favorites, default native icon theme, image previews, zooming in, etc.

Usage

Here's an example on how to use ImFileDialog:

  1. You need to set the CreateTexture and DeleteTexture function
ifd::FileDialog::Instance().CreateTexture = [](uint8_t *data, int w, int h, char fmt) -> void * {
  GLuint tex = 0;
  glGenTextures(1, &tex);
  glBindTexture(GL_TEXTURE_2D, tex);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, (fmt == 0) ? GL_BGRA : GL_RGBA, GL_UNSIGNED_BYTE, data);
  glGenerateMipmap(GL_TEXTURE_2D);
  glBindTexture(GL_TEXTURE_2D, 0);
  return (void *)(uintptr_t)tex;
};
ifd::FileDialog::Instance().DeleteTexture = [](void *tex) {
  GLuint texID = (GLuint)(uintptr_t)tex;
  glDeleteTextures(1, &texID);
};
  1. Open a file dialog on button press (just an example):
if (ImGui::Button("Open a texture"))
  ifd::FileDialog::Instance().Open("TextureOpenDialog", "Open a texture", "Image file (*.png;*.jpg;*.jpeg;*.bmp;*.tga){.png,.jpg,.jpeg,.bmp,.tga},.*");
  1. Render and check if done:
if (ifd::FileDialog::Instance().IsDone("TextureOpenDialog")) {
  if (ifd::FileDialog::Instance().HasResult()) {
    std::string res = ifd::FileDialog::Instance().GetResult().u8string();
    printf("OPEN[%s]\n", res.c_str());
  }
  ifd::FileDialog::Instance().Close();
}

File filter syntax:

Name1 {.ext1,.ext2}, Name2 {.ext3,.ext4},.*

Running the example

If you want to test ImFileDialog, run these commands:

cmake .
make
./ImFileDialogExample

Screenshots

1. Table view:

Table view

2. Icon view:

Icon view

3. Zooming in:

Zooming in

4. Favorites:

Favorites

5. Image preview + threading (CTRL + scroll):

Table view

LICENSE

ImFileDialog is licensed under MIT license. See LICENSE for more details.

About

A file dialog library for Dear ImGui

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • C++ 81.0%
  • C 18.7%
  • Other 0.3%