Skip to content

Commit c261dac

Browse files
committed
Demo: moved ShowUserGuide() lower in the file, to make main demo entry point more visible + fix using IMGUI_DEBUG_LOG() macros in if/else.
1 parent 51bbc70 commit c261dac

File tree

2 files changed

+59
-52
lines changed

2 files changed

+59
-52
lines changed

imgui_demo.cpp

+58-51
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,18 @@
5050
5151
Index of this file:
5252
53-
// [SECTION] Forward Declarations, Helpers
53+
// [SECTION] Forward Declarations
54+
// [SECTION] Helpers
5455
// [SECTION] Demo Window / ShowDemoWindow()
56+
// - ShowDemoWindow()
5557
// - sub section: ShowDemoWindowWidgets()
5658
// - sub section: ShowDemoWindowLayout()
5759
// - sub section: ShowDemoWindowPopups()
5860
// - sub section: ShowDemoWindowTables()
5961
// - sub section: ShowDemoWindowInputs()
6062
// [SECTION] About Window / ShowAboutWindow()
6163
// [SECTION] Style Editor / ShowStyleEditor()
64+
// [SECTION] User Guide / ShowUserGuide()
6265
// [SECTION] Example App: Main Menu Bar / ShowExampleAppMainMenuBar()
6366
// [SECTION] Example App: Debug Console / ShowExampleAppConsole()
6467
// [SECTION] Example App: Debug Log / ShowExampleAppLog()
@@ -190,6 +193,19 @@ static void ShowExampleAppWindowTitles(bool* p_open);
190193
static void ShowExampleAppCustomRendering(bool* p_open);
191194
static void ShowExampleMenuFile();
192195

196+
// We split the contents of the big ShowDemoWindow() function into smaller functions
197+
// (because the link time of very large functions grow non-linearly)
198+
static void ShowDemoWindowWidgets();
199+
static void ShowDemoWindowLayout();
200+
static void ShowDemoWindowPopups();
201+
static void ShowDemoWindowTables();
202+
static void ShowDemoWindowColumns();
203+
static void ShowDemoWindowInputs();
204+
205+
//-----------------------------------------------------------------------------
206+
// [SECTION] Helpers
207+
//-----------------------------------------------------------------------------
208+
193209
// Helper to display a little (?) mark which shows a tooltip when hovered.
194210
// In your own code you may want to display an actual icon if you are using a merged icon fonts (see docs/FONTS.md)
195211
static void HelpMarker(const char* desc)
@@ -207,46 +223,16 @@ static void HelpMarker(const char* desc)
207223

208224
// Helper to wire demo markers located in code to an interactive browser
209225
typedef void (*ImGuiDemoMarkerCallback)(const char* file, int line, const char* section, void* user_data);
210-
extern ImGuiDemoMarkerCallback GImGuiDemoMarkerCallback;
211-
extern void* GImGuiDemoMarkerCallbackUserData;
212-
ImGuiDemoMarkerCallback GImGuiDemoMarkerCallback = NULL;
213-
void* GImGuiDemoMarkerCallbackUserData = NULL;
226+
extern ImGuiDemoMarkerCallback GImGuiDemoMarkerCallback;
227+
extern void* GImGuiDemoMarkerCallbackUserData;
228+
ImGuiDemoMarkerCallback GImGuiDemoMarkerCallback = NULL;
229+
void* GImGuiDemoMarkerCallbackUserData = NULL;
214230
#define IMGUI_DEMO_MARKER(section) do { if (GImGuiDemoMarkerCallback != NULL) GImGuiDemoMarkerCallback(__FILE__, __LINE__, section, GImGuiDemoMarkerCallbackUserData); } while (0)
215231

216-
// Helper to display basic user controls.
217-
void ImGui::ShowUserGuide()
218-
{
219-
ImGuiIO& io = ImGui::GetIO();
220-
ImGui::BulletText("Double-click on title bar to collapse window.");
221-
ImGui::BulletText(
222-
"Click and drag on lower corner to resize window\n"
223-
"(double-click to auto fit window to its contents).");
224-
ImGui::BulletText("CTRL+Click on a slider or drag box to input value as text.");
225-
ImGui::BulletText("TAB/SHIFT+TAB to cycle through keyboard editable fields.");
226-
ImGui::BulletText("CTRL+Tab to select a window.");
227-
if (io.FontAllowUserScaling)
228-
ImGui::BulletText("CTRL+Mouse Wheel to zoom window contents.");
229-
ImGui::BulletText("While inputing text:\n");
230-
ImGui::Indent();
231-
ImGui::BulletText("CTRL+Left/Right to word jump.");
232-
ImGui::BulletText("CTRL+A or double-click to select all.");
233-
ImGui::BulletText("CTRL+X/C/V to use clipboard cut/copy/paste.");
234-
ImGui::BulletText("CTRL+Z,CTRL+Y to undo/redo.");
235-
ImGui::BulletText("ESCAPE to revert.");
236-
ImGui::Unindent();
237-
ImGui::BulletText("With keyboard navigation enabled:");
238-
ImGui::Indent();
239-
ImGui::BulletText("Arrow keys to navigate.");
240-
ImGui::BulletText("Space to activate a widget.");
241-
ImGui::BulletText("Return to input text into a widget.");
242-
ImGui::BulletText("Escape to deactivate a widget, close popup, exit child window.");
243-
ImGui::BulletText("Alt to jump to the menu layer of a window.");
244-
ImGui::Unindent();
245-
}
246-
247232
//-----------------------------------------------------------------------------
248233
// [SECTION] Demo Window / ShowDemoWindow()
249234
//-----------------------------------------------------------------------------
235+
// - ShowDemoWindow()
250236
// - ShowDemoWindowWidgets()
251237
// - ShowDemoWindowLayout()
252238
// - ShowDemoWindowPopups()
@@ -255,28 +241,18 @@ void ImGui::ShowUserGuide()
255241
// - ShowDemoWindowInputs()
256242
//-----------------------------------------------------------------------------
257243

258-
// We split the contents of the big ShowDemoWindow() function into smaller functions
259-
// (because the link time of very large functions grow non-linearly)
260-
static void ShowDemoWindowWidgets();
261-
static void ShowDemoWindowLayout();
262-
static void ShowDemoWindowPopups();
263-
static void ShowDemoWindowTables();
264-
static void ShowDemoWindowColumns();
265-
static void ShowDemoWindowInputs();
266-
267244
// Demonstrate most Dear ImGui features (this is big function!)
268245
// You may execute this function to experiment with the UI and understand what it does.
269246
// You may then search for keywords in the code when you are interested by a specific feature.
270247
void ImGui::ShowDemoWindow(bool* p_open)
271248
{
272249
// Exceptionally add an extra assert here for people confused about initial Dear ImGui setup
273-
// Most ImGui functions would normally just crash if the context is missing.
250+
// Most functions would normally just crash if the context is missing.
274251
IM_ASSERT(ImGui::GetCurrentContext() != NULL && "Missing dear imgui context. Refer to examples app!");
275252

276253
// Examples Apps (accessible from the "Examples" menu)
277254
static bool show_app_main_menu_bar = false;
278255
static bool show_app_documents = false;
279-
280256
static bool show_app_console = false;
281257
static bool show_app_log = false;
282258
static bool show_app_layout = false;
@@ -291,7 +267,6 @@ void ImGui::ShowDemoWindow(bool* p_open)
291267

292268
if (show_app_main_menu_bar) ShowExampleAppMainMenuBar();
293269
if (show_app_documents) ShowExampleAppDocuments(&show_app_documents);
294-
295270
if (show_app_console) ShowExampleAppConsole(&show_app_console);
296271
if (show_app_log) ShowExampleAppLog(&show_app_log);
297272
if (show_app_layout) ShowExampleAppLayout(&show_app_layout);
@@ -304,7 +279,7 @@ void ImGui::ShowDemoWindow(bool* p_open)
304279
if (show_app_window_titles) ShowExampleAppWindowTitles(&show_app_window_titles);
305280
if (show_app_custom_rendering) ShowExampleAppCustomRendering(&show_app_custom_rendering);
306281

307-
// Dear ImGui Apps (accessible from the "Tools" menu)
282+
// Dear ImGui Tools/Apps (accessible from the "Tools" menu)
308283
static bool show_app_metrics = false;
309284
static bool show_app_debug_log = false;
310285
static bool show_app_stack_tool = false;
@@ -367,10 +342,8 @@ void ImGui::ShowDemoWindow(bool* p_open)
367342
}
368343

369344
// Most "big" widgets share a common width settings by default. See 'Demo->Layout->Widgets Width' for details.
370-
371345
// e.g. Use 2/3 of the space for widgets and 1/3 for labels (right align)
372346
//ImGui::PushItemWidth(-ImGui::GetWindowWidth() * 0.35f);
373-
374347
// e.g. Leave a fixed amount of width for labels (by passing a negative value), the rest goes to widgets.
375348
ImGui::PushItemWidth(ImGui::GetFontSize() * -12);
376349

@@ -6423,6 +6396,40 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref)
64236396
ImGui::PopItemWidth();
64246397
}
64256398

6399+
//-----------------------------------------------------------------------------
6400+
// [SECTION] User Guide / ShowUserGuide()
6401+
//-----------------------------------------------------------------------------
6402+
6403+
void ImGui::ShowUserGuide()
6404+
{
6405+
ImGuiIO& io = ImGui::GetIO();
6406+
ImGui::BulletText("Double-click on title bar to collapse window.");
6407+
ImGui::BulletText(
6408+
"Click and drag on lower corner to resize window\n"
6409+
"(double-click to auto fit window to its contents).");
6410+
ImGui::BulletText("CTRL+Click on a slider or drag box to input value as text.");
6411+
ImGui::BulletText("TAB/SHIFT+TAB to cycle through keyboard editable fields.");
6412+
ImGui::BulletText("CTRL+Tab to select a window.");
6413+
if (io.FontAllowUserScaling)
6414+
ImGui::BulletText("CTRL+Mouse Wheel to zoom window contents.");
6415+
ImGui::BulletText("While inputing text:\n");
6416+
ImGui::Indent();
6417+
ImGui::BulletText("CTRL+Left/Right to word jump.");
6418+
ImGui::BulletText("CTRL+A or double-click to select all.");
6419+
ImGui::BulletText("CTRL+X/C/V to use clipboard cut/copy/paste.");
6420+
ImGui::BulletText("CTRL+Z,CTRL+Y to undo/redo.");
6421+
ImGui::BulletText("ESCAPE to revert.");
6422+
ImGui::Unindent();
6423+
ImGui::BulletText("With keyboard navigation enabled:");
6424+
ImGui::Indent();
6425+
ImGui::BulletText("Arrow keys to navigate.");
6426+
ImGui::BulletText("Space to activate a widget.");
6427+
ImGui::BulletText("Return to input text into a widget.");
6428+
ImGui::BulletText("Escape to deactivate a widget, close popup, exit child window.");
6429+
ImGui::BulletText("Alt to jump to the menu layer of a window.");
6430+
ImGui::Unindent();
6431+
}
6432+
64266433
//-----------------------------------------------------------------------------
64276434
// [SECTION] Example App: Main Menu Bar / ShowExampleAppMainMenuBar()
64286435
//-----------------------------------------------------------------------------

imgui_internal.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ namespace ImStb
205205
#endif
206206

207207
// Debug Logging for ShowDebugLogWindow(). This is designed for relatively rare events so please don't spam.
208-
#define IMGUI_DEBUG_LOG(...) ImGui::DebugLog(__VA_ARGS__);
208+
#define IMGUI_DEBUG_LOG(...) ImGui::DebugLog(__VA_ARGS__)
209209
#define IMGUI_DEBUG_LOG_ACTIVEID(...) do { if (g.DebugLogFlags & ImGuiDebugLogFlags_EventActiveId) IMGUI_DEBUG_LOG(__VA_ARGS__); } while (0)
210210
#define IMGUI_DEBUG_LOG_FOCUS(...) do { if (g.DebugLogFlags & ImGuiDebugLogFlags_EventFocus) IMGUI_DEBUG_LOG(__VA_ARGS__); } while (0)
211211
#define IMGUI_DEBUG_LOG_POPUP(...) do { if (g.DebugLogFlags & ImGuiDebugLogFlags_EventPopup) IMGUI_DEBUG_LOG(__VA_ARGS__); } while (0)

0 commit comments

Comments
 (0)