mirror of
https://github.com/ocornut/imgui.git
synced 2024-11-23 21:09:01 +08:00
Tables: Double-clicking on fixed column to resize. Extracted code BeginTableEx().
# Conflicts: # imgui_internal.h
This commit is contained in:
parent
883c236eda
commit
0c3d7bb154
@ -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);
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user