GithubHelp home page GithubHelp logo

studiovc / imfiledialog Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dfranx/imfiledialog

0.0 0.0 0.0 119 KB

A file dialog library for Dear ImGui

License: MIT License

C++ 97.67% CMake 2.33%

imfiledialog's Introduction

ImFileDialog

A simple file dialog library for Dear ImGui.

This library supports favorites, actual Windows icons, image previews, zooming in, etc...

DISCLAIMER: This library was designed and built for use in SHADERed - it uses older version of Dear ImGui so some changes might be required to get it compiled. The way the file filter and the library itself looks was also limited due to me not wanting to break SHADERed's plugins.

Requirements

This library uses C++17's std::filesystem but it also needs these libraries:

Usage

To use ImFileDialog in your project, just add ImFileDialog.h and ImFileDialog.cpp to it.

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;

	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*)tex;
};
ifd::FileDialog::Instance().DeleteTexture = [](void* tex) {
	GLuint texID = (GLuint)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

TODO

  • selecting multiple files
  • preview pane / layout options

LICENSE

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

imfiledialog's People

Contributors

dfranx avatar macpete avatar piernov avatar mennovink 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.