Allolib  1.0
C++ Components For Interactive Multimedia
al_FileSelector.hpp
1 #ifndef AL_FILESELECTOR_HPP
2 #define AL_FILESELECTOR_HPP
3 
4 /* Allolib --
5  Multimedia / virtual environment application class library
6 
7  Copyright (C) 2009. AlloSphere Research Group, Media Arts & Technology,
8  UCSB. Copyright (C) 2012-2018. The Regents of the University of California.
9  All rights reserved.
10 
11  Redistribution and use in source and binary forms, with or without
12  modification, are permitted provided that the following conditions are met:
13 
14  Redistributions of source code must retain the above copyright notice,
15  this list of conditions and the following disclaimer.
16 
17  Redistributions in binary form must reproduce the above copyright
18  notice, this list of conditions and the following disclaimer in the
19  documentation and/or other materials provided with the distribution.
20 
21  Neither the name of the University of California nor the names of its
22  contributors may be used to endorse or promote products derived from
23  this software without specific prior written permission.
24 
25  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
29  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35  POSSIBILITY OF SUCH DAMAGE.
36 
37  File description:
38  FileSelector GUI for ImGui
39 
40  File author(s):
41  AndrĂ©s Cabrera mantaraya36@gmail.com
42 */
43 
44 #include <functional>
45 #include <string>
46 
47 #include "al/io/al_File.hpp"
48 
49 namespace al {
50 
53 class FileSelector {
54  public:
56  std::string globalRoot = "",
57  std::function<bool(std::string)> filterfunction = [](std::string) {
58  return true;
59  });
60 
61  void start(std::string currentDir = "");
62 
68 
69  FileList getSelection();
70 
71  bool isActive() { return mActive; }
72 
73  void cancel() { mActive = false; }
74 
75  protected:
76  bool filteringFunctionWrapper(FilePath const& fp) {
77  return mFilterFunc(mGlobalRoot + mCurrentDir + "/" + fp.file());
78  }
79 
80  private:
81  std::string mSelectedItem = "";
82  std::string mCurrentDir = "";
83  std::string mGlobalRoot = "";
84  FileList items;
85  bool mActive{false};
86  std::function<bool(std::string)> mFilterFunc;
87 };
88 
89 } // namespace al
90 
91 #endif
bool drawFileSelector()
drawFileSelector
Definition: al_App.hpp:23