浏览代码

Updated imgui

Thomas Buck 10 年前
父节点
当前提交
eb9ebdf7e5
共有 3 个文件被更改,包括 124 次插入70 次删除
  1. 1
    1
      src/deps/imgui/imconfig.h
  2. 109
    63
      src/deps/imgui/imgui.cpp
  3. 14
    6
      src/deps/imgui/imgui.h

+ 1
- 1
src/deps/imgui/imconfig.h 查看文件

@@ -39,6 +39,6 @@ namespace ImGui
39 39
 {
40 40
     void    Value(const char* prefix, const MyVec2& v, const char* float_format = NULL);
41 41
     void    Value(const char* prefix, const MyVec4& v, const char* float_format = NULL);
42
-};
42
+}
43 43
 */
44 44
 

+ 109
- 63
src/deps/imgui/imgui.cpp 查看文件

@@ -1,8 +1,8 @@
1
-// ImGui library v1.14 wip
1
+// ImGui library v1.15 wip
2 2
 // See ImGui::ShowTestWindow() for sample code.
3 3
 // Read 'Programmer guide' below for notes on how to setup ImGui in your codebase.
4 4
 // Get latest version at https://github.com/ocornut/imgui
5
-// Developped by Omar Cornut and contributors.
5
+// Developed by Omar Cornut and contributors.
6 6
 
7 7
 /*
8 8
  
@@ -10,13 +10,13 @@
10 10
  =================
11 11
 
12 12
  - easy to use to create code-driven and data-driven tools
13
- - easy to use to create adhoc short-lived tools and long-lived, more elaborate tools
13
+ - easy to use to create ad hoc short-lived tools and long-lived, more elaborate tools
14 14
  - easy to hack and improve
15 15
  - minimize screen real-estate usage
16 16
  - minimize setup and maintainance
17 17
  - minimize state storage on user side
18 18
  - portable, minimize dependencies, run on target (consoles, etc.)
19
- - efficient runtime (nb- we do allocate when "growing" content - creating a window / opening a tree node for the first time, etc. - but a typical frame won't allocate anything)
19
+ - efficient runtime (NB- we do allocate when "growing" content - creating a window / opening a tree node for the first time, etc. - but a typical frame won't allocate anything)
20 20
  - read about immediate-mode GUI principles @ http://mollyrocket.com/861, http://mollyrocket.com/forums/index.html
21 21
 
22 22
  Designed for developers and content-creators, not the typical end-user! Some of the weaknesses includes:
@@ -72,7 +72,7 @@
72 72
         io.DeltaTime = 1.0f/60.0f;
73 73
         io.IniFilename = "imgui.ini";
74 74
 
75
-        // Application mainloop
75
+        // Application main loop
76 76
         while (true)
77 77
         {
78 78
             // 1/ get low-level input
@@ -170,37 +170,37 @@
170 170
  - combo: turn child handling code into popup helper
171 171
  - list selection, concept of a selectable "block" (that can be multiple widgets)
172 172
  - menubar, menus
173
- - plot: make it easier for user to draw into the graph (e.g: draw basis, highlight certain pointsm, 2d plots, multiple plots)
173
+ - plot: make it easier for user to draw into the graph (e.g: draw basis, highlight certain points, 2d plots, multiple plots)
174 174
  - plot: "smooth" automatic scale, user give an input 0.0(full user scale) 1.0(full derived from value)
175 175
  - plot: add a helper e.g. Plot(char* label, float value, float time_span=2.0f) that stores values and Plot them for you - probably another function name. and/or automatically allow to plot ANY displayed value (more reliance on stable ID)
176 176
  - file selection widget -> build the tool in our codebase to improve model-dialog idioms (may or not lead to ImGui changes)
177 177
  - slider: allow using the [-]/[+] buttons used by InputFloat()/InputInt()
178
- - slider: initial absolute click is unprecise. change to relative movement slider? hide mouse cursor, allow more precise input using less screen-space.
179
- - text edit: centered text for slider or input text to it matches typical positionning.
178
+ - slider: initial absolute click is imprecise. change to relative movement slider? hide mouse cursor, allow more precise input using less screen-space.
179
+ - text edit: centered text for slider or input text to it matches typical positioning.
180 180
  - text edit: flag to disable live update of the user buffer. 
181
- - text edit: field resize behaviour - field could stretch when being edited? hover tooltip shows more text?
181
+ - text edit: field resize behavior - field could stretch when being edited? hover tooltip shows more text?
182 182
  - text edit: pasting text into a number box should filter the characters the same way direct input does
183 183
  - settings: write more decent code to allow saving/loading new fields
184
- - settings: api for per-tool simple persistant data (bool,int,float) in .ini file
184
+ - settings: api for per-tool simple persistent data (bool,int,float) in .ini file
185 185
  - log: be able to right-click and log a window or tree-node into tty/file/clipboard?
186 186
  - filters: set a current filter that tree node can automatically query to hide themselves
187 187
  - filters: handle wildcards (with implicit leading/trailing *), regexps
188 188
  - shortcuts: add a shortcut api, e.g. parse "&Save" and/or "Save (CTRL+S)", pass in to widgets or provide simple ways to use (button=activate, input=focus)
189 189
  ! keyboard: tooltip & combo boxes are messing up / not honoring keyboard tabbing
190 190
  - keyboard: full keyboard navigation and focus.
191
- - input: reowrk IO to be able to pass actual events to fix temporal aliasing issues.
192
- - input: support trackpad style scrolling & slider edit.
191
+ - input: rework IO to be able to pass actual events to fix temporal aliasing issues.
192
+ - input: support track pad style scrolling & slider edit.
193 193
  - tooltip: move to fit within screen (e.g. when mouse cursor is right of the screen).
194 194
  - misc: not thread-safe
195 195
  - misc: double-clicking on title bar to minimize isn't consistent, perhaps move to single-click on left-most collapse icon?
196 196
  - style editor: add a button to output C code.
197
- - optimisation/render: use indexed rendering
198
- - optimisation/render: move clip-rect to vertex data? would allow merging all commands
199
- - optimisation/render: merge command-lists with same clip-rect into one even if they aren't sequential? (as long as in-between clip rectangle don't overlap)?
200
- - optimisation/render: font exported by bmfont is not tight fit on vertical axis, incur unneeded pixel-shading cost.
201
- - optimisation: turn some the various stack vectors into statically-sized arrays
202
- - optimisation: better clipping for multi-component widgets
203
- - optimisation: specialize for height based clipping first (assume widgets never go up + height tests before width tests?)
197
+ - optimization/render: use indexed rendering
198
+ - optimization/render: move clip-rect to vertex data? would allow merging all commands
199
+ - optimization/render: merge command-lists with same clip-rect into one even if they aren't sequential? (as long as in-between clip rectangle don't overlap)?
200
+ - optimization/render: font exported by bmfont is not tight fit on vertical axis, incur unneeded pixel-shading cost.
201
+ - optimization: turn some the various stack vectors into statically-sized arrays
202
+ - optimization: better clipping for multi-component widgets
203
+ - optimization: specialize for height based clipping first (assume widgets never go up + height tests before width tests?)
204 204
 */
205 205
 
206 206
 #include "imgui.h"
@@ -243,7 +243,7 @@ static void         FocusWindow(ImGuiWindow* window);
243 243
 static ImGuiWindow* FindWindow(const char* name);
244 244
 static ImGuiWindow* FindHoveredWindow(ImVec2 pos, bool excluding_childs);
245 245
 
246
-}; // namespace ImGui
246
+} // namespace ImGui
247 247
 
248 248
 //-----------------------------------------------------------------------------
249 249
 // Platform dependant default implementations
@@ -1023,7 +1023,7 @@ ImGuiWindow::ImGuiWindow(const char* name, ImVec2 default_pos, ImVec2 default_si
1023 1023
     FontWindowScale = 1.0f;
1024 1024
 
1025 1025
     if (ImLength(Size) < 0.001f)
1026
-        AutoFitFrames = 3;
1026
+        AutoFitFrames = 2;
1027 1027
 
1028 1028
     DrawList = (ImDrawList*)ImGui::MemAlloc(sizeof(ImDrawList));
1029 1029
     new(DrawList) ImDrawList();
@@ -2001,6 +2001,7 @@ bool Begin(const char* name, bool* open, ImVec2 size, float fill_alpha, ImGuiWin
2001 2001
         }
2002 2002
         else
2003 2003
         {
2004
+            // Normal windows store settings in .ini file
2004 2005
             ImGuiIniData* settings = FindWindowSettings(name);
2005 2006
             if (settings && ImLength(settings->Size) > 0.0f && !(flags & ImGuiWindowFlags_NoResize))// && ImLengthsize) == 0.0f)
2006 2007
                 size = settings->Size;
@@ -2170,15 +2171,8 @@ bool Begin(const char* name, bool* open, ImVec2 size, float fill_alpha, ImGuiWin
2170 2171
                     window->SizeFull = window->SizeContentsFit + g.Style.WindowPadding - ImVec2(0.0f, g.Style.ItemSpacing.y);
2171 2172
                 }
2172 2173
             }
2173
-            else if (!(window->Flags & ImGuiWindowFlags_NoResize))
2174
+            else
2174 2175
             {
2175
-                // Draw resize grip
2176
-                const ImGuiAabb resize_aabb(window->Aabb().GetBR()-ImVec2(18,18), window->Aabb().GetBR());
2177
-                const ImGuiID resize_id = window->GetID("#RESIZE");
2178
-                bool hovered, held;
2179
-                ButtonBehaviour(resize_aabb, resize_id, &hovered, &held, true);
2180
-                resize_col = window->Color(held ? ImGuiCol_ResizeGripActive : hovered ? ImGuiCol_ResizeGripHovered : ImGuiCol_ResizeGrip);
2181
-
2182 2176
                 ImVec2 size_auto_fit = ImClamp(window->SizeContentsFit + style.AutoFitPadding, style.WindowMinSize, g.IO.DisplaySize - style.AutoFitPadding);
2183 2177
                 if (window->AutoFitFrames > 0)
2184 2178
                 {
@@ -2186,19 +2180,29 @@ bool Begin(const char* name, bool* open, ImVec2 size, float fill_alpha, ImGuiWin
2186 2180
                     window->SizeFull = ImMax(window->SizeFull, size_auto_fit);
2187 2181
                     MarkSettingsDirty();
2188 2182
                 }
2189
-                else if (g.HoveredWindow == window && held && g.IO.MouseDoubleClicked[0])
2190
-                {
2191
-                    // Manual auto-fit
2192
-                    window->SizeFull = size_auto_fit;
2193
-                    window->Size = window->SizeFull;
2194
-                    MarkSettingsDirty();
2195
-                }
2196
-                else if (held)
2183
+                else if (!(window->Flags & ImGuiWindowFlags_NoResize))
2197 2184
                 {
2198
-                    // Resize
2199
-                    window->SizeFull = ImMax(window->SizeFull + g.IO.MouseDelta, style.WindowMinSize);
2200
-                    window->Size = window->SizeFull;
2201
-                    MarkSettingsDirty();
2185
+                    // Resize grip
2186
+                    const ImGuiAabb resize_aabb(window->Aabb().GetBR()-ImVec2(18,18), window->Aabb().GetBR());
2187
+                    const ImGuiID resize_id = window->GetID("#RESIZE");
2188
+                    bool hovered, held;
2189
+                    ButtonBehaviour(resize_aabb, resize_id, &hovered, &held, true);
2190
+                    resize_col = window->Color(held ? ImGuiCol_ResizeGripActive : hovered ? ImGuiCol_ResizeGripHovered : ImGuiCol_ResizeGrip);
2191
+
2192
+                    if (g.HoveredWindow == window && held && g.IO.MouseDoubleClicked[0])
2193
+                    {
2194
+                        // Manual auto-fit
2195
+                        window->SizeFull = size_auto_fit;
2196
+                        window->Size = window->SizeFull;
2197
+                        MarkSettingsDirty();
2198
+                    }
2199
+                    else if (held)
2200
+                    {
2201
+                        // Resize
2202
+                        window->SizeFull = ImMax(window->SizeFull + g.IO.MouseDelta, style.WindowMinSize);
2203
+                        window->Size = window->SizeFull;
2204
+                        MarkSettingsDirty();
2205
+                    }
2202 2206
                 }
2203 2207
 
2204 2208
                 // Update aabb immediately so that the rendering below isn't one frame late
@@ -2565,6 +2569,14 @@ ImVec2 GetWindowSize()
2565 2569
     return window->Size;
2566 2570
 }
2567 2571
 
2572
+void SetWindowSize(const ImVec2& size)
2573
+{
2574
+    ImGuiWindow* window = GetCurrentWindow();
2575
+    window->SizeFull = size;
2576
+    if (ImLength(size) < 0.001f)
2577
+        window->AutoFitFrames = 3;
2578
+}
2579
+
2568 2580
 ImVec2 GetWindowContentRegionMin()
2569 2581
 {
2570 2582
     ImGuiWindow* window = GetCurrentWindow();
@@ -2599,6 +2611,18 @@ ImDrawList* GetWindowDrawList()
2599 2611
     return window->DrawList;
2600 2612
 }
2601 2613
 
2614
+ImFont GetWindowFont()
2615
+{
2616
+    ImGuiWindow* window = GetCurrentWindow();
2617
+    return window->Font();
2618
+}
2619
+
2620
+float GetWindowFontSize()
2621
+{
2622
+    ImGuiWindow* window = GetCurrentWindow();
2623
+    return window->FontSize();
2624
+}
2625
+
2602 2626
 void SetWindowFontScale(float scale)
2603 2627
 {
2604 2628
     ImGuiWindow* window = GetCurrentWindow();
@@ -3600,13 +3624,7 @@ enum ImGuiPlotType
3600 3624
     ImGuiPlotType_Histogram,
3601 3625
 };
3602 3626
 
3603
-static float PlotGetValue(const float* values, size_t stride, int idx)
3604
-{
3605
-    const float v = *(float*)((unsigned char*)values + (size_t)idx * stride);
3606
-    return v;
3607
-}
3608
-
3609
-static void Plot(ImGuiPlotType plot_type, const char* label, const float* values, int values_count, int values_offset, const char* overlay_text, float scale_min, float scale_max, ImVec2 graph_size, size_t stride)
3627
+static void Plot(ImGuiPlotType plot_type, const char* label, float (*values_getter)(void* data, int idx), void* data, int values_count, int values_offset, const char* overlay_text, float scale_min, float scale_max, ImVec2 graph_size)
3610 3628
 {
3611 3629
     ImGuiState& g = GImGui;
3612 3630
     ImGuiWindow* window = GetCurrentWindow();
@@ -3636,7 +3654,7 @@ static void Plot(ImGuiPlotType plot_type, const char* label, const float* values
3636 3654
         float v_max = -FLT_MAX;
3637 3655
         for (int i = 0; i < values_count; i++)
3638 3656
         {
3639
-            const float v = PlotGetValue(values, stride, i);
3657
+            const float v = values_getter(data, i);
3640 3658
             v_min = ImMin(v_min, v);
3641 3659
             v_max = ImMax(v_max, v);
3642 3660
         }
@@ -3660,8 +3678,8 @@ static void Plot(ImGuiPlotType plot_type, const char* label, const float* values
3660 3678
         const int v_idx = (int)(t * (values_count + ((plot_type == ImGuiPlotType_Lines) ? -1 : 0)));
3661 3679
         IM_ASSERT(v_idx >= 0 && v_idx < values_count);
3662 3680
         
3663
-        const float v0 = PlotGetValue(values, stride, (v_idx + values_offset) % values_count);
3664
-        const float v1 = PlotGetValue(values, stride, (v_idx + 1 + values_offset) % values_count);
3681
+        const float v0 = values_getter(data, (v_idx + values_offset) % values_count);
3682
+        const float v1 = values_getter(data, (v_idx + 1 + values_offset) % values_count);
3665 3683
         if (plot_type == ImGuiPlotType_Lines)
3666 3684
             ImGui::SetTooltip("%d: %8.4g\n%d: %8.4g", v_idx, v0, v_idx+1, v1);
3667 3685
         else if (plot_type == ImGuiPlotType_Histogram)
@@ -3671,7 +3689,7 @@ static void Plot(ImGuiPlotType plot_type, const char* label, const float* values
3671 3689
 
3672 3690
     const float t_step = 1.0f / (float)res_w;
3673 3691
 
3674
-    float v0 = PlotGetValue(values, stride, (0 + values_offset) % values_count);
3692
+    float v0 = values_getter(data, (0 + values_offset) % values_count);
3675 3693
     float t0 = 0.0f;
3676 3694
     ImVec2 p0 = ImVec2( t0, 1.0f - ImSaturate((v0 - scale_min) / (scale_max - scale_min)) );
3677 3695
 
@@ -3683,7 +3701,7 @@ static void Plot(ImGuiPlotType plot_type, const char* label, const float* values
3683 3701
         const float t1 = t0 + t_step;
3684 3702
         const int v_idx = (int)(t0 * values_count);
3685 3703
         IM_ASSERT(v_idx >= 0 && v_idx < values_count);
3686
-        const float v1 = PlotGetValue(values, stride, (v_idx + values_offset + 1) % values_count);
3704
+        const float v1 = values_getter(data, (v_idx + values_offset + 1) % values_count);
3687 3705
         const ImVec2 p1 = ImVec2( t1, 1.0f - ImSaturate((v1 - scale_min) / (scale_max - scale_min)) );
3688 3706
 
3689 3707
         // NB- Draw calls are merged together by the DrawList system.
@@ -3703,16 +3721,42 @@ static void Plot(ImGuiPlotType plot_type, const char* label, const float* values
3703 3721
     RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, graph_bb.Min.y), label);
3704 3722
 }
3705 3723
 
3724
+struct ImGuiPlotArrayGetterData
3725
+{
3726
+    const float* Values;
3727
+    size_t Stride;
3728
+
3729
+    ImGuiPlotArrayGetterData(const float* values, size_t stride) { Values = values; Stride = stride; }
3730
+};
3731
+
3732
+static float Plot_ArrayGetter(void* data, int idx)
3733
+{
3734
+    ImGuiPlotArrayGetterData* plot_data = (ImGuiPlotArrayGetterData*)data;
3735
+    const float v = *(float*)((unsigned char*)plot_data->Values + (size_t)idx * plot_data->Stride);
3736
+    return v;
3737
+}
3738
+
3706 3739
 void PlotLines(const char* label, const float* values, int values_count, int values_offset, const char* overlay_text, float scale_min, float scale_max, ImVec2 graph_size, size_t stride)
3707 3740
 {
3708
-    ImGui::Plot(ImGuiPlotType_Lines, label, values, values_count, values_offset, overlay_text, scale_min, scale_max, graph_size, stride);
3741
+    ImGuiPlotArrayGetterData data(values, stride);
3742
+    ImGui::Plot(ImGuiPlotType_Lines, label, &Plot_ArrayGetter, (void*)&data, values_count, values_offset, overlay_text, scale_min, scale_max, graph_size);
3743
+}
3744
+
3745
+void PlotLines(const char* label, float (*values_getter)(void* data, int idx), void* data, int values_count, int values_offset, const char* overlay_text, float scale_min, float scale_max, ImVec2 graph_size)
3746
+{
3747
+    ImGui::Plot(ImGuiPlotType_Lines, label, values_getter, data, values_count, values_offset, overlay_text, scale_min, scale_max, graph_size);
3709 3748
 }
3710 3749
 
3711 3750
 void PlotHistogram(const char* label, const float* values, int values_count, int values_offset, const char* overlay_text, float scale_min, float scale_max, ImVec2 graph_size, size_t stride)
3712 3751
 {
3713
-    ImGui::Plot(ImGuiPlotType_Histogram, label, values, values_count, values_offset, overlay_text, scale_min, scale_max, graph_size, stride);
3752
+    ImGuiPlotArrayGetterData data(values, stride);
3753
+    ImGui::Plot(ImGuiPlotType_Histogram, label, &Plot_ArrayGetter, (void*)&data, values_count, values_offset, overlay_text, scale_min, scale_max, graph_size);
3714 3754
 }
3715 3755
 
3756
+void PlotHistogram(const char* label, float (*values_getter)(void* data, int idx), void* data, int values_count, int values_offset, const char* overlay_text, float scale_min, float scale_max, ImVec2 graph_size)
3757
+{
3758
+    ImGui::Plot(ImGuiPlotType_Histogram, label, values_getter, data, values_count, values_offset, overlay_text, scale_min, scale_max, graph_size);
3759
+}
3716 3760
 bool Checkbox(const char* label, bool* v)
3717 3761
 {
3718 3762
     ImGuiState& g = GImGui;
@@ -3830,7 +3874,7 @@ bool RadioButton(const char* label, int* v, int v_button)
3830 3874
     return pressed;
3831 3875
 }
3832 3876
 
3833
-}; // namespace ImGui
3877
+} // namespace ImGui
3834 3878
 
3835 3879
 // Wrapper for stb_textedit.h to edit text (our wrapper is for: statically sized buffer, single-line, ASCII, fixed-width font)
3836 3880
 int     STB_TEXTEDIT_STRINGLEN(const STB_TEXTEDIT_STRING* obj)                                  { return (int)ImStrlenW(obj->Text); }
@@ -4633,11 +4677,13 @@ bool ColorEdit4(const char* label, float col[4], bool alpha)
4633 4677
             char* p = buf;
4634 4678
             while (*p == '#' || *p == ' ' || *p == '\t') 
4635 4679
                 p++;
4680
+
4681
+            // Treat at unsigned (%X is unsigned)
4636 4682
             ix = iy = iz = iw = 0;
4637 4683
             if (alpha)
4638
-                sscanf(p, "%02X%02X%02X%02X", &ix, &iy, &iz, &iw);
4684
+                sscanf(p, "%02X%02X%02X%02X", (unsigned int*)&ix, (unsigned int*)&iy, (unsigned int*)&iz, (unsigned int*)&iw);
4639 4685
             else
4640
-                sscanf(p, "%02X%02X%02X", &ix, &iy, &iz);
4686
+                sscanf(p, "%02X%02X%02X", (unsigned int*)&ix, (unsigned int*)&iy, (unsigned int*)&iz);
4641 4687
         }
4642 4688
         break;
4643 4689
     }
@@ -4837,7 +4883,7 @@ float GetColumnOffset(int column_index)
4837 4883
     const ImGuiID column_id = window->DC.ColumnsSetID + ImGuiID(column_index);
4838 4884
     RegisterAliveId(column_id);
4839 4885
     const float default_t = column_index / (float)window->DC.ColumnsCount;
4840
-    const float t = (float)window->StateStorage.GetInt(column_id, (int)(default_t * 8096)) / 8096;      // Cheaply store our floating point value inside the integer (could store an union into the map?)
4886
+    const float t = (float)window->StateStorage.GetInt(column_id, (int)(default_t * 8192)) / 8192;      // Cheaply store our floating point value inside the integer (could store an union into the map?)
4841 4887
 
4842 4888
     const float offset = window->DC.ColumnStartX + t * (window->Size.x - g.Style.ScrollBarWidth - window->DC.ColumnStartX);
4843 4889
     return offset;
@@ -4852,7 +4898,7 @@ void SetColumnOffset(int column_index, float offset)
4852 4898
 
4853 4899
     const ImGuiID column_id = window->DC.ColumnsSetID + ImGuiID(column_index);
4854 4900
     const float t = (offset - window->DC.ColumnStartX) / (window->Size.x - g.Style.ScrollBarWidth - window->DC.ColumnStartX);
4855
-    window->StateStorage.SetInt(column_id, (int)(t*8096));
4901
+    window->StateStorage.SetInt(column_id, (int)(t*8192));
4856 4902
 }
4857 4903
 
4858 4904
 float GetColumnWidth(int column_index)
@@ -5016,7 +5062,7 @@ void Color(const char* prefix, unsigned int v)
5016 5062
     ImGui::ColorButton(col, true);
5017 5063
 }
5018 5064
 
5019
-}; // namespace ImGui
5065
+} // namespace ImGui
5020 5066
 
5021 5067
 //-----------------------------------------------------------------------------
5022 5068
 // ImDrawList
@@ -6452,7 +6498,7 @@ void ShowTestWindow(bool* open)
6452 6498
 }
6453 6499
 // End of Sample code
6454 6500
 
6455
-}; // namespace ImGui
6501
+} // namespace ImGui
6456 6502
 
6457 6503
 //-----------------------------------------------------------------------------
6458 6504
 // Font data
@@ -6661,7 +6707,7 @@ void GetDefaultFontData(const void** fnt_data, unsigned int* fnt_size, const voi
6661 6707
     if (png_size) *png_size = proggy_clean_13_png_size;
6662 6708
 }
6663 6709
 
6664
-};
6710
+} // namespace ImGui
6665 6711
 
6666 6712
 //-----------------------------------------------------------------------------
6667 6713
 

+ 14
- 6
src/deps/imgui/imgui.h 查看文件

@@ -1,4 +1,4 @@
1
-// ImGui library v1.14 wip
1
+// ImGui library v1.15 wip
2 2
 // See .cpp file for commentary.
3 3
 // See ImGui::ShowTestWindow() for sample code.
4 4
 // Read 'Programmer guide' in .cpp for notes on how to setup ImGui in your codebase.
@@ -63,7 +63,7 @@ namespace ImGui
63 63
     void*       MemAlloc(size_t sz);
64 64
     void        MemFree(void* ptr);
65 65
     void*       MemRealloc(void* ptr, size_t sz);
66
-};
66
+}
67 67
 
68 68
 // std::vector<> like class to avoid dragging dependencies (also: windows implementation of STL with debug enabled is absurdly slow, so let's bypass it so our code runs fast in debug). 
69 69
 // Use '#define ImVector std::vector' if you want to use the STL type or your own type.
@@ -139,18 +139,21 @@ namespace ImGui
139 139
     void        ShowTestWindow(bool* open = NULL);
140 140
 
141 141
     // Window
142
-    bool        Begin(const char* name = "Debug", bool* open = NULL, ImVec2 size = ImVec2(0,0), float fill_alpha = -1.0f, ImGuiWindowFlags flags = 0);
142
+    bool        Begin(const char* name = "Debug", bool* open = NULL, ImVec2 size = ImVec2(0,0), float fill_alpha = -1.0f, ImGuiWindowFlags flags = 0);    // return false when window is collapsed, so you can early out in your code.
143 143
     void        End();
144 144
     void        BeginChild(const char* str_id, ImVec2 size = ImVec2(0,0), bool border = false, ImGuiWindowFlags extra_flags = 0);
145 145
     void        EndChild();
146 146
     bool        GetWindowIsFocused();
147 147
     ImVec2      GetWindowSize();
148 148
     float       GetWindowWidth();
149
+    void		SetWindowSize(const ImVec2& size);                                  // set to ImVec2(0,0) to force an auto-fit
149 150
     ImVec2      GetWindowPos();                                                     // you should rarely need/care about the window position, but it can be useful if you want to use your own drawing.
150 151
     void        SetWindowPos(const ImVec2& pos);                                    // set current window pos.
151 152
     ImVec2      GetWindowContentRegionMin();
152 153
     ImVec2      GetWindowContentRegionMax();
153 154
     ImDrawList* GetWindowDrawList();                                                // get rendering command-list if you want to append your own draw primitives.
155
+    ImFont      GetWindowFont();
156
+    float       GetWindowFontSize();
154 157
     void        SetWindowFontScale(float scale);                                    // per-window font scale. Adjust IO.FontBaseScale if you want to scale all windows together.
155 158
     void        SetScrollPosHere();                                                 // adjust scrolling position to center into the current cursor position.
156 159
     void        SetKeyboardFocusHere(int offset = 0);                               // focus keyboard on the next widget. Use 'offset' to access sub components of a multiple component widget.
@@ -214,7 +217,9 @@ namespace ImGui
214 217
     bool        SliderAngle(const char* label, float* v, float v_degrees_min = -360.0f, float v_degrees_max = +360.0f);     // *v in radians
215 218
     bool        SliderInt(const char* label, int* v, int v_min, int v_max, const char* display_format = "%.0f");
216 219
     void        PlotLines(const char* label, const float* values, int values_count, int values_offset = 0, const char* overlay_text = NULL, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0,0), size_t stride = sizeof(float));
220
+    void        PlotLines(const char* label, float (*values_getter)(void* data, int idx), void* data, int values_count, int values_offset = 0, const char* overlay_text = NULL, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0,0));
217 221
     void        PlotHistogram(const char* label, const float* values, int values_count, int values_offset = 0, const char* overlay_text = NULL, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0,0), size_t stride = sizeof(float));
222
+    void        PlotHistogram(const char* label, float (*values_getter)(void* data, int idx), void* data, int values_count, int values_offset = 0, const char* overlay_text = NULL, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0,0));
218 223
     bool        Checkbox(const char* label, bool* v);
219 224
     bool        CheckboxFlags(const char* label, unsigned int* flags, unsigned int flags_value);
220 225
     bool        RadioButton(const char* label, bool active);
@@ -277,7 +282,7 @@ namespace ImGui
277 282
     void        GetDefaultFontData(const void** fnt_data, unsigned int* fnt_size, const void** png_data, unsigned int* png_size);
278 283
     ImVec2      CalcTextSize(const char* text, const char* text_end = NULL, const bool hide_text_after_hash = true);
279 284
 
280
-}; // namespace ImGui
285
+} // namespace ImGui
281 286
 
282 287
 // Flags for ImGui::Begin()
283 288
 enum ImGuiWindowFlags_
@@ -575,7 +580,6 @@ struct ImDrawCmd
575 580
     ImVec4          clip_rect;
576 581
 };
577 582
 
578
-// sizeof() == 20
579 583
 struct ImDrawVert
580 584
 {
581 585
     ImVec2  pos;
@@ -584,7 +588,11 @@ struct ImDrawVert
584 588
 };
585 589
 
586 590
 // Draw command list
587
-// User is responsible for providing a renderer for this in ImGuiIO::RenderDrawListFn
591
+// This is the low-level list of polygon that ImGui:: functions are filling. At the end of the frame, all command lists are passed to your ImGuiIO::RenderDrawListFn function for rendering.
592
+// Each ImGui window contains its own ImDrawList.
593
+// If you want to add custom rendering within a window, you can use ImGui::GetWindowDrawList() to access the current draw list and add your own primitives.
594
+// You can interleave normal ImGui:: calls and adding primitives to the current draw list.
595
+// Note that this only gives you access to rendering polygons. If your intent is to create custom widgets and the publicly exposed functions/data aren't sufficient, you can add code in imgui_user.inl
588 596
 struct ImDrawList
589 597
 {
590 598
     // This is what you have to render

正在加载...
取消
保存