mirror of
				https://github.com/Drezil/imgui.git
				synced 2025-10-30 20:51:06 +01:00 
			
		
		
		
	Exposed BeginCombo() publicly.
This commit is contained in:
		| @@ -9166,7 +9166,7 @@ void ImGui::EndCombo() | |||||||
|     EndPopup(); |     EndPopup(); | ||||||
| } | } | ||||||
|  |  | ||||||
| // Combo box function. | // Old API, prefer using BeginCombo() nowadays if you can. | ||||||
| bool ImGui::Combo(const char* label, int* current_item, bool (*items_getter)(void*, int, const char**), void* data, int items_count, int popup_max_height_in_items) | bool ImGui::Combo(const char* label, int* current_item, bool (*items_getter)(void*, int, const char**), void* data, int items_count, int popup_max_height_in_items) | ||||||
| { | { | ||||||
|     ImGuiContext& g = *GImGui; |     ImGuiContext& g = *GImGui; | ||||||
| @@ -9175,16 +9175,18 @@ bool ImGui::Combo(const char* label, int* current_item, bool (*items_getter)(voi | |||||||
|     if (*current_item >= 0 && *current_item < items_count) |     if (*current_item >= 0 && *current_item < items_count) | ||||||
|         items_getter(data, *current_item, &preview_text); |         items_getter(data, *current_item, &preview_text); | ||||||
|  |  | ||||||
|  |     // The old Combo() API exposed "popup_max_height_in_items", however the new more general BeginCombo() API doesn't, so we emulate it here. | ||||||
|     if (popup_max_height_in_items != -1 && !g.SetNextWindowSizeConstraint) |     if (popup_max_height_in_items != -1 && !g.SetNextWindowSizeConstraint) | ||||||
|     { |     { | ||||||
|         float popup_max_height = CalcMaxPopupHeightFromItemCount(popup_max_height_in_items); |         float popup_max_height = CalcMaxPopupHeightFromItemCount(popup_max_height_in_items); | ||||||
|         SetNextWindowSizeConstraints(ImVec2(0,0), ImVec2(FLT_MAX, popup_max_height)); |         SetNextWindowSizeConstraints(ImVec2(0,0), ImVec2(FLT_MAX, popup_max_height)); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     if (!BeginCombo(label, preview_text, 0)) |     if (!BeginCombo(label, preview_text, 0)) | ||||||
|         return false; |         return false; | ||||||
|  |  | ||||||
|     // Display items |     // Display items | ||||||
|     // FIXME-OPT: Use clipper |     // FIXME-OPT: Use clipper (if we can disable it on the appearing frame to make sure our call to SetScrollHere() is processed) | ||||||
|     bool value_changed = false; |     bool value_changed = false; | ||||||
|     for (int i = 0; i < items_count; i++) |     for (int i = 0; i < items_count; i++) | ||||||
|     { |     { | ||||||
| @@ -9236,7 +9238,7 @@ static bool Items_SingleStringGetter(void* data, int idx, const char** out_text) | |||||||
| } | } | ||||||
|  |  | ||||||
| // Combo box helper allowing to pass an array of strings. | // Combo box helper allowing to pass an array of strings. | ||||||
| bool ImGui::Combo(const char* label, int* current_item, const char* const* items, int items_count, int height_in_items) | bool ImGui::Combo(const char* label, int* current_item, const char* const items[], int items_count, int height_in_items) | ||||||
| { | { | ||||||
|     const bool value_changed = Combo(label, current_item, Items_ArrayGetter, (void*)items, items_count, height_in_items); |     const bool value_changed = Combo(label, current_item, Items_ArrayGetter, (void*)items, items_count, height_in_items); | ||||||
|     return value_changed; |     return value_changed; | ||||||
|   | |||||||
							
								
								
									
										25
									
								
								imgui.h
									
									
									
									
									
								
							
							
						
						
									
										25
									
								
								imgui.h
									
									
									
									
									
								
							| @@ -79,6 +79,7 @@ typedef int ImGuiStyleVar;          // enum: a variable identifier for styling | |||||||
| typedef int ImDrawCornerFlags;      // flags: for ImDrawList::AddRect*() etc.   // enum ImDrawCornerFlags_ | typedef int ImDrawCornerFlags;      // flags: for ImDrawList::AddRect*() etc.   // enum ImDrawCornerFlags_ | ||||||
| typedef int ImGuiColorEditFlags;    // flags: for ColorEdit*(), ColorPicker*()  // enum ImGuiColorEditFlags_ | typedef int ImGuiColorEditFlags;    // flags: for ColorEdit*(), ColorPicker*()  // enum ImGuiColorEditFlags_ | ||||||
| typedef int ImGuiColumnsFlags;      // flags: for *Columns*()                   // enum ImGuiColumnsFlags_ | typedef int ImGuiColumnsFlags;      // flags: for *Columns*()                   // enum ImGuiColumnsFlags_ | ||||||
|  | typedef int ImGuiComboFlags;        // flags: for BeginCombo()                  // enum ImGuiComboFlags_ | ||||||
| typedef int ImGuiHoveredFlags;      // flags: for IsItemHovered()               // enum ImGuiHoveredFlags_ | typedef int ImGuiHoveredFlags;      // flags: for IsItemHovered()               // enum ImGuiHoveredFlags_ | ||||||
| typedef int ImGuiInputTextFlags;    // flags: for InputText*()                  // enum ImGuiInputTextFlags_ | typedef int ImGuiInputTextFlags;    // flags: for InputText*()                  // enum ImGuiInputTextFlags_ | ||||||
| typedef int ImGuiSelectableFlags;   // flags: for Selectable()                  // enum ImGuiSelectableFlags_ | typedef int ImGuiSelectableFlags;   // flags: for Selectable()                  // enum ImGuiSelectableFlags_ | ||||||
| @@ -284,15 +285,20 @@ namespace ImGui | |||||||
|     IMGUI_API bool          CheckboxFlags(const char* label, unsigned int* flags, unsigned int flags_value); |     IMGUI_API bool          CheckboxFlags(const char* label, unsigned int* flags, unsigned int flags_value); | ||||||
|     IMGUI_API bool          RadioButton(const char* label, bool active); |     IMGUI_API bool          RadioButton(const char* label, bool active); | ||||||
|     IMGUI_API bool          RadioButton(const char* label, int* v, int v_button); |     IMGUI_API bool          RadioButton(const char* label, int* v, int v_button); | ||||||
|     IMGUI_API bool          Combo(const char* label, int* current_item, const char* const* items, int items_count, int height_in_items = -1); |  | ||||||
|     IMGUI_API bool          Combo(const char* label, int* current_item, const char* items_separated_by_zeros, int height_in_items = -1);    // separate items with \0, end item-list with \0\0 |  | ||||||
|     IMGUI_API bool          Combo(const char* label, int* current_item, bool (*items_getter)(void* data, int idx, const char** out_text), void* data, int items_count, int height_in_items = -1); |  | ||||||
|     IMGUI_API 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), int stride = sizeof(float)); |     IMGUI_API 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), int stride = sizeof(float)); | ||||||
|     IMGUI_API 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)); |     IMGUI_API 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)); | ||||||
|     IMGUI_API 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), int stride = sizeof(float)); |     IMGUI_API 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), int stride = sizeof(float)); | ||||||
|     IMGUI_API 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)); |     IMGUI_API 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)); | ||||||
|     IMGUI_API void          ProgressBar(float fraction, const ImVec2& size_arg = ImVec2(-1,0), const char* overlay = NULL); |     IMGUI_API void          ProgressBar(float fraction, const ImVec2& size_arg = ImVec2(-1,0), const char* overlay = NULL); | ||||||
|  |  | ||||||
|  |     // Widgets: Combo Box | ||||||
|  |     // The new BeginCombo()/EndCombo() api allows you to manage your contents and selection state however you want it.  | ||||||
|  |     IMGUI_API bool          BeginCombo(const char* label, const char* preview_value, ImGuiComboFlags flags = 0); | ||||||
|  |     IMGUI_API void          EndCombo(); | ||||||
|  |     IMGUI_API bool          Combo(const char* label, int* current_item, const char* const items[], int items_count, int popup_max_height_in_items = -1); | ||||||
|  |     IMGUI_API bool          Combo(const char* label, int* current_item, const char* items_separated_by_zeros, int popup_max_height_in_items = -1);      // Separate items with \0 within a string, end item-list with \0\0. e.g. "One\0Two\0Three\0" | ||||||
|  |     IMGUI_API bool          Combo(const char* label, int* current_item, bool(*items_getter)(void* data, int idx, const char** out_text), void* data, int items_count, int popup_max_height_in_items = -1); | ||||||
|  |  | ||||||
|     // Widgets: Drags (tip: ctrl+click on a drag box to input with keyboard. manually input values aren't clamped, can go off-bounds) |     // Widgets: Drags (tip: ctrl+click on a drag box to input with keyboard. manually input values aren't clamped, can go off-bounds) | ||||||
|     // For all the Float2/Float3/Float4/Int2/Int3/Int4 versions of every functions, note that a 'float v[X]' function argument is the same as 'float* v', the array syntax is just a way to document the number of elements that are expected to be accessible. You can pass address of your first element out of a contiguous set, e.g. &myvector.x |     // For all the Float2/Float3/Float4/Int2/Int3/Int4 versions of every functions, note that a 'float v[X]' function argument is the same as 'float* v', the array syntax is just a way to document the number of elements that are expected to be accessible. You can pass address of your first element out of a contiguous set, e.g. &myvector.x | ||||||
|     IMGUI_API bool          DragFloat(const char* label, float* v, float v_speed = 1.0f, float v_min = 0.0f, float v_max = 0.0f, const char* display_format = "%.3f", float power = 1.0f);     // If v_min >= v_max we have no bound |     IMGUI_API bool          DragFloat(const char* label, float* v, float v_speed = 1.0f, float v_min = 0.0f, float v_max = 0.0f, const char* display_format = "%.3f", float power = 1.0f);     // If v_min >= v_max we have no bound | ||||||
| @@ -403,7 +409,7 @@ namespace ImGui | |||||||
|     IMGUI_API bool          IsPopupOpen(const char* str_id);                                    // return true if the popup is open |     IMGUI_API bool          IsPopupOpen(const char* str_id);                                    // return true if the popup is open | ||||||
|     IMGUI_API void          CloseCurrentPopup();                                                // close the popup we have begin-ed into. clicking on a MenuItem or Selectable automatically close the current popup. |     IMGUI_API void          CloseCurrentPopup();                                                // close the popup we have begin-ed into. clicking on a MenuItem or Selectable automatically close the current popup. | ||||||
|  |  | ||||||
|     // Logging: all text output from interface is redirected to tty/file/clipboard. By default, tree nodes are automatically opened during logging. |     // Logging/Capture: all text output from interface is captured to tty/file/clipboard. By default, tree nodes are automatically opened during logging. | ||||||
|     IMGUI_API void          LogToTTY(int max_depth = -1);                                       // start logging to tty |     IMGUI_API void          LogToTTY(int max_depth = -1);                                       // start logging to tty | ||||||
|     IMGUI_API void          LogToFile(int max_depth = -1, const char* filename = NULL);         // start logging to file |     IMGUI_API void          LogToFile(int max_depth = -1, const char* filename = NULL);         // start logging to file | ||||||
|     IMGUI_API void          LogToClipboard(int max_depth = -1);                                 // start logging to OS clipboard |     IMGUI_API void          LogToClipboard(int max_depth = -1);                                 // start logging to OS clipboard | ||||||
| @@ -575,6 +581,17 @@ enum ImGuiSelectableFlags_ | |||||||
|     ImGuiSelectableFlags_AllowDoubleClick   = 1 << 2    // Generate press events on double clicks too |     ImGuiSelectableFlags_AllowDoubleClick   = 1 << 2    // Generate press events on double clicks too | ||||||
| }; | }; | ||||||
|  |  | ||||||
|  | // Flags for ImGui::BeginCombo() | ||||||
|  | enum ImGuiComboFlags_ | ||||||
|  | { | ||||||
|  |     ImGuiComboFlags_PopupAlignLeft      = 1 << 0,   // Align the popup toward the left by default | ||||||
|  |     ImGuiComboFlags_HeightSmall         = 1 << 1,   // Max ~4 items visible. Tip: If you want your combo popup to be a specific size you can use SetNextWindowSizeConstraints() prior to calling BeginCombo() | ||||||
|  |     ImGuiComboFlags_HeightRegular       = 1 << 2,   // Max ~8 items visible (default) | ||||||
|  |     ImGuiComboFlags_HeightLarge         = 1 << 3,   // Max ~20 items visible | ||||||
|  |     ImGuiComboFlags_HeightLargest       = 1 << 4,   // As many fitting items as possible | ||||||
|  |     ImGuiComboFlags_HeightMask_         = ImGuiComboFlags_HeightSmall | ImGuiComboFlags_HeightRegular | ImGuiComboFlags_HeightLarge | ImGuiComboFlags_HeightLargest | ||||||
|  | }; | ||||||
|  |  | ||||||
| // Flags for ImGui::IsItemHovered(), ImGui::IsWindowHovered() | // Flags for ImGui::IsItemHovered(), ImGui::IsWindowHovered() | ||||||
| enum ImGuiHoveredFlags_ | enum ImGuiHoveredFlags_ | ||||||
| { | { | ||||||
|   | |||||||
| @@ -48,7 +48,6 @@ typedef int ImGuiButtonFlags;       // flags: for ButtonEx(), ButtonBehavior() | |||||||
| typedef int ImGuiItemFlags;         // flags: for PushItemFlag()                // enum ImGuiItemFlags_ | typedef int ImGuiItemFlags;         // flags: for PushItemFlag()                // enum ImGuiItemFlags_ | ||||||
| typedef int ImGuiSeparatorFlags;    // flags: for Separator() - internal        // enum ImGuiSeparatorFlags_ | typedef int ImGuiSeparatorFlags;    // flags: for Separator() - internal        // enum ImGuiSeparatorFlags_ | ||||||
| typedef int ImGuiSliderFlags;       // flags: for SliderBehavior()              // enum ImGuiSliderFlags_ | typedef int ImGuiSliderFlags;       // flags: for SliderBehavior()              // enum ImGuiSliderFlags_ | ||||||
| typedef int ImGuiComboFlags;        // flags: for BeginCombo()                  // enum ImGuiComboFlags_ |  | ||||||
|  |  | ||||||
| //------------------------------------------------------------------------- | //------------------------------------------------------------------------- | ||||||
| // STB libraries | // STB libraries | ||||||
| @@ -210,18 +209,6 @@ enum ImGuiSelectableFlagsPrivate_ | |||||||
|     ImGuiSelectableFlags_DrawFillAvailWidth = 1 << 6 |     ImGuiSelectableFlags_DrawFillAvailWidth = 1 << 6 | ||||||
| }; | }; | ||||||
|  |  | ||||||
| enum ImGuiComboFlags_ |  | ||||||
| { |  | ||||||
|     ImGuiComboFlags_PopupAlignLeft      = 1 << 0,   // Align the popup toward the left by default |  | ||||||
|  |  | ||||||
|     // If you want your combo popup to be a specific size you can use SetNextWindowSizeConstraints() prior to calling BeginCombo() |  | ||||||
|     ImGuiComboFlags_HeightSmall         = 1 << 1,   // Max ~4 items visible |  | ||||||
|     ImGuiComboFlags_HeightRegular       = 1 << 2,   // Max ~8 items visible (default) |  | ||||||
|     ImGuiComboFlags_HeightLarge         = 1 << 3,   // Max ~20 items visible |  | ||||||
|     ImGuiComboFlags_HeightLargest       = 1 << 4,   // As many fitting items as possible |  | ||||||
|     ImGuiComboFlags_HeightMask_         = ImGuiComboFlags_HeightSmall | ImGuiComboFlags_HeightRegular | ImGuiComboFlags_HeightLarge | ImGuiComboFlags_HeightLargest |  | ||||||
| }; |  | ||||||
|  |  | ||||||
| enum ImGuiSeparatorFlags_ | enum ImGuiSeparatorFlags_ | ||||||
| { | { | ||||||
|     ImGuiSeparatorFlags_Horizontal          = 1 << 0,   // Axis default to current layout type, so generally Horizontal unless e.g. in a menu bar |     ImGuiSeparatorFlags_Horizontal          = 1 << 0,   // Axis default to current layout type, so generally Horizontal unless e.g. in a menu bar | ||||||
| @@ -859,10 +846,6 @@ namespace ImGui | |||||||
|     IMGUI_API void          EndColumns();                                                         // close columns |     IMGUI_API void          EndColumns();                                                         // close columns | ||||||
|     IMGUI_API void          PushColumnClipRect(int column_index = -1); |     IMGUI_API void          PushColumnClipRect(int column_index = -1); | ||||||
|  |  | ||||||
|     // FIXME-WIP: New Combo API |  | ||||||
|     IMGUI_API bool          BeginCombo(const char* label, const char* preview_value, ImGuiComboFlags flags = 0); |  | ||||||
|     IMGUI_API void          EndCombo(); |  | ||||||
|  |  | ||||||
|     // NB: All position are in absolute pixels coordinates (never using window coordinates internally) |     // NB: All position are in absolute pixels coordinates (never using window coordinates internally) | ||||||
|     // AVOID USING OUTSIDE OF IMGUI.CPP! NOT FOR PUBLIC CONSUMPTION. THOSE FUNCTIONS ARE A MESS. THEIR SIGNATURE AND BEHAVIOR WILL CHANGE, THEY NEED TO BE REFACTORED INTO SOMETHING DECENT. |     // AVOID USING OUTSIDE OF IMGUI.CPP! NOT FOR PUBLIC CONSUMPTION. THOSE FUNCTIONS ARE A MESS. THEIR SIGNATURE AND BEHAVIOR WILL CHANGE, THEY NEED TO BE REFACTORED INTO SOMETHING DECENT. | ||||||
|     IMGUI_API void          RenderText(ImVec2 pos, const char* text, const char* text_end = NULL, bool hide_text_after_hash = true); |     IMGUI_API void          RenderText(ImVec2 pos, const char* text, const char* text_end = NULL, bool hide_text_after_hash = true); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user