From c39862160451561b98bb1319d4c061b31a971284 Mon Sep 17 00:00:00 2001 From: Hane Date: Sun, 14 Jan 2024 22:01:14 +0100 Subject: [PATCH] Add README.md --- README.md | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++ filepicker.hpp | 6 ++--- 2 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..642ed45 --- /dev/null +++ b/README.md @@ -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. diff --git a/filepicker.hpp b/filepicker.hpp index 2e5f8a4..6d0f1d5 100644 --- a/filepicker.hpp +++ b/filepicker.hpp @@ -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); }