mirror of
				https://github.com/Drezil/imgui.git
				synced 2025-11-04 15:11:05 +01:00 
			
		
		
		
	Bullet(), BulletText(): vertical and horizontal alignment fixes (namely for widget sized line height). (followup to #414, #282)
This commit is contained in:
		
							
								
								
									
										25
									
								
								imgui.cpp
									
									
									
									
									
								
							
							
						
						
									
										25
									
								
								imgui.cpp
									
									
									
									
									
								
							@@ -5583,7 +5583,7 @@ bool ImGui::CollapsingHeader(const char* label, const char* str_id, bool display
 | 
			
		||||
    const ImVec2 label_size = CalcTextSize(label, NULL, true);
 | 
			
		||||
 | 
			
		||||
    // We vertically grow up to current line height up the typical widget height.
 | 
			
		||||
    const float text_base_offset_y = ImMax(0.0f, window->DC.CurrentLineTextBaseOffset - padding.y);
 | 
			
		||||
    const float text_base_offset_y = ImMax(0.0f, window->DC.CurrentLineTextBaseOffset - padding.y); // Latch before ItemSize changes it
 | 
			
		||||
    const float frame_height = ImMax(ImMin(window->DC.CurrentLineHeight, g.FontSize + g.Style.FramePadding.y*2), label_size.y + padding.y*2);
 | 
			
		||||
    ImRect bb = ImRect(window->DC.CursorPos, ImVec2(window->Pos.x + GetContentRegionMax().x, window->DC.CursorPos.y + frame_height));
 | 
			
		||||
    if (display_frame)
 | 
			
		||||
@@ -5657,21 +5657,21 @@ void ImGui::Bullet()
 | 
			
		||||
 | 
			
		||||
    ImGuiState& g = *GImGui;
 | 
			
		||||
    const ImGuiStyle& style = g.Style;
 | 
			
		||||
    const float line_height = g.FontSize;
 | 
			
		||||
    const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(line_height, line_height));
 | 
			
		||||
    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))
 | 
			
		||||
    {
 | 
			
		||||
        ImGui::SameLine(0, -1);
 | 
			
		||||
        ImGui::SameLine(0, style.FramePadding.x*2);
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Render
 | 
			
		||||
    const float bullet_size = line_height*0.15f;
 | 
			
		||||
    window->DrawList->AddCircleFilled(bb.Min + ImVec2(style.FramePadding.x + line_height*0.5f, line_height*0.5f), bullet_size, GetColorU32(ImGuiCol_Text));
 | 
			
		||||
    const float bullet_size = g.FontSize*0.15f;
 | 
			
		||||
    window->DrawList->AddCircleFilled(bb.Min + ImVec2(style.FramePadding.x + g.FontSize*0.5f, line_height*0.5f), bullet_size, GetColorU32(ImGuiCol_Text));
 | 
			
		||||
 | 
			
		||||
    // Stay on same line
 | 
			
		||||
    ImGui::SameLine(0, -1);
 | 
			
		||||
    ImGui::SameLine(0, style.FramePadding.x*2);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Text with a little bullet aligned to the typical tree node.
 | 
			
		||||
@@ -5686,17 +5686,18 @@ void ImGui::BulletTextV(const char* fmt, va_list args)
 | 
			
		||||
 | 
			
		||||
    const char* text_begin = g.TempBuffer;
 | 
			
		||||
    const char* text_end = text_begin + ImFormatStringV(g.TempBuffer, IM_ARRAYSIZE(g.TempBuffer), fmt, args);
 | 
			
		||||
    const float line_height = g.FontSize;
 | 
			
		||||
    const ImVec2 label_size = CalcTextSize(text_begin, text_end, true);
 | 
			
		||||
    const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(line_height + (label_size.x > 0.0f ? (style.FramePadding.x*2) : 0.0f),0) + label_size);  // Empty text doesn't add padding
 | 
			
		||||
    const float text_base_offset_y = ImMax(0.0f, window->DC.CurrentLineTextBaseOffset); // Latch before ItemSize changes it
 | 
			
		||||
    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))
 | 
			
		||||
        return;
 | 
			
		||||
 | 
			
		||||
    // Render
 | 
			
		||||
    const float bullet_size = line_height*0.15f;
 | 
			
		||||
    window->DrawList->AddCircleFilled(bb.Min + ImVec2(style.FramePadding.x + line_height*0.5f, line_height*0.5f), bullet_size, GetColorU32(ImGuiCol_Text));
 | 
			
		||||
    RenderText(bb.Min+ImVec2(g.FontSize + style.FramePadding.x*2,0), text_begin, text_end);
 | 
			
		||||
    const float bullet_size = g.FontSize*0.15f;
 | 
			
		||||
    window->DrawList->AddCircleFilled(bb.Min + ImVec2(style.FramePadding.x + g.FontSize*0.5f, line_height*0.5f), bullet_size, GetColorU32(ImGuiCol_Text));
 | 
			
		||||
    RenderText(bb.Min+ImVec2(g.FontSize + style.FramePadding.x*2, text_base_offset_y), text_begin, text_end);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ImGui::BulletText(const char* fmt, ...)
 | 
			
		||||
 
 | 
			
		||||
@@ -991,6 +991,15 @@ void ImGui::ShowTestWindow(bool* p_opened)
 | 
			
		||||
            ImGui::SameLine(0.0f, spacing); ImGui::Button("Button##2");
 | 
			
		||||
            if (tree_opened) { for (int i = 0; i < 6; i++) ImGui::BulletText("Item %d..", i); ImGui::TreePop(); }   // Dummy tree data
 | 
			
		||||
 | 
			
		||||
            // Bullet
 | 
			
		||||
            ImGui::Button("Button##3"); 
 | 
			
		||||
            ImGui::SameLine(0.0f, spacing); 
 | 
			
		||||
            ImGui::BulletText("Bullet text");
 | 
			
		||||
 | 
			
		||||
            ImGui::AlignFirstTextHeightToWidgets();
 | 
			
		||||
            ImGui::BulletText("Node");
 | 
			
		||||
            ImGui::SameLine(0.0f, spacing); ImGui::Button("Button##4");
 | 
			
		||||
 | 
			
		||||
            ImGui::TreePop();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -2261,6 +2270,7 @@ static void ShowExampleAppPropertyEditor(bool* opened)
 | 
			
		||||
                        //ImGui::Text("Field_%d", i);
 | 
			
		||||
                        char label[32];
 | 
			
		||||
                        sprintf(label, "Field_%d", i);
 | 
			
		||||
                        ImGui::Bullet();
 | 
			
		||||
                        ImGui::Selectable(label);
 | 
			
		||||
                        ImGui::NextColumn();
 | 
			
		||||
                        ImGui::PushItemWidth(-1);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user