Compare commits

...

2 commits

Author SHA1 Message Date
809a5abcd5 Add README.md 2024-01-14 22:01:14 +01:00
f937069560 demo source cleanup 2024-01-14 18:32:41 +01:00
4 changed files with 77 additions and 71 deletions

60
README.md Normal file
View file

@ -0,0 +1,60 @@
Single-header file picker Windows library for ImGui.
# How to use
int renderFilePicker(wchar_t* userPath, bool* windowOpen, int windowFlags = 0) {
Call `int fp::renderFilePicker(wchar_t* userPath, bool* windowOpen, int windowFlags = 0);` within the render loop providing a pre-allocated C-string buffer of MAX_PATH characters in `userPath`. `windowOpen` must be initially set to `true`, and will set itself to `false` when execution is done. If succesful, your buffer will contain a valid path. You can check the file picker state each frame by parsing this function's return value. You can provide `windowFlags` to customize its appearance.
## Window states
```
- fp::ExitFlags::EXIT_CONTINUE : Window will render next frame.
- fp::ExitFlags::EXIT_SELECTED : A path has been successfully returned, window will close.
- fp::ExitFlags::EXIT_CLOSED : User has closed the window. No path is returned.
- fp::ExitFlags::EXIT_ERROR : An unexpected error has ocurred. No path is returned.
```
## Valid window flags
```
- fp::WindowFlags::FP_FULLSCREEN`: Render window in full screen, without decorations.
```
# Library dependencies
- **C++ STL**: This library uses `vector` and `w\string`.
## Build considerations
Define `DEBUG` to print relevant information to the console.
# Demo build instructions
## Build requirements
- [**GLFW v3**](https://github.com/glfw/glfw/releases): used as rendering backend. Executable in releases is compiled with version [`3.3.8`](https://github.com/glfw/glfw/releases/tag/3.3.8).
- Compiled with `clang` using [**llvm-mingw 20220906**](https://github.com/mstorsjo/llvm-mingw/releases/tag/20220906).
## How to compile
Download GLFW and pick your libraries according to your toolchain(`mingw-w64` in this example).
Then, call your compiler directly (`clang` is demonstrated here) specifying both libs needed and your paths to the necessary header and lib files:
```
clang++ demo/main.cpp -o demo/demo.exe -L C:/pathtollvmmingw/x86_64-w64-mingw32/bin -I C:\pathtollvmmingw\include -L C:/pathtoglfw/lib-mingw-w64 -I C:\pathtoglfw\include -lglfw3 -l libc++
```
If you want to statically link:
```
clang++ demo/main.cpp -o demo/si.exe -DDEBUG -L C:\capybara\libclang\x86_64-w64-mingw32\bin -L C:\capybara\libclang\x86_64-w64-mingw32\lib -I C:\capybara\libclang\include -std=c++17 -lglfw3 -l opengl32 -l gdi32 -l user32 -l kernel32 -l imm32 -static-libstdc++ --verbose
```
Add `-DDEBUG` to print filepicker's debug information, if you so desire.
# To-Dos
- Implement a file watcher to check for changes on the current directory.
- Add Linux support.
- Allow users to provide their own memory allocations as an option.

View file

@ -1,26 +1,15 @@
// Dear ImGui: standalone example application for GLFW + OpenGL 3, using programmable pipeline
// (GLFW is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan/Metal graphics context creation, etc.)
// If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp.
// Read online: https://github.com/ocornut/imgui/tree/master/docs
//Demo executable based on GLFW
#define IMGUI_IMPLEMENTATION
#define GL_SILENCE_DEPRECATION
#include "unityBuild.h"
#include "filepicker.hpp"
#include "../filepicker.hpp"
// [Win32] Our example includes a copy of glfw3.lib pre-compiled with VS2010 to maximize ease of testing and compatibility with old VS compilers.
// To link with VS2010-era libraries, VS2015+ requires linking with legacy_stdio_definitions.lib, which we do using this pragma.
// Your own project should not be affected, as you are likely to link with a newer binary of GLFW that is adequate for your version of Visual Studio.
#if defined(_MSC_VER) && (_MSC_VER >= 1900) && !defined(IMGUI_DISABLE_WIN32_FUNCTIONS)
#pragma comment(lib, "legacy_stdio_definitions")
#endif
static void glfw_error_callback(int error, const char* description)
{
static void glfw_error_callback(int error, const char* description) {
fprintf(stderr, "Glfw Error %d: %s\n", error, description);
}
int main(int, char**) {
// Setup window
glfwSetErrorCallback(glfw_error_callback);
@ -61,8 +50,6 @@ int main(int, char**) {
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO(); (void)io;
//io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
//io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
// Setup Dear ImGui style
ImGui::StyleColorsDark();
@ -72,22 +59,6 @@ int main(int, char**) {
ImGui_ImplGlfw_InitForOpenGL(window, true);
ImGui_ImplOpenGL3_Init(glsl_version);
// Load Fonts
// - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them.
// - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple.
// - If the file cannot be loaded, the function will return NULL. Please handle those errors in your application (e.g. use an assertion, or display an error and quit).
// - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call.
// - Use '#define IMGUI_ENABLE_FREETYPE' in your imconfig file to use Freetype for higher quality font rendering.
// - Read 'docs/FONTS.md' for more instructions and details.
// - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
//io.Fonts->AddFontDefault();
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\segoeui.ttf", 18.0f);
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf", 16.0f);
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf", 16.0f);
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/Cousine-Regular.ttf", 15.0f);
//ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
//IM_ASSERT(font != NULL);
// Our state
bool show_demo_window = true;
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
@ -96,9 +67,6 @@ int main(int, char**) {
while (!glfwWindowShouldClose(window)) {
// Poll and handle events (inputs, window resize, etc.)
// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.
// - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application, or clear/overwrite your copy of the mouse data.
// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application, or clear/overwrite your copy of the keyboard data.
// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
glfwPollEvents();
// Start the Dear ImGui frame
@ -114,8 +82,7 @@ int main(int, char**) {
if (show_demo_window)
ImGui::ShowDemoWindow(&show_demo_window);
// Rendering
ImGui::Render();
int display_w, display_h;
@ -128,18 +95,6 @@ int main(int, char**) {
glfwSwapBuffers(window);
}
// Cleanup
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown();

View file

@ -1,25 +1,16 @@
// dear imgui: single-file wrapper include
// We use this to validate compiling all *.cpp files in a same compilation unit.
// Users of that technique (also called "Unity builds") can generally provide this themselves,
// so we don't really recommend you use this in your projects.
// Do this:
// #define IMGUI_IMPLEMENTATION
// Before you include this file in *one* C++ file to create the implementation.
// Using this in your project will leak the contents of imgui_internal.h and ImVec2 operators in this compilation unit.
#define WIN32_LEAN_AND_MEAN
#define UNICODE
#define _UNICODE
#include "imgui/imgui.h"
#include "../imgui/imgui.h"
#ifdef IMGUI_IMPLEMENTATION
#include "imgui/imgui.cpp"
#include "imgui/imgui_demo.cpp"
#include "imgui/imgui_draw.cpp"
#include "imgui/imgui_tables.cpp"
#include "imgui/imgui_widgets.cpp"
#include "imgui/backends/imgui_impl_glfw.h"
#include "imgui/backends/imgui_impl_opengl3.h"
#include "imgui/backends/imgui_impl_opengl3.cpp"
#include "imgui/backends/imgui_impl_glfw.cpp"
#include "../imgui/imgui.cpp"
#include "../imgui/imgui_demo.cpp"
#include "../imgui/imgui_draw.cpp"
#include "../imgui/imgui_tables.cpp"
#include "../imgui/imgui_widgets.cpp"
#include "../imgui/backends/imgui_impl_glfw.h"
#include "../imgui/backends/imgui_impl_opengl3.h"
#include "../imgui/backends/imgui_impl_opengl3.cpp"
#include "../imgui/backends/imgui_impl_glfw.cpp"
#endif

View file

@ -126,7 +126,7 @@ enum WindowFlags {
FP_DIRECTORY_SELECT = (1<<4)
};
enum exitFlags {
enum ExitFlags {
EXIT_CONTINUE = (1<<0),
EXIT_SELECTED = (1<<1),
EXIT_CLOSED = (1<<2),
@ -762,14 +762,14 @@ int windowRendering(wchar_t* userPath, bool* windowOpen, int windowFlags = 0){
if(ImGui::Button("Select")) {
log_wdebugcpp(chosenPath << " TRIED TO RETURN");
ImGui::End();
return exitWindow(userPath, windowOpen, exitFlags::EXIT_SELECTED);
return exitWindow(userPath, windowOpen, ExitFlags::EXIT_SELECTED);
}
//listFlags = handleFolderAccessResult(listFlags, addrBarVal, &showError, error, ErrorMessages::addrBarError, history, currentPath, addrBarVal);
ImGui::End();
if(windowOpen) return EXIT_CONTINUE;
else return exitWindow(userPath, windowOpen, exitFlags::EXIT_CLOSED);
else return exitWindow(userPath, windowOpen, ExitFlags::EXIT_CLOSED);
}