@@ -341,133 +341,3 @@ void ImGui::RenderCollapseTriangle(ImVec2 p_min, bool is_open, float scale, bool
341341 window->DrawList ->AddTriangleFilled (ImVec2 (2 +a.x , 2 +a.y ), ImVec2 (2 +b.x , 2 +b.y ), ImVec2 (2 +c.x , 2 +c.y ), GetColorU32 (ImGuiCol_BorderShadow));
342342 window->DrawList ->AddTriangleFilled (a, b, c, GetColorU32 (ImGuiCol_Text));
343343}
344- // Combo box function.
345- bool ImGui::Combo (const char * label, int * current_item, bool (*items_getter)(void *, int , const char **), void* data, int items_count, int height_in_items, bool show_arrow_down)
346- {
347- ImGuiWindow* window = GetCurrentWindow ();
348- if (window->SkipItems )
349- return false ;
350-
351- ImGuiContext& g = *GImGui;
352- const ImGuiStyle& style = g.Style ;
353- const ImGuiID id = window->GetID (label);
354- const float w = CalcItemWidth ();
355-
356- const ImVec2 label_size = CalcTextSize (label, NULL , true );
357- const ImRect frame_bb (window->DC .CursorPos , ImVec2 (w+ window->DC .CursorPos .x , label_size.y + style.FramePadding .y * 2 .0f + window->DC .CursorPos .y ));
358- const ImRect total_bb (frame_bb.Min ,ImVec2 (frame_bb.Max .x +label_size.x > frame_bb.Max .x + 0 .0f ? style.ItemInnerSpacing .x + label_size.x : 0 .0f + frame_bb.Max .x , 0 .0f + frame_bb.Max .x ));
359- ItemSize (total_bb, style.FramePadding .y );
360- if (!ItemAdd (total_bb, id))
361- return false ;
362-
363- const float arrow_size = show_arrow_down ? (g.FontSize + style.FramePadding .x * 2 .0f ) : 0 ;
364- const bool hovered = IsHovered (frame_bb, id);
365- bool popup_open = IsPopupOpen (id, ImGuiPopupFlags_AnyPopupLevel);
366- bool popup_opened_now = false ;
367-
368- const ImRect value_bb (frame_bb.Min , ImVec2 (frame_bb.Max .x -arrow_size, frame_bb.Max .y -0 .0f ));
369- if (show_arrow_down)
370- {
371- RenderFrame (frame_bb.Min , frame_bb.Max , GetColorU32 (ImGuiCol_FrameBg), true , style.FrameRounding );
372- RenderFrame (ImVec2 (frame_bb.Max .x - arrow_size, frame_bb.Min .y ), frame_bb.Max , GetColorU32 (popup_open || hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button), true , style.FrameRounding ); // FIXME-ROUNDING
373- RenderCollapseTriangle (ImVec2 (frame_bb.Max .x - arrow_size+ style.FramePadding .x , frame_bb.Min .y + style.FramePadding .y ), true );
374- }
375- if (*current_item >= 0 && *current_item < items_count)
376- {
377- const char * item_text;
378- if (items_getter (data, *current_item, &item_text))
379- RenderTextClipped (ImVec2 (frame_bb.Min .x + style.FramePadding .x , frame_bb.Min .y + style.FramePadding .y ), value_bb.Max , item_text, NULL , NULL );
380- }
381-
382- if (label_size.x > 0 )
383- RenderText (ImVec2 (frame_bb.Max .x + style.ItemInnerSpacing .x , frame_bb.Min .y + style.FramePadding .y ), label);
384-
385- if (hovered)
386- {
387- SetHoveredID (id);
388- if (g.IO .MouseClicked [0 ])
389- {
390- SetActiveID (0 ,NULL );
391- if (IsPopupOpen (id, ImGuiPopupFlags_AnyPopupLevel))
392- {
393- ClosePopup (id);
394- }
395- else
396- {
397- FocusWindow (window);
398- OpenPopup (label);
399- popup_open = popup_opened_now = true ;
400- }
401- }
402- }
403-
404- bool value_changed = false ;
405- if (IsPopupOpen (id, ImGuiPopupFlags_AnyPopupLevel))
406- {
407- // Size default to hold ~7 items
408- if (height_in_items < 0 )
409- height_in_items = 7 ;
410-
411- float popup_height = (label_size.y + style.ItemSpacing .y ) * ImMin (items_count, height_in_items) + (style.FramePadding .y * 3 );
412- float popup_y1 = frame_bb.Max .y ;
413- float popup_y2 = ImClamp (popup_y1 + popup_height, popup_y1, g.IO .DisplaySize .y - style.DisplaySafeAreaPadding .y );
414- if ((popup_y2 - popup_y1) < ImMin (popup_height, frame_bb.Min .y - style.DisplaySafeAreaPadding .y ))
415- {
416- // Position our combo ABOVE because there's more space to fit! (FIXME: Handle in Begin() or use a shared helper. We have similar code in Begin() for popup placement)
417- popup_y1 = ImClamp (frame_bb.Min .y - popup_height, style.DisplaySafeAreaPadding .y , frame_bb.Min .y );
418- popup_y2 = frame_bb.Min .y ;
419- }
420- ImRect popup_rect (ImVec2 (frame_bb.Min .x , popup_y1), ImVec2 (frame_bb.Max .x , popup_y2));
421- SetNextWindowPos (popup_rect.Min );
422- SetNextWindowSize (popup_rect.GetSize ());
423- PushStyleVar (ImGuiStyleVar_WindowPadding, style.FramePadding );
424-
425- const ImGuiWindowFlags flags = ImGuiWindowFlags_NoCollapse;
426- if (BeginPopupEx ((ImGuiID)label, flags))
427- {
428- // Display items
429- Spacing ();
430- for (int i = 0 ; i < items_count; i++)
431- {
432- PushID ((void *)(intptr_t )i);
433- const bool item_selected = (i == *current_item);
434- const char * item_text;
435- if (!items_getter (data, i, &item_text))
436- item_text = " *Unknown item*" ;
437- if (Selectable (item_text, item_selected))
438- {
439- ClearActiveID ();
440- value_changed = true ;
441- *current_item = i;
442- }
443- if (item_selected && popup_opened_now)
444- SetScrollHereY ();
445- PopID ();
446- }
447- EndPopup ();
448- }
449- PopStyleVar ();
450- }
451- return value_changed;
452- }
453-
454- // Combo box helper allowing to pass an array of strings.
455- bool ImGui::Combo (const char * label, int * current_item, const char ** items, int items_count, int height_in_items, bool show_arrow_down)
456- {
457- const bool value_changed = Combo (label, current_item, Items_ArrayGetter, (void *)items, items_count, height_in_items,false );
458- return value_changed;
459- }
460-
461- // Combo box helper allowing to pass all items in a single string.
462- bool ImGui::Combo (const char * label, int * current_item, const char * items_separated_by_zeros, int height_in_items, bool show_arrow_down)
463- {
464- int items_count = 0 ;
465- const char * p = items_separated_by_zeros; // FIXME-OPT: Avoid computing this, or at least only when combo is open
466- while (*p)
467- {
468- p += strlen (p) + 1 ;
469- items_count++;
470- }
471- bool value_changed = Combo (label, current_item, Items_SingleStringGetter, (void *)items_separated_by_zeros, items_count, height_in_items, show_arrow_down);
472- return value_changed;
473- }
0 commit comments