mirror of
				https://github.com/Drezil/imgui.git
				synced 2025-10-31 13:11:05 +01:00 
			
		
		
		
	Internal: ItemAdd(), IsClippedEx(): removed unnecessary indirection for ID parameter
This commit is contained in:
		
							
								
								
									
										64
									
								
								imgui.cpp
									
									
									
									
									
								
							
							
						
						
									
										64
									
								
								imgui.cpp
									
									
									
									
									
								
							| @@ -1969,12 +1969,12 @@ void ImGui::ItemSize(const ImRect& bb, float text_offset_y) | ||||
| // Declare item bounding box for clipping and interaction. | ||||
| // Note that the size can be different than the one provided to ItemSize(). Typically, widgets that spread over available surface | ||||
| // declares their minimum size requirement to ItemSize() and then use a larger region for drawing/interaction, which is passed to ItemAdd(). | ||||
| bool ImGui::ItemAdd(const ImRect& bb, const ImGuiID* id) | ||||
| bool ImGui::ItemAdd(const ImRect& bb, ImGuiID id) | ||||
| { | ||||
|     ImGuiContext& g = *GImGui; | ||||
|     ImGuiWindow* window = g.CurrentWindow; | ||||
|     const bool is_clipped = IsClippedEx(bb, id, false); | ||||
|     window->DC.LastItemId = id ? *id : 0; | ||||
|     window->DC.LastItemId = id; | ||||
|     window->DC.LastItemRect = bb; | ||||
|     window->DC.LastItemRectHoveredRect = false; | ||||
|     if (is_clipped) | ||||
| @@ -2031,12 +2031,12 @@ bool ImGui::ItemHoverable(const ImRect& bb, ImGuiID id) | ||||
|     return true; | ||||
| } | ||||
|  | ||||
| bool ImGui::IsClippedEx(const ImRect& bb, const ImGuiID* id, bool clip_even_when_logged) | ||||
| bool ImGui::IsClippedEx(const ImRect& bb, ImGuiID id, bool clip_even_when_logged) | ||||
| { | ||||
|     ImGuiContext& g = *GImGui; | ||||
|     ImGuiWindow* window = g.CurrentWindow; | ||||
|     if (!bb.Overlaps(window->ClipRect)) | ||||
|         if (!id || *id != g.ActiveId) | ||||
|         if (id == 0 || id != g.ActiveId) | ||||
|             if (clip_even_when_logged || !g.LogEnabled) | ||||
|                 return true; | ||||
|     return false; | ||||
| @@ -3790,7 +3790,7 @@ void ImGui::EndChild() | ||||
|         ImGuiWindow* parent_window = GetCurrentWindow(); | ||||
|         ImRect bb(parent_window->DC.CursorPos, parent_window->DC.CursorPos + sz); | ||||
|         ItemSize(sz); | ||||
|         ItemAdd(bb, NULL); | ||||
|         ItemAdd(bb, 0); | ||||
|     } | ||||
| } | ||||
|  | ||||
| @@ -5598,7 +5598,7 @@ void ImGui::TextUnformatted(const char* text, const char* text_end) | ||||
|                 while (line < text_end) | ||||
|                 { | ||||
|                     const char* line_end = strchr(line, '\n'); | ||||
|                     if (IsClippedEx(line_rect, NULL, false)) | ||||
|                     if (IsClippedEx(line_rect, 0, false)) | ||||
|                         break; | ||||
|  | ||||
|                     const ImVec2 line_size = CalcTextSize(line, line_end, false); | ||||
| @@ -5630,7 +5630,7 @@ void ImGui::TextUnformatted(const char* text, const char* text_end) | ||||
|  | ||||
|         ImRect bb(text_pos, text_pos + text_size); | ||||
|         ItemSize(bb); | ||||
|         ItemAdd(bb, NULL); | ||||
|         ItemAdd(bb, 0); | ||||
|     } | ||||
|     else | ||||
|     { | ||||
| @@ -5640,7 +5640,7 @@ void ImGui::TextUnformatted(const char* text, const char* text_end) | ||||
|         // Account of baseline offset | ||||
|         ImRect bb(text_pos, text_pos + text_size); | ||||
|         ItemSize(text_size); | ||||
|         if (!ItemAdd(bb, NULL)) | ||||
|         if (!ItemAdd(bb, 0)) | ||||
|             return; | ||||
|  | ||||
|         // Render (we don't hide text after ## in this end-user function) | ||||
| @@ -5674,7 +5674,7 @@ void ImGui::LabelTextV(const char* label, const char* fmt, va_list args) | ||||
|     const ImRect value_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y + style.FramePadding.y*2)); | ||||
|     const ImRect total_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w + (label_size.x > 0.0f ? style.ItemInnerSpacing.x : 0.0f), style.FramePadding.y*2) + label_size); | ||||
|     ItemSize(total_bb, style.FramePadding.y); | ||||
|     if (!ItemAdd(total_bb, NULL)) | ||||
|     if (!ItemAdd(total_bb, 0)) | ||||
|         return; | ||||
|  | ||||
|     // Render | ||||
| @@ -5799,7 +5799,7 @@ bool ImGui::ButtonEx(const char* label, const ImVec2& size_arg, ImGuiButtonFlags | ||||
|  | ||||
|     const ImRect bb(pos, pos + size); | ||||
|     ItemSize(bb, style.FramePadding.y); | ||||
|     if (!ItemAdd(bb, &id)) | ||||
|     if (!ItemAdd(bb, id)) | ||||
|         return false; | ||||
|  | ||||
|     if (window->DC.ItemFlags & ImGuiItemFlags_ButtonRepeat) flags |= ImGuiButtonFlags_Repeat; | ||||
| @@ -5846,7 +5846,7 @@ bool ImGui::InvisibleButton(const char* str_id, const ImVec2& size_arg) | ||||
|     ImVec2 size = CalcItemSize(size_arg, 0.0f, 0.0f); | ||||
|     const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + size); | ||||
|     ItemSize(bb); | ||||
|     if (!ItemAdd(bb, &id)) | ||||
|     if (!ItemAdd(bb, id)) | ||||
|         return false; | ||||
|  | ||||
|     bool hovered, held; | ||||
| @@ -5890,7 +5890,7 @@ void ImGui::Image(ImTextureID user_texture_id, const ImVec2& size, const ImVec2& | ||||
|     if (border_col.w > 0.0f) | ||||
|         bb.Max += ImVec2(2,2); | ||||
|     ItemSize(bb); | ||||
|     if (!ItemAdd(bb, NULL)) | ||||
|     if (!ItemAdd(bb, 0)) | ||||
|         return; | ||||
|  | ||||
|     if (border_col.w > 0.0f) | ||||
| @@ -5927,7 +5927,7 @@ bool ImGui::ImageButton(ImTextureID user_texture_id, const ImVec2& size, const I | ||||
|     const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + size + padding*2); | ||||
|     const ImRect image_bb(window->DC.CursorPos + padding, window->DC.CursorPos + padding + size); | ||||
|     ItemSize(bb); | ||||
|     if (!ItemAdd(bb, &id)) | ||||
|     if (!ItemAdd(bb, id)) | ||||
|         return false; | ||||
|  | ||||
|     bool hovered, held; | ||||
| @@ -6129,7 +6129,7 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* l | ||||
|     // (Ideally we'd want to add a flag for the user to specify we want want the hit test to be done up to the right side of the content or not) | ||||
|     const ImRect interact_bb = display_frame ? bb : ImRect(bb.Min.x, bb.Min.y, bb.Min.x + text_width + style.ItemSpacing.x*2, bb.Max.y); | ||||
|     bool is_open = TreeNodeBehaviorIsOpen(id, flags); | ||||
|     if (!ItemAdd(interact_bb, &id)) | ||||
|     if (!ItemAdd(interact_bb, id)) | ||||
|     { | ||||
|         if (is_open && !(flags & ImGuiTreeNodeFlags_NoTreePushOnOpen)) | ||||
|             TreePushRawID(id); | ||||
| @@ -6399,7 +6399,7 @@ void ImGui::Bullet() | ||||
|     const float line_height = ImMax(ImMin(window->DC.CurrentLineHeight, g.FontSize + g.Style.FramePadding.y*2), g.FontSize); | ||||
|     const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(g.FontSize, line_height)); | ||||
|     ItemSize(bb); | ||||
|     if (!ItemAdd(bb, NULL)) | ||||
|     if (!ItemAdd(bb, 0)) | ||||
|     { | ||||
|         SameLine(0, style.FramePadding.x*2); | ||||
|         return; | ||||
| @@ -6427,7 +6427,7 @@ void ImGui::BulletTextV(const char* fmt, va_list args) | ||||
|     const float line_height = ImMax(ImMin(window->DC.CurrentLineHeight, g.FontSize + g.Style.FramePadding.y*2), g.FontSize); | ||||
|     const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(g.FontSize + (label_size.x > 0.0f ? (label_size.x + style.FramePadding.x*2) : 0.0f), ImMax(line_height, label_size.y)));  // Empty text doesn't add padding | ||||
|     ItemSize(bb); | ||||
|     if (!ItemAdd(bb, NULL)) | ||||
|     if (!ItemAdd(bb, 0)) | ||||
|         return; | ||||
|  | ||||
|     // Render | ||||
| @@ -6783,7 +6783,7 @@ bool ImGui::SliderFloat(const char* label, float* v, float v_min, float v_max, c | ||||
|     const ImRect total_bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0.0f)); | ||||
|  | ||||
|     // NB- we don't call ItemSize() yet because we may turn into a text edit box below | ||||
|     if (!ItemAdd(total_bb, &id)) | ||||
|     if (!ItemAdd(total_bb, id)) | ||||
|     { | ||||
|         ItemSize(total_bb, style.FramePadding.y); | ||||
|         return false; | ||||
| @@ -6840,7 +6840,7 @@ bool ImGui::VSliderFloat(const char* label, const ImVec2& size, float* v, float | ||||
|     const ImRect bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0.0f)); | ||||
|  | ||||
|     ItemSize(bb, style.FramePadding.y); | ||||
|     if (!ItemAdd(frame_bb, &id)) | ||||
|     if (!ItemAdd(frame_bb, id)) | ||||
|         return false; | ||||
|     const bool hovered = ItemHoverable(frame_bb, id); | ||||
|  | ||||
| @@ -7078,7 +7078,7 @@ bool ImGui::DragFloat(const char* label, float* v, float v_speed, float v_min, f | ||||
|     const ImRect total_bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0.0f)); | ||||
|  | ||||
|     // NB- we don't call ItemSize() yet because we may turn into a text edit box below | ||||
|     if (!ItemAdd(total_bb, &id)) | ||||
|     if (!ItemAdd(total_bb, id)) | ||||
|     { | ||||
|         ItemSize(total_bb, style.FramePadding.y); | ||||
|         return false; | ||||
| @@ -7284,7 +7284,7 @@ void ImGui::PlotEx(ImGuiPlotType plot_type, const char* label, float (*values_ge | ||||
|     const ImRect inner_bb(frame_bb.Min + style.FramePadding, frame_bb.Max - style.FramePadding); | ||||
|     const ImRect total_bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0)); | ||||
|     ItemSize(total_bb, style.FramePadding.y); | ||||
|     if (!ItemAdd(total_bb, NULL)) | ||||
|     if (!ItemAdd(total_bb, 0)) | ||||
|         return; | ||||
|     const bool hovered = ItemHoverable(inner_bb, 0); | ||||
|  | ||||
| @@ -7424,7 +7424,7 @@ void ImGui::ProgressBar(float fraction, const ImVec2& size_arg, const char* over | ||||
|     ImVec2 pos = window->DC.CursorPos; | ||||
|     ImRect bb(pos, pos + CalcItemSize(size_arg, CalcItemWidth(), g.FontSize + style.FramePadding.y*2.0f)); | ||||
|     ItemSize(bb, style.FramePadding.y); | ||||
|     if (!ItemAdd(bb, NULL)) | ||||
|     if (!ItemAdd(bb, 0)) | ||||
|         return; | ||||
|  | ||||
|     // Render | ||||
| @@ -7471,7 +7471,7 @@ bool ImGui::Checkbox(const char* label, bool* v) | ||||
|         total_bb = ImRect(ImMin(check_bb.Min, text_bb.Min), ImMax(check_bb.Max, text_bb.Max)); | ||||
|     } | ||||
|  | ||||
|     if (!ItemAdd(total_bb, &id)) | ||||
|     if (!ItemAdd(total_bb, id)) | ||||
|         return false; | ||||
|  | ||||
|     bool hovered, held; | ||||
| @@ -7534,7 +7534,7 @@ bool ImGui::RadioButton(const char* label, bool active) | ||||
|         total_bb.Add(text_bb); | ||||
|     } | ||||
|  | ||||
|     if (!ItemAdd(total_bb, &id)) | ||||
|     if (!ItemAdd(total_bb, id)) | ||||
|         return false; | ||||
|  | ||||
|     ImVec2 center = check_bb.GetCenter(); | ||||
| @@ -7872,7 +7872,7 @@ bool ImGui::InputTextEx(const char* label, char* buf, int buf_size, const ImVec2 | ||||
|     else | ||||
|     { | ||||
|         ItemSize(total_bb, style.FramePadding.y); | ||||
|         if (!ItemAdd(total_bb, &id)) | ||||
|         if (!ItemAdd(total_bb, id)) | ||||
|             return false; | ||||
|     } | ||||
|     const bool hovered = ItemHoverable(frame_bb, id); | ||||
| @@ -8657,7 +8657,7 @@ bool ImGui::BeginCombo(const char* label, const char* preview_value, ImVec2 popu | ||||
|     const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y + style.FramePadding.y*2.0f)); | ||||
|     const ImRect total_bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0.0f)); | ||||
|     ItemSize(total_bb, style.FramePadding.y); | ||||
|     if (!ItemAdd(total_bb, &id)) | ||||
|     if (!ItemAdd(total_bb, id)) | ||||
|         return false; | ||||
|  | ||||
|     const float arrow_size = SmallSquareSize(); | ||||
| @@ -8806,7 +8806,7 @@ bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags fl | ||||
|     bb_with_spacing.Min.y -= spacing_U; | ||||
|     bb_with_spacing.Max.x += spacing_R; | ||||
|     bb_with_spacing.Max.y += spacing_D; | ||||
|     if (!ItemAdd(bb_with_spacing, &id)) | ||||
|     if (!ItemAdd(bb_with_spacing, id)) | ||||
|     { | ||||
|         if ((flags & ImGuiSelectableFlags_SpanAllColumns) && window->DC.ColumnsCount > 1) | ||||
|             PushColumnClipRect(); | ||||
| @@ -9271,7 +9271,7 @@ bool ImGui::ColorButton(const char* desc_id, const ImVec4& col, ImGuiColorEditFl | ||||
|         size.y = default_size; | ||||
|     const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + size); | ||||
|     ItemSize(bb); | ||||
|     if (!ItemAdd(bb, &id)) | ||||
|     if (!ItemAdd(bb, id)) | ||||
|         return false; | ||||
|  | ||||
|     bool hovered, held; | ||||
| @@ -9940,7 +9940,7 @@ void ImGui::Separator() | ||||
|  | ||||
|     const ImRect bb(ImVec2(x1, window->DC.CursorPos.y), ImVec2(x2, window->DC.CursorPos.y+1.0f)); | ||||
|     ItemSize(ImVec2(0.0f, 0.0f)); // NB: we don't provide our width so that it doesn't get feed back into AutoFit, we don't provide height to not alter layout. | ||||
|     if (!ItemAdd(bb, NULL)) | ||||
|     if (!ItemAdd(bb, 0)) | ||||
|     { | ||||
|         if (window->DC.ColumnsCount > 1) | ||||
|             PushColumnClipRect(); | ||||
| @@ -9970,7 +9970,7 @@ void ImGui::VerticalSeparator() | ||||
|     float y2 = window->DC.CursorPos.y + window->DC.CurrentLineHeight;  | ||||
|     const ImRect bb(ImVec2(window->DC.CursorPos.x, y1), ImVec2(window->DC.CursorPos.x + 1.0f, y2)); | ||||
|     ItemSize(ImVec2(bb.GetWidth(), 0.0f)); | ||||
|     if (!ItemAdd(bb, NULL)) | ||||
|     if (!ItemAdd(bb, 0)) | ||||
|         return; | ||||
|  | ||||
|     window->DrawList->AddLine(ImVec2(bb.Min.x, bb.Min.y), ImVec2(bb.Min.x, bb.Max.y), GetColorU32(ImGuiCol_Separator)); | ||||
| @@ -9994,7 +9994,7 @@ void ImGui::Dummy(const ImVec2& size) | ||||
|  | ||||
|     const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + size); | ||||
|     ItemSize(bb); | ||||
|     ItemAdd(bb, NULL); | ||||
|     ItemAdd(bb, 0); | ||||
| } | ||||
|  | ||||
| bool ImGui::IsRectVisible(const ImVec2& size) | ||||
| @@ -10058,7 +10058,7 @@ void ImGui::EndGroup() | ||||
|     { | ||||
|         window->DC.CurrentLineTextBaseOffset = ImMax(window->DC.PrevLineTextBaseOffset, group_data.BackupCurrentLineTextBaseOffset);      // FIXME: Incorrect, we should grab the base offset from the *first line* of the group but it is hard to obtain now. | ||||
|         ItemSize(group_bb.GetSize(), group_data.BackupCurrentLineTextBaseOffset); | ||||
|         ItemAdd(group_bb, NULL); | ||||
|         ItemAdd(group_bb, 0); | ||||
|     } | ||||
|  | ||||
|     // If the current ActiveId was declared within the boundary of our group, we copy it to LastItemId so IsItemActive() will be functional on the entire group. | ||||
| @@ -10344,7 +10344,7 @@ void ImGui::EndColumns() | ||||
|             const ImGuiID column_id = window->DC.ColumnsSetId + ImGuiID(i); | ||||
|             const float column_w = 4.0f; // Width for interaction | ||||
|             const ImRect column_rect(ImVec2(x - column_w, y1), ImVec2(x + column_w, y2)); | ||||
|             if (IsClippedEx(column_rect, &column_id, false)) | ||||
|             if (IsClippedEx(column_rect, column_id, false)) | ||||
|                 continue; | ||||
|              | ||||
|             bool hovered = false, held = false; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user