mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-14 17:07:01 +00:00
Tables: Add demo code. Remove dead code + seemingly duplicate border in TableDrawBorders().
This commit is contained in:
parent
2ee20fdb7c
commit
172704c079
2
imgui.h
2
imgui.h
@ -1069,7 +1069,7 @@ enum ImGuiTableFlags_
|
||||
ImGuiTableFlags_BordersOuter = ImGuiTableFlags_BordersOuterV | ImGuiTableFlags_BordersOuterH, // Draw outer borders.
|
||||
ImGuiTableFlags_Borders = ImGuiTableFlags_BordersInner | ImGuiTableFlags_BordersOuter, // Draw all borders.
|
||||
ImGuiTableFlags_BordersFullHeightV = 1 << 12, // Borders covers all rows even when Headers are being used. Allow resizing from any rows.
|
||||
// Padding, Sizing
|
||||
// Sizing, Padding
|
||||
ImGuiTableFlags_SizingPolicyFixedX = 1 << 13, // Default if ScrollX is on. Columns will default to use _WidthFixed or _WidthAlwaysAutoResize policy. Read description above for more details.
|
||||
ImGuiTableFlags_SizingPolicyStretchX = 1 << 14, // Default if ScrollX is off. Columns will default to use _WidthStretch policy. Read description above for more details.
|
||||
ImGuiTableFlags_NoHeadersWidth = 1 << 15, // Disable header width contribution to automatic width calculation.
|
||||
|
@ -3385,8 +3385,12 @@ static void ShowDemoWindowTables()
|
||||
if (ImGui::TreeNode("Borders, background"))
|
||||
{
|
||||
// Expose a few Borders related flags interactively
|
||||
enum ContentsType { CT_Text, CT_FillButton };
|
||||
static ImGuiTableFlags flags = ImGuiTableFlags_BordersOuter | ImGuiTableFlags_RowBg;
|
||||
static bool display_headers = false;
|
||||
static bool display_width = false;
|
||||
static int contents_type = CT_Text;
|
||||
|
||||
ImGui::CheckboxFlags("ImGuiTableFlags_RowBg", (unsigned int*)&flags, ImGuiTableFlags_RowBg);
|
||||
ImGui::CheckboxFlags("ImGuiTableFlags_Borders", (unsigned int*)&flags, ImGuiTableFlags_Borders);
|
||||
ImGui::SameLine(); HelpMarker("ImGuiTableFlags_Borders\n = ImGuiTableFlags_BordersInnerV\n | ImGuiTableFlags_BordersOuterV\n | ImGuiTableFlags_BordersInnerV\n | ImGuiTableFlags_BordersOuterH");
|
||||
@ -3402,15 +3406,30 @@ static void ShowDemoWindowTables()
|
||||
ImGui::Indent();
|
||||
ImGui::CheckboxFlags("ImGuiTableFlags_BordersOuterV", (unsigned int*)&flags, ImGuiTableFlags_BordersOuterV);
|
||||
ImGui::CheckboxFlags("ImGuiTableFlags_BordersInnerV", (unsigned int*)&flags, ImGuiTableFlags_BordersInnerV);
|
||||
ImGui::CheckboxFlags("ImGuiTableFlags_BordersFullHeightV", (unsigned int*)&flags, ImGuiTableFlags_BordersFullHeightV); ImGui::SameLine(); HelpMarker("Makes a difference when headers are enabled");
|
||||
ImGui::Unindent();
|
||||
|
||||
ImGui::CheckboxFlags("ImGuiTableFlags_BordersOuter", (unsigned int*)&flags, ImGuiTableFlags_BordersOuter);
|
||||
ImGui::CheckboxFlags("ImGuiTableFlags_BordersInner", (unsigned int*)&flags, ImGuiTableFlags_BordersInner);
|
||||
ImGui::Unindent();
|
||||
ImGui::Checkbox("Debug Display width", &display_width);
|
||||
ImGui::AlignTextToFramePadding(); ImGui::Text("Cell contents:");
|
||||
ImGui::SameLine(); ImGui::RadioButton("Text", &contents_type, CT_Text);
|
||||
ImGui::SameLine(); ImGui::RadioButton("FillButton", &contents_type, CT_FillButton);
|
||||
ImGui::Checkbox("Display headers", &display_headers);
|
||||
ImGui::Checkbox("Display debug width", &display_width);
|
||||
|
||||
if (ImGui::BeginTable("##table1", 3, flags))
|
||||
{
|
||||
// Display headers so we can inspect their interaction with borders.
|
||||
// (Headers are not the main purpose of this section of the demo, so we are not elaborating on them too much. See other sections for details)
|
||||
if (display_headers)
|
||||
{
|
||||
ImGui::TableSetupColumn("One");
|
||||
ImGui::TableSetupColumn("Two");
|
||||
ImGui::TableSetupColumn("Three");
|
||||
ImGui::TableHeadersRow();
|
||||
}
|
||||
|
||||
for (int row = 0; row < 5; row++)
|
||||
{
|
||||
ImGui::TableNextRow();
|
||||
@ -3420,7 +3439,7 @@ static void ShowDemoWindowTables()
|
||||
char buf[32];
|
||||
if (display_width)
|
||||
{
|
||||
// [DEBUG] Draw limits
|
||||
// [DEBUG] Draw limits FIXME-TABLE: Move to Advanced section
|
||||
ImVec2 p = ImGui::GetCursorScreenPos();
|
||||
float contents_x1 = p.x;
|
||||
float contents_x2 = ImGui::GetWindowPos().x + ImGui::GetContentRegionMax().x;
|
||||
@ -3437,7 +3456,11 @@ static void ShowDemoWindowTables()
|
||||
{
|
||||
sprintf(buf, "Hello %d,%d", row, column);
|
||||
}
|
||||
ImGui::TextUnformatted(buf);
|
||||
|
||||
if (contents_type == CT_Text)
|
||||
ImGui::TextUnformatted(buf);
|
||||
else if (contents_type)
|
||||
ImGui::Button(buf, ImVec2(-FLT_MIN, 0.0f));
|
||||
}
|
||||
}
|
||||
ImGui::EndTable();
|
||||
@ -4305,7 +4328,6 @@ static void ShowDemoWindowTables()
|
||||
static float row_min_height = 0.0f; // Auto
|
||||
static float inner_width_with_scroll = 0.0f; // Auto-extend
|
||||
static bool outer_size_enabled = true;
|
||||
static bool lock_first_column_visibility = false;
|
||||
static bool show_headers = true;
|
||||
static bool show_wrapped_text = false;
|
||||
//static ImGuiTextFilter filter;
|
||||
@ -4370,6 +4392,8 @@ static void ShowDemoWindowTables()
|
||||
|
||||
ImGui::BulletText("Other:");
|
||||
ImGui::Indent();
|
||||
ImGui::Checkbox("show_headers", &show_headers);
|
||||
ImGui::Checkbox("show_wrapped_text", &show_wrapped_text);
|
||||
ImGui::DragFloat2("##OuterSize", &outer_size_value.x);
|
||||
ImGui::SameLine(0.0f, ImGui::GetStyle().ItemInnerSpacing.x);
|
||||
ImGui::Checkbox("outer_size", &outer_size_enabled);
|
||||
@ -4384,9 +4408,6 @@ static void ShowDemoWindowTables()
|
||||
ImGui::DragInt("items_count", &items_count, 0.1f, 0, 5000);
|
||||
ImGui::Combo("contents_type (first column)", &contents_type, contents_type_names, IM_ARRAYSIZE(contents_type_names));
|
||||
//filter.Draw("filter");
|
||||
ImGui::Checkbox("show_headers", &show_headers);
|
||||
ImGui::Checkbox("show_wrapped_text", &show_wrapped_text);
|
||||
ImGui::Checkbox("lock_first_column_visibility", &lock_first_column_visibility);
|
||||
ImGui::Unindent();
|
||||
|
||||
ImGui::PopItemWidth();
|
||||
@ -4424,7 +4445,7 @@ static void ShowDemoWindowTables()
|
||||
// We use the "user_id" parameter of TableSetupColumn() to specify a user id that will be stored in the sort specifications.
|
||||
// This is so our sort function can identify a column given our own identifier. We could also identify them based on their index!
|
||||
ImGui::TableSetupScrollFreeze(freeze_cols, freeze_rows);
|
||||
ImGui::TableSetupColumn("ID", ImGuiTableColumnFlags_DefaultSort | ImGuiTableColumnFlags_WidthFixed | (lock_first_column_visibility ? ImGuiTableColumnFlags_NoHide : 0), -1.0f, MyItemColumnID_ID);
|
||||
ImGui::TableSetupColumn("ID", ImGuiTableColumnFlags_DefaultSort | ImGuiTableColumnFlags_WidthFixed | ImGuiTableColumnFlags_NoHide, -1.0f, MyItemColumnID_ID);
|
||||
ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthFixed, -1.0f, MyItemColumnID_Name);
|
||||
ImGui::TableSetupColumn("Action", ImGuiTableColumnFlags_NoSort | ImGuiTableColumnFlags_WidthFixed, -1.0f, MyItemColumnID_Action);
|
||||
ImGui::TableSetupColumn("Quantity Long Label", ImGuiTableColumnFlags_PreferSortDescending | ImGuiTableColumnFlags_WidthStretch, 1.0f, MyItemColumnID_Quantity);// , ImGuiTableColumnFlags_None | ImGuiTableColumnFlags_WidthAlwaysAutoResize);
|
||||
|
@ -1147,7 +1147,8 @@ void ImGui::TableDrawBorders(ImGuiTable* table)
|
||||
float draw_y2_base = (table->FreezeRowsCount >= 1 ? table->OuterRect.Min.y : table->WorkRect.Min.y) + table->LastFirstRowHeight;
|
||||
float draw_y2_full = table->OuterRect.Max.y;
|
||||
ImU32 border_base_col;
|
||||
if (!table->IsUsingHeaders || (table->Flags & ImGuiTableFlags_BordersFullHeightV))
|
||||
const bool borders_full_height = (table->IsUsingHeaders == false) || (table->Flags & ImGuiTableFlags_BordersFullHeightV);
|
||||
if (borders_full_height)
|
||||
{
|
||||
draw_y2_base = draw_y2_full;
|
||||
border_base_col = table->BorderColorLight;
|
||||
@ -1157,9 +1158,6 @@ void ImGui::TableDrawBorders(ImGuiTable* table)
|
||||
border_base_col = table->BorderColorStrong;
|
||||
}
|
||||
|
||||
if ((table->Flags & ImGuiTableFlags_BordersOuterV) && (table->InnerWindow == table->OuterWindow))
|
||||
inner_drawlist->AddLine(ImVec2(table->OuterRect.Min.x, draw_y1), ImVec2(table->OuterRect.Min.x, draw_y2_base), border_base_col, border_size);
|
||||
|
||||
if (table->Flags & ImGuiTableFlags_BordersInnerV)
|
||||
{
|
||||
for (int order_n = 0; order_n < table->ColumnsCount; order_n++)
|
||||
@ -1696,24 +1694,12 @@ void ImGui::TableEndRow(ImGuiTable* table)
|
||||
ImU32 border_col = 0;
|
||||
const float border_size = TABLE_BORDER_SIZE;
|
||||
if (table->CurrentRow != 0 || table->InnerWindow == table->OuterWindow)
|
||||
{
|
||||
if (table->Flags & ImGuiTableFlags_BordersInnerH)
|
||||
{
|
||||
//if (table->CurrentRow == 0 && table->InnerWindow == table->OuterWindow)
|
||||
// border_col = table->BorderOuterColor;
|
||||
//else
|
||||
if (table->CurrentRow > 0)// && !(table->LastRowFlags & ImGuiTableRowFlags_Headers))
|
||||
if (table->CurrentRow > 0)
|
||||
border_col = (table->LastRowFlags & ImGuiTableRowFlags_Headers) ? table->BorderColorStrong : table->BorderColorLight;
|
||||
}
|
||||
else
|
||||
{
|
||||
//if (table->RowFlags & ImGuiTableRowFlags_Headers)
|
||||
// border_col = table->BorderOuterColor;
|
||||
}
|
||||
}
|
||||
|
||||
const bool draw_cell_bg_color = table->RowCellDataCurrent >= 0;
|
||||
const bool draw_strong_bottom_border = unfreeze_rows_actual;// || (table->RowFlags & ImGuiTableRowFlags_Headers);
|
||||
const bool draw_strong_bottom_border = unfreeze_rows_actual;
|
||||
if ((bg_col0 | bg_col1 | border_col) != 0 || draw_strong_bottom_border || draw_cell_bg_color)
|
||||
{
|
||||
// In theory we could call SetWindowClipRectBeforeChannelChange() but since we know TableEndRow() is
|
||||
|
Loading…
Reference in New Issue
Block a user