• Stars
    star
    651
  • Rank 69,175 (Top 2 %)
  • Language
    C++
  • License
    MIT License
  • Created over 5 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

File browser implementation for dear-imgui. C++17 is required.

imgui-filebrowser

imgui-filebrowser is a header-only file browser implementation for dear-imgui. C++ 17 is required.

IMG

Getting Started

imfilebrowser.h should be included after imgui.h:

#include <imgui.h>
#include <imfilebrowser.h>

Instead of creating a file dialog with an immediate function call, you need to create a ImGui::FileBrowser instance, open it with member function Open(), and call Display() in each frame. Here is a simple example:

#include <imgui.h>
#include <imfilebrowser.h>

int main()
{
    //...initialize rendering window and imgui
    
    // create a file browser instance
    ImGui::FileBrowser fileDialog;
    
    // (optional) set browser properties
    fileDialog.SetTitle("title");
    fileDialog.SetTypeFilters({ ".h", ".cpp" });
    
    // mainloop
    while(continueRendering)
    {
        //...do other stuff like ImGui::NewFrame();
        
        if(ImGui::Begin("dummy window"))
        {
            // open file dialog when user clicks this button
            if(ImGui::Button("open file dialog"))
                fileDialog.Open();
        }
        ImGui::End();
        
        fileDialog.Display();
        
        if(fileDialog.HasSelected())
        {
            std::cout << "Selected filename" << fileDialog.GetSelected().string() << std::endl;
            fileDialog.ClearSelected();
        }
        
        //...do other stuff like ImGui::Render();
    }
    
    //...shutdown
}

Options

Various options can be combined with '|' and passed to the constructor:

enum ImGuiFileBrowserFlags_
{
    ImGuiFileBrowserFlags_SelectDirectory   = 1 << 0, // select directory instead of regular file
    ImGuiFileBrowserFlags_EnterNewFilename  = 1 << 1, // allow user to enter new filename when selecting regular file
    ImGuiFileBrowserFlags_NoModal           = 1 << 2, // file browsing window is modal by default. specify this to use a popup window
    ImGuiFileBrowserFlags_NoTitleBar        = 1 << 3, // hide window title bar
    ImGuiFileBrowserFlags_NoStatusBar       = 1 << 4, // hide status bar at the bottom of browsing window
    ImGuiFileBrowserFlags_CloseOnEsc        = 1 << 5, // close file browser when pressing 'ESC'
    ImGuiFileBrowserFlags_CreateNewDir      = 1 << 6, // allow user to create new directory
    ImGuiFileBrowserFlags_MultipleSelection = 1 << 7, // allow user to select multiple files. this will hide ImGuiFileBrowserFlags_EnterNewFilename
};

When ImGuiFileBrowserFlags_MultipleSelection is enabled, use fileBrowser.GetMultiSelected() to get all selected filenames (instead of fileBrowser.GetSelected(), which returns only one of them).

Here are some common examples:

// select single regular file for opening
0
// select multiple regular files for opening
ImGuiFileBrowserFlags_MultipleSelection
// select single directory for opening
ImGuiFileBrowserFlags_SelectDirectory
// select multiple directories for opening
ImGuiFileBrowserFlags_SelectDirectory | ImGuiFileBrowserFlags_MultipleSelection
// select single regular file for saving
ImGuiFileBrowserFlags_EnterNewFilename | ImGuiFileBrowserFlags_CreateNewDir
// select single directory for saving
ImGuiFileBrowserFlags_SelectDirectory | ImGuiFileBrowserFlags_CreateNewDir

Usage

  • double click to enter a directory
  • single click to (de)select a regular file (or directory, when ImGuiFileBrowserFlags_SelectDirectory is enabled)
  • When ImGuiFileBrowserFlags_SelectDirectory is enabled and no directory is selected, click ok to choose the current directory as selected result
  • When ImGuiFileBrowserFlags_MultipleSelection is enabled, hold Shift or Ctrl to select more than one file
  • When ImGuiFileBrowserFlags_CreateNewDir is enabled, click the top-right little button "+" to create a new directory
  • When ImGuiFileBrowserFlags_SelectDirectory is not specified, double click to choose a regular file as selected result.

Type Filters

  • (optionally) use browser.SetTypeFilters({".h", ".cpp"}) to set file extension filters.
  • ".*" matches with any extension
  • filters are case-insensitive on Windows platform

Note

The filebrowser implementation queries drive list via Win32 API (only on Windows). Thus <Windows.h> is included in <imfilebrowser.h>, which may pollute the global namespace. This can be solved by simply moving the GetDrivesBitMask() definition into a cpp file.

More Repositories

1

Atrc

My path tracer
C++
519
star
2

AtmosphereRenderer

A C++/DirectX 11 implementation of "A Scalable and Production Ready Sky and Atmosphere Rendering Technique"
C++
68
star
3

GAMES202

用C++和DirectX 11实现的GAMES202作业
C++
64
star
4

SDFGenerator

GPU 3D SDF generator using DirectX 11 compute shader
C++
57
star
5

Btrc

Experimental GPU renderer using two-stage programming
C
33
star
6

cuj

Run-time program generator embedded in C++
C++
28
star
7

Rtrc

Graphics toolkits
C++
22
star
8

PaperCutLight

Paper cut light box previewer
C++
14
star
9

CatmullClarkSubdivision

Catmull-Clark网格细分算法
C++
13
star
10

Utils

Header-only C++ utility tools for self using. C++17 required.
C++
12
star
11

D3D11-SMAA

My DirectX 11 MLAA & SMAA implementation
C++
11
star
12

agz-utils

C++17 utility tools for computer graphics
C
10
star
13

VoxelWorld

A simple simulator of minecraft-style world
C++
10
star
14

ImageQuilting

C++ implementation of example-based texture synthesis algorithm in paper "Image Quilting for Texture Synthesis and Transfer".
C++
9
star
15

DirectX12Lab

My DirectX 12 playground
C++
8
star
16

D3D11-Volume

My personal physically-based volume rendering lab on GPU
C++
8
star
17

vkpt

My Vulkan abstraction layer (WIP)
C++
8
star
18

CompilerCourse_UESTC

编译原理实验代码
C++
6
star
19

EfficientShading

My real-time rendering pipeline playground based on DirectX 12
C++
5
star
20

AGZParserGen

Flexible parser generator
C++
2
star
21

cpp-member-function-trait

Trait classes for C++ member function pointer types
C++
2
star
22

AirGuanZ.github.io

个人主页,菜鸟建设中
HTML
1
star
23

OWE

对DirectX11着色器的简单封装
C++
1
star
24

VRPG

C++
1
star
25

EulerOperation

C++
1
star
26

GCTS

C++ implementation of example-based texture synthesis algo in paper "Graphcut Textures: Image and Video Synthesis Using Graph Cuts"
C++
1
star