Addon widgets for GUI library Dear ImGui.

Related tags

GUI ImGui-Addons
Overview

BUILD STATUS

ImGui-Addons

Addon widgets for GUI library Dear ImGui.

File Dialog

A simple cross-platform file dialog that uses dirent interface for reading directories and files. It's present as a standard header file in Unix based systems afaik and is also contained in some compilers like MinGW but I have decided to use Toni Rönkkö's ported version so atleast the code remains compiler independent. Both Open and Save file dialogs are supported. C++11 is required.

Code uses ported dirent.h provided by Toni on Windows and on UNIX code uses standard dirent.h header, but unfortunately the code hasn't been checked extensively on UNIX based systems especially MacOS. So if someone finds problems on other platforms do tell me or submit a pull request. Also I don't think the code will work with Unicode paths containing language specific or other special characters as I blatantly use normal char* and std::string everywhere. The ported dirent.h for Windows uses wcstombs function to convert widechars to multibyte sequences but according to the docs this also fails if a wide character that doesnt' correspond to a valid Mulitbyte char is encountered. Anyways Not an expert at this topic so you may find errors if your paths contain special characters outside the normal 0-255 range.

Thanks to @Sandy, the code was tested on linux and runs fine except except that double clicks don't work all the time. This might be due to problems in ImGui itself or a problem on a specific computer only. So if anybody else encounters any issues do tell me.

Usage

Make sure all the imgui files are accessible as imgui.h and so on without specifying the folder they are in. You must mention the path to the folder they are in, in your IDE. Also make sure dirent.h is accessible as Dirent/dirent.h. If you don't like these include paths, you can change how ImGuiFileBrowser.h and the corresponding cpp file accesses these yourself. Now include ImGuiFileBrowser.h and use it like this..

..
imgui_addons::ImGuiFileBrowser file_dialog; // As a class member or globally

// Now inside any function
void showMainMenu()
{
    bool open = false, save = false;
    if(ImGui::BeginMainMenuBar())
    {
        if (ImGui::BeginMenu("Menu"))
        {
            if (ImGui::MenuItem("Open", NULL))
                open = true;
        if (ImGui::MenuItem("Save", NULL))
                save = true;
            
        ImGui::EndMenu();
        }
        ImGui::EndMainMenuBar();
    }
    
    //Remember the name to ImGui::OpenPopup() and showFileDialog() must be same...
    if(open)
        ImGui::OpenPopup("Open File");
    if(save)
        ImGui::OpenPopup("Save File");
        
    /* Optional third parameter. Support opening only compressed rar/zip files. 
     * Opening any other file will show error, return false and won't close the dialog.
     */
    if(file_dialog.showFileDialog("Open File", imgui_addons::ImGuiFileBrowser::DialogMode::OPEN, ImVec2(700, 310), ".rar,.zip,.7z"))
    {
        std::cout << file_dialog.selected_fn << std::endl;      // The name of the selected file or directory in case of Select Directory dialog mode
        std::cout << file_dialog.selected_path << std::endl;    // The absolute path to the selected file
    }
    if(file_dialog.showFileDialog("Save File", imgui_addons::ImGuiFileBrowser::DialogMode::SAVE, ImVec2(700, 310), ".png,.jpg,.bmp"))
    {
        std::cout << file_dialog.selected_fn << std::endl;      // The name of the selected file or directory in case of Select Directory dialog mode
        std::cout << file_dialog.selected_path << std::endl;    // The absolute path to the selected file
        std::cout << file_dialog.ext << std::endl;              // Access ext separately (For SAVE mode)
        //Do writing of files based on extension here
    }
}

Note that the Save file dialog just stores whatever name the user types in selected_fn The user may try to save with a different extension than one already selected in the extension box This is upto the programmer, whether to use the extension selected in the UI or the one typed in the file name by the user. I've also added the modified imgui_demo.cpp to include the file dialog in the menu bar so you can check how it's working there.

Enough chitchat, here's a gif in-action, click for full video (I hope you guys don't consider me a weeb after seeing the screensavers collection xD )

Demo

Update

So the file dialog has been revamped to closely resemble the Windows file dialog. I've tried my best, and I'm happy with the results. Some internal workings have changed so gonna highlight them here.

  • 3 Different modes are supported currently. OPEN for opening files, SAVE for saving files an SELECT for selecting a directory.
  • There is only a single function call now showFileDialog(). A DialogMode enum is exposed (with values defined above) publicly which allows switching between different modes.
  • The selected file/folder name and the absolute path can be accessed separately through selected_fn and selected_path respectively.
Comments
  • Testing on Linux

    Testing on Linux

    I tested compiling on Linux and this is what I found.

    My system (Arch Linux) does not supply d_namlen or define _DIRENT_HAVE_D_NAMLEN. There are a few windows-specific calls used:

    • GetLogicalDriveStringsA
    • GetLogicalDriveStringsA
    • GetDriveTypeA

    Here are the errors. (warnings ommited)

    $ clang++ -c FileBrowser/ImGuiFileBrowser.cpp -I imgui -o ImGuiFileBrowser.cpp 
    FileBrowser/ImGuiFileBrowser.cpp:306:51: error: no member named 'd_namlen' in 'dirent'; did you mean 'd_reclen'?
                    if((ent->d_name[0] == '.' && ent->d_namlen == 1))
                                                      ^~~~~~~~
                                                      d_reclen
    /usr/include/bits/dirent.h:31:24: note: 'd_reclen' declared here
        unsigned short int d_reclen;
                           ^
    FileBrowser/ImGuiFileBrowser.cpp:308:28: error: no member named 'd_namlen' in 'dirent'; did you mean 'd_reclen'?
                    if( !(ent->d_namlen == 2 && ent->d_name[0] == '.' && ent->d_name[1] == '.') )
                               ^~~~~~~~
                               d_reclen
    /usr/include/bits/dirent.h:31:24: note: 'd_reclen' declared here
        unsigned short int d_reclen;
                           ^
    FileBrowser/ImGuiFileBrowser.cpp:319:55: error: no member named 'd_namlen' in 'dirent'; did you mean 'd_reclen'?
                        if((ent->d_name[0] == '.' && ent->d_namlen > 1))
                                                          ^~~~~~~~
                                                          d_reclen
    /usr/include/bits/dirent.h:31:24: note: 'd_reclen' declared here
        unsigned short int d_reclen;
                           ^
    FileBrowser/ImGuiFileBrowser.cpp:361:9: error: unknown type name 'DWORD'
            DWORD len = GetLogicalDriveStringsA(0,NULL);
            ^
    FileBrowser/ImGuiFileBrowser.cpp:361:21: error: use of undeclared identifier 'GetLogicalDriveStringsA'
            DWORD len = GetLogicalDriveStringsA(0,NULL);
                        ^
    FileBrowser/ImGuiFileBrowser.cpp:370:16: error: use of undeclared identifier 'DRIVE_REMOVABLE'
                if(DRIVE_REMOVABLE == GetDriveTypeA(drv))
                   ^
    FileBrowser/ImGuiFileBrowser.cpp:370:35: error: use of undeclared identifier 'GetDriveTypeA'
                if(DRIVE_REMOVABLE == GetDriveTypeA(drv))
                                      ^
    FileBrowser/ImGuiFileBrowser.cpp:372:21: error: use of undeclared identifier 'DRIVE_FIXED'
                else if(DRIVE_FIXED == GetDriveTypeA(drv))
                        ^
    FileBrowser/ImGuiFileBrowser.cpp:372:36: error: use of undeclared identifier 'GetDriveTypeA'
                else if(DRIVE_FIXED == GetDriveTypeA(drv))
                                       ^
    2 warnings and 9 errors generated.
    
    opened by bwrsandman 8
  • Please don't force imgui into a subdirectory

    Please don't force imgui into a subdirectory

    https://github.com/gallickgunner/ImGui-Addons/blob/f7b72fbdc62c73fb132fb6ddd2c6895b61a1f6bb/FileBrowser/ImGuiFileBrowser.h#L4

    imgui.h lives in the root of the imgui file structure.

    Rather specify the include dir through the build system.

    opened by sphaero 7
  • Is there a way to only display a browser for a single directory?

    Is there a way to only display a browser for a single directory?

    I'm working on a game engine, and I'm already using this file browser to open and save projects and scenes. However, I'd also like to use it for selecting sprites, scripts, etc, but they are only in the Assets folder, so how could I modify it to only search in the Assets folder?

    opened by quou 6
  • Filter Alignment issue (20/02/12 version)

    Filter Alignment issue (20/02/12 version)

    Hi ,

    I'm using the extension on Windows , and I get this opening the file dialog : filebrowserproblem As you can see there's a small alignment problem of the filter that is behind the file list. Anyway thanks for your work ! Until now it's the best file browser for imgui windows users :)

    opened by SadE54 6
  • enum value changed

    enum value changed

    Thanks for sharing your code. I think ImGuiSelectableFlags_PressedOnClick is obsolete (and does not compile with the latest version of ImGUI) and I replaced it with ImGuiSelectableFlags_SelectOnClick but I am not 100% sure.

    Bests Roberto

    opened by robertogrossi 5
  • Min Max macros in Windows (again)

    Min Max macros in Windows (again)

    Not sure what change made this happen but I can't build on Windows anymore with imgui 1.85.

    C:\projects\gazebosc-sphaero\ext\ImGui-Addons\FileBrowser\ImGuiFileBrowser.cpp(121,46): error C2589: '(': illegal token on right side of '::' [C:\projects\gazebosc-sphaero\build\gazebosc.vcxproj]
    C:\projects\gazebosc-sphaero\ext\ImGui-Addons\FileBrowser\ImGuiFileBrowser.cpp(121): error C2144: syntax error: 'unknown-type' should be preceded by ')' [C:\projects\gazebosc-sphaero\build\gazebosc.vcxproj]
    

    Very much related to #7

    I think it can also be fixed by using std::max<float> instead of std::max etc

    However it's just a workaround.

    opened by sphaero 3
  • ImGuiSelectableFlags_PressedOnClick becomes ImGuiSelectableFlags_SelectOnClick ?

    ImGuiSelectableFlags_PressedOnClick becomes ImGuiSelectableFlags_SelectOnClick ?

    Hi there, first, a big thx for this addon to Imgui. Then it seems that there has been a litle change in Imgui, so that your file does not compile anymore with Imgui 1.77. In imgui_internal.h it seems that ImGuiSelectableFlags_PressedOnClick becomes ImGuiSelectableFlags_SelectOnClick . So you have to change accordingly you ImguiFileBrowser.ccp , line 615 . I suppose that this line was in relation with the file filter combobox that seems to work ok.

    opened by DaveInDev 3
  • Invalid new path if clicking on folder that has same name as a parent or contains part of a parent's name

    Invalid new path if clicking on folder that has same name as a parent or contains part of a parent's name

    Here's a simple fix I made. I haven't tested it thoroughly but it seems to have fix the bug.

    - new_path = current_path.substr(0, current_path.find("/" + current_dirlist[idx]) + current_dirlist[idx].length() + 2 );
    + {
    +     new_path = "";
    +     for (auto iter = current_dirlist.begin() + 1; iter != current_dirlist.begin() + idx + 1; ++iter)
    +         new_path += *iter + "/";
    + }
    

    Since there was two folders with the same name in the path, if you navigate to the deepest one by clicking on it the current_path.find is going to find the first folder instead.

    Example: C:/a/path/to/a/folder

    Clicking on the second folder "a" is going to cause the bug. In this case the path is still valid.

    Example: C:/app/path/to/a/folder

    In that case the new path would be "C:/ap" which does not exist.

    opened by PhilippeMarcotte 2
  • SELECT folder option

    SELECT folder option

    It would be great for the SELECT folder option to specify also a file filter, so as to get also the list of those filenames contained in the selected folder. Something like this:

    file_dialog.showFileDialog("Select Directory##popup", imgui_addons::ImGuiFileBrowser::DialogMode::SELECT, ImVec2(500,300), ".zip,.tgz", &filelist)

    Thanks -R

    opened by robertogrossi 2
  • validateFile extension bug

    validateFile extension bug

    Hi, i've found a small bug inside the bool validateFile() function, file ImGuiFileBrowser.cpp, line 1055:

    std::string file_ext = idx == std::string::npos ? "" : selected_fn.substr(idx, selected_fn.length() - idx);
    

    is returning ".ext"

    while in needed the extension without the dot to correctly check, "ext"

    so idx+1, in the substring extraction, fix the issue:

    std::string file_ext = idx == std::string::npos ? "" : selected_fn.substr(idx+1, selected_fn.length() - idx);
    
    opened by d3cod3 2
  • Improvements

    Improvements

    I started to play with the extension but I can see several improvement that could be made. It(s just my point , so it could differs from one to another :)

    Here's a Windows 10 file dialog : filebrowser2

    The allowed extensions are displayed in a list at the right of the filter in a list after the name filter. So the names that don't corresponding to the extension pattern are not displayed , so not selectable.

    Moreover, adding the classical jokers like '*' to the filter could be an improvement, at least for windows users :)

    Finally it should be possible to pass a filename as a string to open the save dialog , to allow acting as a 'save as' with a already existing file

    opened by SadE54 2
Releases(v2.0)
  • v2.0(Mar 13, 2020)

    Revamped File Dialog to closely resemble Windows one.

    Changelog

    • 3 Different modes are supported currently. OPEN for opening files, SAVE for saving files an SELECT for selecting a directory.
    • There is only a single function call now showFileDialog(). A DialogMode enum is exposed (with values defined above) publicly which allows switching between different modes.
    • The selected file/folder name and the absolute path can be accessed separately through selected_fn and selected_path respectively.
    Source code(tar.gz)
    Source code(zip)
  • v1.0(Mar 13, 2020)

Owner
A CS graduate amused by Computer Graphics, Mathematics and GPU Programming. I mostly work together with @jabberw0ky on personal projects.
null
An addon of imgui for supporting docks in the imgui's window

An addon of imgui for support dock in the window

BB 207 Nov 29, 2022
Real-time GUI layout creator/editor for Dear ImGui

ImStudio Real-time GUI layout creator/editor for Dear ImGui Inspired by Code-Building/ImGuiBuilder Features Drag edit Property edit Covers most of the

null 303 Jan 9, 2023
imgui-filebrowser is a header-only 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. Getting Started imfilebrowser.h s

Z Guan 435 Jan 1, 2023
This is a thin c-api wrapper programmatically generated for the excellent C++ immediate mode gui Dear ImGui.

cimgui This is a thin c-api wrapper programmatically generated for the excellent C++ immediate mode gui Dear ImGui. All imgui.h functions are programm

Victor Bombi 22 Jul 5, 2021
Window and GUI system based on Dear ImGui from OCornut

ImWindow Window and GUI system based on ImGui from OCornut. Include docking/floating window, multi window and multi render support. Platform Actually

Thibault Hennequin 715 Dec 20, 2022
A permissively licensed markdown single-header library for Dear ImGui.

Support development of imgui_markdown through GitHub Sponsors or Patreon imgui_markdown Markdown For Dear ImGui A permissively licensed markdown singl

Juliette Foucaut 853 Jan 8, 2023
Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies

Dear ImGui (This library is available under a free and permissive license, but needs financial support to sustain its continued improvements. In addit

omar 44.5k Jan 7, 2023
Advanced 2D Plotting for Dear ImGui

ImPlot ImPlot is an immediate mode, GPU accelerated plotting library for Dear ImGui. It aims to provide a first-class API that ImGui fans will love. I

Evan Pezent 2.9k Jan 9, 2023
Dear ImGui prototyping wrapper.

LabImGui Prototyping framework LabImGui wraps up creating a window, GL bindings, and a full screen docking set up with ImGui so that all of the boiler

Nick Porcino 1 Dec 5, 2022
An integrated information center created with dear ImGui using modern C++ design / coding style.

ImGui info-center Introduction An integrated notification and information center created with dear ImGui. Interfaces and variables are designed under

Feej 7 Oct 29, 2022
This is a software renderer for Dear ImGui. I built it not out of a specific need, but because it was fun

Dear ImGui software renderer This is a software renderer for Dear ImGui. I built it not out of a specific need, but because it was fun. The goal was t

Emil Ernerfeldt 214 Dec 22, 2022
Immediate mode 3D gizmo for scene editing and other controls based on Dear Imgui

ImGuizmo Latest stable tagged version is 1.83. Current master version is 1.84 WIP. What started with the gizmo is now a collection of dear imgui widge

Cedric Guillemet 2.3k Dec 27, 2022
Nice things to use along dear imgui

Mini hexadecimal editor! Right-click for option menu. Features: Keyboard controls. Read-only mode. Optional Ascii display. Optional HexII display. Goto address. Highlight range/function. Read/Write handlers.

omar 664 Jan 1, 2023
Sample Unreal Engine 5.0.1 C++ Project That Incorporates Dear ImGui

UE5 With Dear ImGui A sample Unreal Engine 5.0.1 C++ project that incorporates the Dear ImGui graphical user interface library. YouTube Tutorial This

Kyle Geske 36 Dec 25, 2022
A Proof-of-concept of embedding Qt widgets into QML.

QQuickWidgetContainer It helps you embed Qt widgets into QML. Limitations and Disclaimer This is a proof-concept of bridging QWidget-based window syst

Moody 2 Nov 25, 2021
Plugin for Rainmeter: Making widgets using web technology

PluginWebView Plugin to take advantage of Microsoft Edge WebView2 to display web content on a skin. WebView window is attached into skin window so all

null 29 Nov 20, 2022
Simple and portable (but not inflexible) GUI library in C that uses the native GUI technologies of each platform it supports.

libui: a portable GUI library for C This README is being written. Status It has come to my attention that I have not been particularly clear about how

Pietro Gagliardi 10.4k Jan 2, 2023
super duper simple gui for C, wrapping imgui and stb

super duper simle gui for C, wrapping imgui and stb You can use it as a static library with cmake. See the example directory for a complete example. E

Rasmus 11 May 19, 2022
Simple ImGui external base. Uses ImGui DX9.

ImGui External Base ??️ What is this? ⚡ Hello all! I used to use noteffex's loader base for all my external ImGui projects. I got bored of using this

Alfie 11 Jun 29, 2022