mirror of
				https://github.com/Drezil/imgui.git
				synced 2025-11-04 07:01:04 +01:00 
			
		
		
		
	Style: Added ButtonTextAlign, ImGuiStyleVar_ButtonTextAlign (#842)
This commit is contained in:
		
							
								
								
									
										10
									
								
								imgui.cpp
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								imgui.cpp
									
									
									
									
									
								
							@@ -743,6 +743,7 @@ ImGuiStyle::ImGuiStyle()
 | 
			
		||||
    ScrollbarRounding       = 9.0f;             // Radius of grab corners rounding for scrollbar
 | 
			
		||||
    GrabMinSize             = 10.0f;            // Minimum width/height of a grab box for slider/scrollbar
 | 
			
		||||
    GrabRounding            = 0.0f;             // Radius of grabs corners rounding. Set to 0.0f to have rectangular slider grabs.
 | 
			
		||||
    ButtonTextAlign         = ImVec2(0.5f,0.5f);// Alignment of button text when button is larger than text.
 | 
			
		||||
    DisplayWindowPadding    = ImVec2(22,22);    // Window positions are clamped to be visible within the display area by at least this amount. Only covers regular windows.
 | 
			
		||||
    DisplaySafeAreaPadding  = ImVec2(4,4);      // If you cannot see the edge of your screen (e.g. on a TV) increase the safe area padding. Covers popups/tooltips as well regular windows.
 | 
			
		||||
    AntiAliasedLines        = true;             // Enable anti-aliasing on lines/borders. Disable if you are really short on CPU/GPU.
 | 
			
		||||
@@ -2890,7 +2891,7 @@ void ImGui::RenderTextClipped(const ImVec2& pos_min, const ImVec2& pos_max, cons
 | 
			
		||||
    if (clip_rect) // If we had no explicit clipping rectangle then pos==clip_min
 | 
			
		||||
        need_clipping |= (pos.x < clip_min->x) || (pos.y < clip_min->y);
 | 
			
		||||
 | 
			
		||||
    // Align whole block (we should defer that to the better rendering function
 | 
			
		||||
    // Align whole block. We should defer that to the better rendering function when we'll have support for individual line alignment.
 | 
			
		||||
    if (align.x > 0.0f) pos.x = ImMax(pos.x, pos.x + (pos_max.x - pos.x - text_size.x) * align.x);
 | 
			
		||||
    if (align.y > 0.0f) pos.y = ImMax(pos.y, pos.y + (pos_max.y - pos.y - text_size.y) * align.y);
 | 
			
		||||
 | 
			
		||||
@@ -4686,6 +4687,7 @@ static const ImGuiStyleVarInfo GStyleVarInfo[ImGuiStyleVar_Count_] =
 | 
			
		||||
    { ImGuiDataType_Float2, (ImU32)IM_OFFSETOF(ImGuiStyle, ItemInnerSpacing) },
 | 
			
		||||
    { ImGuiDataType_Float,  (ImU32)IM_OFFSETOF(ImGuiStyle, IndentSpacing) },
 | 
			
		||||
    { ImGuiDataType_Float,  (ImU32)IM_OFFSETOF(ImGuiStyle, GrabMinSize) },
 | 
			
		||||
    { ImGuiDataType_Float2, (ImU32)IM_OFFSETOF(ImGuiStyle, ButtonTextAlign) },
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static const ImGuiStyleVarInfo* GetStyleVarInfo(ImGuiStyleVar idx)
 | 
			
		||||
@@ -5583,7 +5585,7 @@ bool ImGui::ButtonEx(const char* label, const ImVec2& size_arg, ImGuiButtonFlags
 | 
			
		||||
    // Render
 | 
			
		||||
    const ImU32 col = GetColorU32((hovered && held) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button);
 | 
			
		||||
    RenderFrame(bb.Min, bb.Max, col, true, style.FrameRounding);
 | 
			
		||||
    RenderTextClipped(bb.Min, bb.Max, label, NULL, &label_size, style.ButtonTextAlign);
 | 
			
		||||
    RenderTextClipped(bb.Min + style.FramePadding, bb.Max - style.FramePadding, label, NULL, &label_size, style.ButtonTextAlign, &bb);
 | 
			
		||||
 | 
			
		||||
    // Automatically close popups
 | 
			
		||||
    //if (pressed && !(flags & ImGuiButtonFlags_DontClosePopups) && (window->Flags & ImGuiWindowFlags_Popup))
 | 
			
		||||
@@ -5950,12 +5952,12 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* l
 | 
			
		||||
            const char log_prefix[] = "\n##";
 | 
			
		||||
            const char log_suffix[] = "##";
 | 
			
		||||
            LogRenderedText(text_pos, log_prefix, log_prefix+3);
 | 
			
		||||
            RenderTextClipped(text_pos, bb.Max, label, label_end, &label_size, ImVec2(0.0f,0.0f));
 | 
			
		||||
            RenderTextClipped(text_pos, bb.Max, label, label_end, &label_size);
 | 
			
		||||
            LogRenderedText(text_pos, log_suffix+1, log_suffix+3);
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            RenderTextClipped(text_pos, bb.Max, label, label_end, &label_size, ImVec2(0.0f,0.0f));
 | 
			
		||||
            RenderTextClipped(text_pos, bb.Max, label, label_end, &label_size);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user