Separator(): output vertical separator when used in horizontal layout mode, so it works in menu bars.

This commit is contained in:
omar 2017-09-26 15:43:48 +02:00
parent c7a606ab7e
commit be03882a15
2 changed files with 53 additions and 21 deletions

View File

@ -9893,10 +9893,23 @@ bool ImGui::ColorPicker4(const char* label, float col[4], ImGuiColorEditFlags fl
// Horizontal separating line. // Horizontal separating line.
void ImGui::Separator() void ImGui::Separator()
{ {
ImGuiContext& g = *GImGui;
ImGuiWindow* window = GetCurrentWindow(); ImGuiWindow* window = GetCurrentWindow();
if (window->SkipItems) if (window->SkipItems)
return; return;
ImGuiWindowFlags flags = 0;
if ((flags & (ImGuiSeparatorFlags_Horizontal | ImGuiSeparatorFlags_Vertical)) == 0)
{
if (window->DC.LayoutType == ImGuiLayoutType_Horizontal)
flags |= ImGuiSeparatorFlags_Vertical;
else
flags |= ImGuiSeparatorFlags_Horizontal;
}
IM_ASSERT(ImIsPowerOfTwo((int)(flags & (ImGuiSeparatorFlags_Horizontal | ImGuiSeparatorFlags_Vertical)))); // Check that only 1 option is selected
if (flags & ImGuiSeparatorFlags_Horizontal)
{
if (window->DC.ColumnsCount > 1) if (window->DC.ColumnsCount > 1)
PopClipRect(); PopClipRect();
@ -9916,7 +9929,6 @@ void ImGui::Separator()
window->DrawList->AddLine(bb.Min, ImVec2(bb.Max.x,bb.Min.y), GetColorU32(ImGuiCol_Separator)); window->DrawList->AddLine(bb.Min, ImVec2(bb.Max.x,bb.Min.y), GetColorU32(ImGuiCol_Separator));
ImGuiContext& g = *GImGui;
if (g.LogEnabled) if (g.LogEnabled)
LogText(IM_NEWLINE "--------------------------------"); LogText(IM_NEWLINE "--------------------------------");
@ -9926,6 +9938,19 @@ void ImGui::Separator()
window->DC.ColumnsCellMinY = window->DC.CursorPos.y; window->DC.ColumnsCellMinY = window->DC.CursorPos.y;
} }
} }
else if (flags & ImGuiSeparatorFlags_Vertical)
{
const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(1.0f, window->DC.CurrentLineHeight));
ItemSize(ImVec2(bb.GetWidth(), 0.0f));
if (!ItemAdd(bb, NULL))
return;
window->DrawList->AddLine(ImVec2(bb.Min.x, bb.Min.y), ImVec2(bb.Min.x, bb.Max.y), GetColorU32(ImGuiCol_Separator));
if (g.LogEnabled)
LogText("|");
}
}
void ImGui::Spacing() void ImGui::Spacing()
{ {

View File

@ -48,6 +48,7 @@ typedef int ImGuiLayoutType; // enum ImGuiLayoutType_
typedef int ImGuiButtonFlags; // enum ImGuiButtonFlags_ typedef int ImGuiButtonFlags; // enum ImGuiButtonFlags_
typedef int ImGuiTreeNodeFlags; // enum ImGuiTreeNodeFlags_ typedef int ImGuiTreeNodeFlags; // enum ImGuiTreeNodeFlags_
typedef int ImGuiSliderFlags; // enum ImGuiSliderFlags_ typedef int ImGuiSliderFlags; // enum ImGuiSliderFlags_
typedef int ImGuiSeparatorFlags; // enum ImGuiSeparatorFlags_
typedef int ImGuiItemFlags; // enum ImGuiItemFlags_ typedef int ImGuiItemFlags; // enum ImGuiItemFlags_
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
@ -203,6 +204,12 @@ enum ImGuiSelectableFlagsPrivate_
ImGuiSelectableFlags_DrawFillAvailWidth = 1 << 6 ImGuiSelectableFlags_DrawFillAvailWidth = 1 << 6
}; };
enum ImGuiSeparatorFlags_
{
ImGuiSeparatorFlags_Horizontal = 1 << 0, // Axis default to current layout type, so generally Horizontal unless e.g. in a menu bar
ImGuiSeparatorFlags_Vertical = 1 << 1
};
// FIXME: this is in development, not exposed/functional as a generic feature yet. // FIXME: this is in development, not exposed/functional as a generic feature yet.
enum ImGuiLayoutType_ enum ImGuiLayoutType_
{ {