mirror of
				https://github.com/Drezil/imgui.git
				synced 2025-11-04 15:11:05 +01:00 
			
		
		
		
	Combo, Inputint, InputFloat, ColorEdit4 all use the small size for little square
This commit is contained in:
		
							
								
								
									
										30
									
								
								imgui.cpp
									
									
									
									
									
								
							
							
						
						
									
										30
									
								
								imgui.cpp
									
									
									
									
									
								
							@@ -8253,6 +8253,12 @@ bool ImGui::InputTextMultiline(const char* label, char* buf, size_t buf_size, co
 | 
				
			|||||||
    return InputTextEx(label, buf, (int)buf_size, size, flags | ImGuiInputTextFlags_Multiline, callback, user_data);
 | 
					    return InputTextEx(label, buf, (int)buf_size, size, flags | ImGuiInputTextFlags_Multiline, callback, user_data);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static inline float SmallSquareSize()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    ImGuiContext& g = *GImGui;
 | 
				
			||||||
 | 
					    return g.FontSize + g.Style.FramePadding.y * 2.0f;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// NB: scalar_format here must be a simple "%xx" format string with no prefix/suffix (unlike the Drag/Slider functions "display_format" argument)
 | 
					// NB: scalar_format here must be a simple "%xx" format string with no prefix/suffix (unlike the Drag/Slider functions "display_format" argument)
 | 
				
			||||||
bool ImGui::InputScalarEx(const char* label, ImGuiDataType data_type, void* data_ptr, void* step_ptr, void* step_fast_ptr, const char* scalar_format, ImGuiInputTextFlags extra_flags)
 | 
					bool ImGui::InputScalarEx(const char* label, ImGuiDataType data_type, void* data_ptr, void* step_ptr, void* step_fast_ptr, const char* scalar_format, ImGuiInputTextFlags extra_flags)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@@ -8266,7 +8272,7 @@ bool ImGui::InputScalarEx(const char* label, ImGuiDataType data_type, void* data
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    BeginGroup();
 | 
					    BeginGroup();
 | 
				
			||||||
    PushID(label);
 | 
					    PushID(label);
 | 
				
			||||||
    const ImVec2 button_sz = ImVec2(g.FontSize, g.FontSize) + style.FramePadding*2.0f;
 | 
					    const ImVec2 button_sz = ImVec2(SmallSquareSize(), SmallSquareSize());
 | 
				
			||||||
    if (step_ptr)
 | 
					    if (step_ptr)
 | 
				
			||||||
        PushItemWidth(ImMax(1.0f, CalcItemWidth() - (button_sz.x + style.ItemInnerSpacing.x)*2));
 | 
					        PushItemWidth(ImMax(1.0f, CalcItemWidth() - (button_sz.x + style.ItemInnerSpacing.x)*2));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -8481,7 +8487,7 @@ bool ImGui::Combo(const char* label, int* current_item, bool (*items_getter)(voi
 | 
				
			|||||||
    if (!ItemAdd(total_bb, &id))
 | 
					    if (!ItemAdd(total_bb, &id))
 | 
				
			||||||
        return false;
 | 
					        return false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const float arrow_size = (g.FontSize + style.FramePadding.x * 2.0f);
 | 
					    const float arrow_size = SmallSquareSize();
 | 
				
			||||||
    const bool hovered = IsHovered(frame_bb, id);
 | 
					    const bool hovered = IsHovered(frame_bb, id);
 | 
				
			||||||
    bool popup_open = IsPopupOpen(id);
 | 
					    bool popup_open = IsPopupOpen(id);
 | 
				
			||||||
    bool popup_opened_now = false;
 | 
					    bool popup_opened_now = false;
 | 
				
			||||||
@@ -8489,7 +8495,7 @@ bool ImGui::Combo(const char* label, int* current_item, bool (*items_getter)(voi
 | 
				
			|||||||
    const ImRect value_bb(frame_bb.Min, frame_bb.Max - ImVec2(arrow_size, 0.0f));
 | 
					    const ImRect value_bb(frame_bb.Min, frame_bb.Max - ImVec2(arrow_size, 0.0f));
 | 
				
			||||||
    RenderFrame(frame_bb.Min, frame_bb.Max, GetColorU32(ImGuiCol_FrameBg), true, style.FrameRounding);
 | 
					    RenderFrame(frame_bb.Min, frame_bb.Max, GetColorU32(ImGuiCol_FrameBg), true, style.FrameRounding);
 | 
				
			||||||
    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
 | 
					    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
 | 
				
			||||||
    RenderCollapseTriangle(ImVec2(frame_bb.Max.x-arrow_size, frame_bb.Min.y) + style.FramePadding, true);
 | 
					    RenderCollapseTriangle(ImVec2(frame_bb.Max.x - arrow_size + style.FramePadding.y, frame_bb.Min.y + style.FramePadding.y), true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (*current_item >= 0 && *current_item < items_count)
 | 
					    if (*current_item >= 0 && *current_item < items_count)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
@@ -8988,12 +8994,6 @@ void ImGui::ColorTooltip(const char* text, const float col[4], ImGuiColorEditFla
 | 
				
			|||||||
    EndTooltip();
 | 
					    EndTooltip();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static inline float ColorSquareSize()
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    ImGuiContext& g = *GImGui;
 | 
					 | 
				
			||||||
    return g.FontSize + g.Style.FramePadding.y * 2.0f;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static inline ImU32 ImAlphaBlendColor(ImU32 col_a, ImU32 col_b)
 | 
					static inline ImU32 ImAlphaBlendColor(ImU32 col_a, ImU32 col_b)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    float t = ((col_b >> IM_COL32_A_SHIFT) & 0xFF) / 255.f;
 | 
					    float t = ((col_b >> IM_COL32_A_SHIFT) & 0xFF) / 255.f;
 | 
				
			||||||
@@ -9065,7 +9065,7 @@ bool ImGui::ColorButton(const char* desc_id, const ImVec4& col, ImGuiColorEditFl
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    ImGuiContext& g = *GImGui;
 | 
					    ImGuiContext& g = *GImGui;
 | 
				
			||||||
    const ImGuiID id = window->GetID(desc_id);
 | 
					    const ImGuiID id = window->GetID(desc_id);
 | 
				
			||||||
    float default_size = ColorSquareSize();
 | 
					    float default_size = SmallSquareSize();
 | 
				
			||||||
    if (size.x == 0.0f)
 | 
					    if (size.x == 0.0f)
 | 
				
			||||||
        size.x = default_size;
 | 
					        size.x = default_size;
 | 
				
			||||||
    if (size.y == 0.0f)
 | 
					    if (size.y == 0.0f)
 | 
				
			||||||
@@ -9143,7 +9143,7 @@ static void ColorPickerOptionsPopup(ImGuiColorEditFlags flags, float* ref_col)
 | 
				
			|||||||
    ImGuiContext& g = *GImGui;
 | 
					    ImGuiContext& g = *GImGui;
 | 
				
			||||||
    if (allow_opt_picker)
 | 
					    if (allow_opt_picker)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        ImVec2 picker_size(g.FontSize * 8, ImMax(g.FontSize * 8 - (ColorSquareSize() + g.Style.ItemInnerSpacing.x), 1.0f)); // FIXME: Picker size copied from main picker function
 | 
					        ImVec2 picker_size(g.FontSize * 8, ImMax(g.FontSize * 8 - (SmallSquareSize() + g.Style.ItemInnerSpacing.x), 1.0f)); // FIXME: Picker size copied from main picker function
 | 
				
			||||||
        ImGui::PushItemWidth(picker_size.x);
 | 
					        ImGui::PushItemWidth(picker_size.x);
 | 
				
			||||||
        for (int picker_type = 0; picker_type < 2; picker_type++)
 | 
					        for (int picker_type = 0; picker_type < 2; picker_type++)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
@@ -9183,7 +9183,8 @@ bool ImGui::ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flag
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    ImGuiContext& g = *GImGui;
 | 
					    ImGuiContext& g = *GImGui;
 | 
				
			||||||
    const ImGuiStyle& style = g.Style;
 | 
					    const ImGuiStyle& style = g.Style;
 | 
				
			||||||
    const float w_extra = (flags & ImGuiColorEditFlags_NoSmallPreview) ? 0.0f : (ColorSquareSize() + style.ItemInnerSpacing.x);
 | 
					    const float square_sz = SmallSquareSize();
 | 
				
			||||||
 | 
					    const float w_extra = (flags & ImGuiColorEditFlags_NoSmallPreview) ? 0.0f : (square_sz + style.ItemInnerSpacing.x);
 | 
				
			||||||
    const float w_items_all = CalcItemWidth() - w_extra;
 | 
					    const float w_items_all = CalcItemWidth() - w_extra;
 | 
				
			||||||
    const char* label_display_end = FindRenderedTextEnd(label);
 | 
					    const char* label_display_end = FindRenderedTextEnd(label);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -9314,7 +9315,6 @@ bool ImGui::ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flag
 | 
				
			|||||||
                TextUnformatted(label, label_display_end);
 | 
					                TextUnformatted(label, label_display_end);
 | 
				
			||||||
                Separator();
 | 
					                Separator();
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            float square_sz = ColorSquareSize();
 | 
					 | 
				
			||||||
            ImGuiColorEditFlags picker_flags_to_forward = ImGuiColorEditFlags__DataTypeMask | ImGuiColorEditFlags__PickerMask | ImGuiColorEditFlags_HDR | ImGuiColorEditFlags_NoAlpha | ImGuiColorEditFlags_AlphaBar;
 | 
					            ImGuiColorEditFlags picker_flags_to_forward = ImGuiColorEditFlags__DataTypeMask | ImGuiColorEditFlags__PickerMask | ImGuiColorEditFlags_HDR | ImGuiColorEditFlags_NoAlpha | ImGuiColorEditFlags_AlphaBar;
 | 
				
			||||||
            ImGuiColorEditFlags picker_flags = (flags_untouched & picker_flags_to_forward) | ImGuiColorEditFlags__InputsMask | ImGuiColorEditFlags_NoLabel | ImGuiColorEditFlags_AlphaPreviewHalf;
 | 
					            ImGuiColorEditFlags picker_flags = (flags_untouched & picker_flags_to_forward) | ImGuiColorEditFlags__InputsMask | ImGuiColorEditFlags_NoLabel | ImGuiColorEditFlags_AlphaPreviewHalf;
 | 
				
			||||||
            PushItemWidth(square_sz * 12.0f); // Use 256 + bar sizes?
 | 
					            PushItemWidth(square_sz * 12.0f); // Use 256 + bar sizes?
 | 
				
			||||||
@@ -9431,7 +9431,8 @@ bool ImGui::ColorPicker4(const char* label, float col[4], ImGuiColorEditFlags fl
 | 
				
			|||||||
    // Setup
 | 
					    // Setup
 | 
				
			||||||
    bool alpha_bar = (flags & ImGuiColorEditFlags_AlphaBar) && !(flags & ImGuiColorEditFlags_NoAlpha);
 | 
					    bool alpha_bar = (flags & ImGuiColorEditFlags_AlphaBar) && !(flags & ImGuiColorEditFlags_NoAlpha);
 | 
				
			||||||
    ImVec2 picker_pos = window->DC.CursorPos;
 | 
					    ImVec2 picker_pos = window->DC.CursorPos;
 | 
				
			||||||
    float bars_width = ColorSquareSize(); // Arbitrary smallish width of Hue/Alpha picking bars
 | 
					    float square_sz = SmallSquareSize();
 | 
				
			||||||
 | 
					    float bars_width = square_sz; // Arbitrary smallish width of Hue/Alpha picking bars
 | 
				
			||||||
    float sv_picker_size = ImMax(bars_width * 1, CalcItemWidth() - (alpha_bar ? 2 : 1) * (bars_width + style.ItemInnerSpacing.x)); // Saturation/Value picking box
 | 
					    float sv_picker_size = ImMax(bars_width * 1, CalcItemWidth() - (alpha_bar ? 2 : 1) * (bars_width + style.ItemInnerSpacing.x)); // Saturation/Value picking box
 | 
				
			||||||
    float bar0_pos_x = picker_pos.x + sv_picker_size + style.ItemInnerSpacing.x;
 | 
					    float bar0_pos_x = picker_pos.x + sv_picker_size + style.ItemInnerSpacing.x;
 | 
				
			||||||
    float bar1_pos_x = bar0_pos_x + bars_width + style.ItemInnerSpacing.x;
 | 
					    float bar1_pos_x = bar0_pos_x + bars_width + style.ItemInnerSpacing.x;
 | 
				
			||||||
@@ -9543,7 +9544,6 @@ bool ImGui::ColorPicker4(const char* label, float col[4], ImGuiColorEditFlags fl
 | 
				
			|||||||
    if (!(flags & ImGuiColorEditFlags_NoSidePreview))
 | 
					    if (!(flags & ImGuiColorEditFlags_NoSidePreview))
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        ImVec4 col_v4(col[0], col[1], col[2], (flags & ImGuiColorEditFlags_NoAlpha) ? 1.0f : col[3]);
 | 
					        ImVec4 col_v4(col[0], col[1], col[2], (flags & ImGuiColorEditFlags_NoAlpha) ? 1.0f : col[3]);
 | 
				
			||||||
        float square_sz = ColorSquareSize();
 | 
					 | 
				
			||||||
        if ((flags & ImGuiColorEditFlags_NoLabel))
 | 
					        if ((flags & ImGuiColorEditFlags_NoLabel))
 | 
				
			||||||
            Text("Current");
 | 
					            Text("Current");
 | 
				
			||||||
        ColorButton("##current", col_v4, (flags & (ImGuiColorEditFlags_HDR|ImGuiColorEditFlags_AlphaPreview|ImGuiColorEditFlags_AlphaPreviewHalf|ImGuiColorEditFlags_NoTooltip)), ImVec2(square_sz * 3, square_sz * 2));
 | 
					        ColorButton("##current", col_v4, (flags & (ImGuiColorEditFlags_HDR|ImGuiColorEditFlags_AlphaPreview|ImGuiColorEditFlags_AlphaPreviewHalf|ImGuiColorEditFlags_NoTooltip)), ImVec2(square_sz * 3, square_sz * 2));
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user