GCC Code Coverage Report


Directory: ./
File: lib/geogram_gfx/imgui_ext/imgui_ext.h
Date: 2026-09-07 02:37:58
Exec Total Coverage
Lines: 0 11 0.0%
Functions: 0 5 0.0%
Branches: 0 0 -%

Line Branch Exec Source
1 /*
2 * Copyright (c) 2000-2022 Inria
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * * Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * * Neither the name of the ALICE Project-Team nor the names of its
14 * contributors may be used to endorse or promote products derived from this
15 * software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
28 *
29 * Contact: Bruno Levy
30 *
31 * https://www.inria.fr/fr/bruno-levy
32 *
33 * Inria,
34 * Domaine de Voluceau,
35 * 78150 Le Chesnay - Rocquencourt
36 * FRANCE
37 *
38 */
39
40 #ifndef GEOGRAM_GFX_IMGUI_EXT
41 #define GEOGRAM_GFX_IMGUI_EXT
42
43 #include <geogram_gfx/basic/common.h>
44 #include <string>
45
46 #ifdef GEO_COMPILER_GCC_FAMILY
47 #pragma GCC diagnostic push
48 #pragma GCC diagnostic ignored "-Wsign-conversion"
49 #ifdef GEO_COMPILER_CLANG
50 #pragma GCC diagnostic ignored "-Wunknown-warning-option"
51 #pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
52 #pragma GCC diagnostic ignored "-Wc++98-compat-pedantic"
53 #endif
54 #endif
55
56 #include <geogram_gfx/third_party/imgui/imgui.h>
57 #include <geogram_gfx/third_party/imgui/misc/cpp/imgui_stdlib.h>
58
59 #if defined(GEO_COMPILER_GCC_FAMILY)
60 #pragma GCC diagnostic pop
61 #endif
62
63
64 /**
65 * \file geogram_gfx/ImGui_ext/imgui_ext.h
66 * \brief Extension functions for ImGui.
67 */
68
69 namespace GEO {
70 /**
71 * \brief Maximum string length for ImGUI.
72 * TODO replace with ImGui functions to handle dynamic buffer with
73 * InputText().
74 */
75 enum { geo_imgui_string_length = 4096 };
76
77 namespace FileSystem {
78 class Node;
79 }
80 }
81
82 typedef int ImGuiExtFileDialogFlags;
83
84
85 enum ImGuiExtFileDialogFlags_ {
86 ImGuiExtFileDialogFlags_Load = 1,
87 ImGuiExtFileDialogFlags_Save = 2
88 };
89
90 #ifdef GOMGEN
91 #undef GEOGRAM_GFX_API
92 #define GEOGRAM_GFX_API
93 #endif
94
95 namespace ImGui {
96
97 /**
98 * \brief Gets the global application scaling.
99 * \details The global application scaling can be changed
100 * for high DPI displays. Some GUI elements need to
101 * be scaled accordingly.
102 * \return The global application scaling.
103 */
104 float GEOGRAM_GFX_API scaling();
105
106 /**
107 * \brief Sets the global application scaling.
108 * \details The global application scaling can be changed
109 * for high DPI displays. Some GUI elements need to
110 * be scaled accordingly.
111 * \param x The global application scaling.
112 */
113 void GEOGRAM_GFX_API set_scaling(float x);
114
115 /**
116 * \brief Manages the GUI of a color editor.
117 * \details This creates a custom dialog with the color editor and
118 * a default palette, as in ImGUI example.
119 * \param[in] label the label of the widget, passed to ImGUI
120 * \param[in,out] color a pointer to an array of 3 floats
121 * \retval true if the color was changed
122 * \retval false otherwise
123 */
124 bool GEOGRAM_GFX_API ColorEdit3WithPalette(
125 const char* label, float color[3]
126 );
127
128 /**
129 * \brief Manages the GUI of a color editor.
130 * \details This creates a custom dialog with the color editor and
131 * a default palette, as in ImGUI example.
132 * \param[in] label the label of the widget, passed to ImGUI
133 * \param[in,out] color a pointer to an array of 4 floats
134 * \retval true if the color was changed
135 * \retval false otherwise
136 */
137 bool GEOGRAM_GFX_API ColorEdit4WithPalette(
138 const char* label, float color[4]
139 );
140
141 /**
142 * \brief Opens a file dialog.
143 * \param[in] label the window label of the file dialog
144 * \param[in] extensions semi-colon-separated list of extensions, without
145 * the dot
146 * \param[in] filename initial filename or empty string
147 * \param[in] root an optional root Node. If null or unspecified, then
148 * the default root is used.
149 * \details The file dialog is drawn and handled after, by calling
150 * FileDialog()
151 */
152 void GEOGRAM_GFX_API OpenFileDialog(
153 const char* label,
154 const char* extensions,
155 const char* filename,
156 ImGuiExtFileDialogFlags flags,
157 GEO::FileSystem::Node* root = nullptr
158 );
159
160 /**
161 * \brief Draws a FileDialog.
162 * \details If OpenFileDialog() was called before, then the dialog is drawn,
163 * otherwise it is ignored.
164 * \param[in] label the window label of the file dialog
165 * \param[in,out] filename the file to be read
166 * \param[in] filename_buff_len the size of the buffer pointed by filename
167 * \retval true if a file was selected
168 * \retval false otherwise
169 */
170 bool GEOGRAM_GFX_API FileDialog(
171 const char* label,
172 char* filename, size_t filename_buff_len
173 );
174
175 /**
176 * \brief Displays a tooltip.
177 * \details The tooltip is displayed if the previous item is hovered,
178 * \p str is non-null and tooltips are enabled.
179 * \param[in] str the tooltip to be displayed.
180 * \see EnableTooltips(), DisableToolTips()
181 */
182 void GEOGRAM_GFX_API Tooltip(const char* str);
183
184 /**
185 * \brief Enables tooltips.
186 * \see ToolTip()
187 */
188 void GEOGRAM_GFX_API EnableTooltips();
189
190 /**
191 * \brief Disables tooltips.
192 * \see ToolTip()
193 */
194 void GEOGRAM_GFX_API DisableTooltips();
195
196
197 /**
198 * \brief Button without border.
199 */
200 bool GEOGRAM_GFX_API SimpleButton(const char* label);
201
202 /**
203 * \brief Button without border.
204 */
205 bool GEOGRAM_GFX_API SimpleButton(const char* label, const ImVec2& size);
206
207 /**
208 * \brief Draws a text label centered in the current window.
209 * \param[in] text the text to be drawn.
210 */
211 void GEOGRAM_GFX_API CenteredText(const char* text);
212
213 /**
214 * \Brief Emulate pre-v1.92 ImGUI API
215 */
216 void GEOGRAM_GFX_API PushFont(ImFont* font);
217
218
219 #ifndef GOMGEN
220 /**
221 * \brief Adapter for ImGui::MenuItem() for std::string.
222 */
223 inline bool MenuItem(
224 const std::string& name, const char* shortcut,
225 bool* p_selected = nullptr, bool enabled = true
226 ) {
227 return ImGui::MenuItem(name.c_str(), shortcut, p_selected, enabled);
228 }
229
230 /**
231 * \brief Adapter for ImGui::MenuItem() for std::string.
232 */
233 inline bool MenuItem(
234 const std::string& name, const char* shortcut = nullptr,
235 bool selected = false, bool enabled = true
236 ) {
237 return ImGui::MenuItem(name.c_str(), shortcut, selected, enabled);
238 }
239
240 /**
241 * \brief Adapter for ImGui::BeginMenu() for std::string.
242 */
243 inline bool BeginMenu(const std::string& name) {
244 return ImGui::BeginMenu(name.c_str());
245 }
246
247 /**
248 * \brief Adapter for ImGui::Button() for std::string.
249 */
250 inline bool Button(const std::string& name) {
251 return ImGui::Button(name.c_str());
252 }
253
254 /**
255 * \brief Wrapper for std::string around SimpleButton()
256 */
257 inline bool SimpleButton(const std::string& label) {
258 return SimpleButton(label.c_str());
259 }
260
261 /**
262 * \brief Displays a tooltip.
263 * \details The tooltip is displayed if the previous item is hovered,
264 * \p str is non-null and tooltips are enabled.
265 * \param[in] s the tooltip to be displayed.
266 * \see EnableTooltips(), DisableToolTips()
267 */
268 inline void Tooltip(const std::string& s) {
269 Tooltip(s.c_str());
270 }
271 #endif
272
273 }
274
275 #endif
276