From 0c3d7bb1542f7aa06d19fac82d88f1a72dc848a6 Mon Sep 17 00:00:00 2001 From: omar Date: Sat, 28 Dec 2019 19:34:19 +0100 Subject: [PATCH] Tables: Double-clicking on fixed column to resize. Extracted code BeginTableEx(). # Conflicts: # imgui_internal.h --- imgui_internal.h | 2 ++ imgui_tables.cpp | 18 +++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/imgui_internal.h b/imgui_internal.h index f5678f83..ea9b552b 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -2181,6 +2181,8 @@ namespace ImGui //IMGUI_API int GetTableColumnNo(); //IMGUI_API bool SetTableColumnNo(int column_n); //IMGUI_API int GetTableLineNo(); + + IMGUI_API bool BeginTableEx(const char* name, ImGuiID id, int columns_count, ImGuiTableFlags flags = 0, const ImVec2& outer_size = ImVec2(0, 0), float inner_width = 0.0f); IMGUI_API void TableBeginInitVisibility(ImGuiTable* table); IMGUI_API void TableUpdateDrawChannels(ImGuiTable* table); IMGUI_API void TableUpdateLayout(ImGuiTable* table); diff --git a/imgui_tables.cpp b/imgui_tables.cpp index e847d477..4edcaad0 100644 --- a/imgui_tables.cpp +++ b/imgui_tables.cpp @@ -145,13 +145,18 @@ inline ImGuiTableFlags TableFixFlags(ImGuiTableFlags flags) // FIXME-TABLE: Replace enlarge vs fixed width by a flag. // Even if not really useful, we allow 'inner_scroll_width < outer_size.x' for consistency and to facilitate understanding of what the value does. bool ImGui::BeginTable(const char* str_id, int columns_count, ImGuiTableFlags flags, const ImVec2& outer_size, float inner_width) +{ + ImGuiID id = GetID(str_id); + return BeginTableEx(str_id, id, columns_count, flags, outer_size, inner_width); +} + +bool ImGui::BeginTableEx(const char* name, ImGuiID id, int columns_count, ImGuiTableFlags flags, const ImVec2& outer_size, float inner_width) { ImGuiContext& g = *GImGui; ImGuiWindow* outer_window = GetCurrentWindow(); IM_ASSERT(columns_count > 0 && columns_count < IMGUI_TABLE_MAX_COLUMNS && "Only 0..63 columns allowed!"); if (flags & ImGuiTableFlags_ScrollX) IM_ASSERT(inner_width >= 0.0f); - ImGuiID id = GetID(str_id); const bool use_child_window = (flags & (ImGuiTableFlags_ScrollX | ImGuiTableFlags_ScrollY)) != 0; const ImVec2 avail_size = GetContentRegionAvail(); @@ -209,7 +214,7 @@ bool ImGui::BeginTable(const char* str_id, int columns_count, ImGuiTableFlags // Create scrolling region (without border = zero window padding) ImGuiWindowFlags child_flags = (flags & ImGuiTableFlags_ScrollX) ? ImGuiWindowFlags_HorizontalScrollbar : ImGuiWindowFlags_None; - BeginChildEx(str_id, instance_id, table->OuterRect.GetSize(), false, child_flags); + BeginChildEx(name, instance_id, table->OuterRect.GetSize(), false, child_flags); table->InnerWindow = g.CurrentWindow; table->WorkRect = table->InnerWindow->WorkRect; table->OuterRect = table->InnerWindow->Rect(); @@ -810,7 +815,14 @@ void ImGui::TableUpdateBorders(ImGuiTable* table) KeepAliveID(column_id); bool hovered = false, held = false; - ButtonBehavior(hit_rect, column_id, &hovered, &held, ImGuiButtonFlags_FlattenChildren | ImGuiButtonFlags_AllowItemOverlap); + bool pressed = ButtonBehavior(hit_rect, column_id, &hovered, &held, ImGuiButtonFlags_FlattenChildren | ImGuiButtonFlags_AllowItemOverlap | ImGuiButtonFlags_PressedOnClick | ImGuiButtonFlags_PressedOnDoubleClick); + if (pressed && IsMouseDoubleClicked(0) && !(column->Flags & ImGuiTableColumnFlags_WidthStretch)) + { + // FIXME-TABLE: Double-clicking on column edge could auto-fit weighted column? + TableSetColumnAutofit(table, column_n); + ClearActiveID(); + held = hovered = false; + } if (held) { table->ResizedColumn = (ImS8)column_n;