Git Product home page Git Product logo

imgui-addons's Introduction

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.

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

Copy all the necessary ImGui files in one folder and include it's path in your IDE. Also include the path to Dirent folder so dirent.h is accessible as Dirent/dirent.h. 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;
	if(ImGui::BeginMainMenuBar())
	{
	    if (ImGui::BeginMenu("Menu"))
	    {
	        if (ImGui::MenuItem("Open", NULL))
	            open = true;
	    }
	    ImGui::EndMainMenuBar();
	}
	
	//Remember the name to ImGui::OpenPopup() and showFileDialog() must be same...
	if(open)
	    ImGui::OpenPopup("Open 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", ImVec2(700, 310), ".rar,.zip,.7z"))
	    std::cout << file_dialog.selected_fn << std::endl;
}

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

imgui-addons's People

Contributors

gallickgunner avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.