Columns: Moved BeginColumns/EndColumns/flags from #913 to imgui_internals.h + minor shallow tweaks. Removed demo code temporarily. (#125)
This commit is contained in:
parent
bc78535bbf
commit
19a42cb2fd
26
imgui.cpp
26
imgui.cpp
@ -9928,15 +9928,13 @@ int ImGui::GetColumnsCount()
|
||||
return window->DC.ColumnsCount;
|
||||
}
|
||||
|
||||
static float OffsetNormToPixels(float offsetNorm)
|
||||
static float OffsetNormToPixels(ImGuiWindow* window, float offset_norm)
|
||||
{
|
||||
ImGuiWindow* window = ImGui::GetCurrentWindowRead();
|
||||
return offsetNorm * (window->DC.ColumnsMaxX - window->DC.ColumnsMinX);
|
||||
return offset_norm * (window->DC.ColumnsMaxX - window->DC.ColumnsMinX);
|
||||
}
|
||||
|
||||
static float PixelsToOffsetNorm(float offset)
|
||||
static float PixelsToOffsetNorm(ImGuiWindow* window, float offset)
|
||||
{
|
||||
ImGuiWindow* window = ImGui::GetCurrentWindowRead();
|
||||
return (offset - window->DC.ColumnsMinX) / (window->DC.ColumnsMaxX - window->DC.ColumnsMinX);
|
||||
}
|
||||
|
||||
@ -9986,18 +9984,18 @@ void ImGui::SetColumnOffset(int column_index, float offset)
|
||||
|
||||
IM_ASSERT(column_index < window->DC.ColumnsData.Size);
|
||||
|
||||
const bool preserveWidth = !(window->DC.ColumnsFlags & ImGuiColumnsFlags_NoPreserveWidths) && (column_index < window->DC.ColumnsCount-1);
|
||||
const float width = preserveWidth ? GetColumnWidth(column_index) : 0.0f;
|
||||
const bool preserve_width = !(window->DC.ColumnsFlags & ImGuiColumnsFlags_NoPreserveWidths) && (column_index < window->DC.ColumnsCount-1);
|
||||
const float width = preserve_width ? GetColumnWidth(column_index) : 0.0f;
|
||||
|
||||
if (!(window->DC.ColumnsFlags & ImGuiColumnsFlags_NoForceWithinWindow))
|
||||
offset = ImMin((float)(int)offset, window->DC.ColumnsMaxX - g.Style.ColumnsMinSpacing * (window->DC.ColumnsCount - column_index));
|
||||
const float offsetNorm = PixelsToOffsetNorm(offset);
|
||||
const float offset_norm = PixelsToOffsetNorm(window, offset);
|
||||
|
||||
const ImGuiID column_id = window->DC.ColumnsSetId + ImGuiID(column_index);
|
||||
window->DC.StateStorage->SetFloat(column_id, offsetNorm);
|
||||
window->DC.ColumnsData[column_index].OffsetNorm = offsetNorm;
|
||||
window->DC.StateStorage->SetFloat(column_id, offset_norm);
|
||||
window->DC.ColumnsData[column_index].OffsetNorm = offset_norm;
|
||||
|
||||
if (preserveWidth)
|
||||
if (preserve_width)
|
||||
SetColumnOffset(column_index+1, offset + ImMax(g.Style.ColumnsMinSpacing, width));
|
||||
}
|
||||
|
||||
@ -10007,7 +10005,7 @@ float ImGui::GetColumnWidth(int column_index)
|
||||
if (column_index < 0)
|
||||
column_index = window->DC.ColumnsCurrent;
|
||||
|
||||
return OffsetNormToPixels(window->DC.ColumnsData[column_index+1].OffsetNorm - window->DC.ColumnsData[column_index].OffsetNorm);
|
||||
return OffsetNormToPixels(window, window->DC.ColumnsData[column_index+1].OffsetNorm - window->DC.ColumnsData[column_index].OffsetNorm);
|
||||
}
|
||||
|
||||
void ImGui::SetColumnWidth(int column_index, float width)
|
||||
@ -10066,7 +10064,7 @@ void ImGui::BeginColumns(const char* id, int columns_count, ImGuiColumnsFlags fl
|
||||
const float default_t = column_index / (float)window->DC.ColumnsCount;
|
||||
float t = window->DC.StateStorage->GetFloat(column_id, default_t); // Cheaply store our floating point value inside the integer (could store a union into the map?)
|
||||
if (!(window->DC.ColumnsFlags & ImGuiColumnsFlags_NoForceWithinWindow))
|
||||
t = ImMin(t, PixelsToOffsetNorm(window->DC.ColumnsMaxX - g.Style.ColumnsMinSpacing * (window->DC.ColumnsCount - column_index)));
|
||||
t = ImMin(t, PixelsToOffsetNorm(window, window->DC.ColumnsMaxX - g.Style.ColumnsMinSpacing * (window->DC.ColumnsCount - column_index)));
|
||||
window->DC.ColumnsData[column_index].OffsetNorm = t;
|
||||
}
|
||||
window->DrawList->ChannelsSplit(window->DC.ColumnsCount);
|
||||
@ -10098,7 +10096,7 @@ void ImGui::EndColumns()
|
||||
{
|
||||
float x = window->Pos.x + GetColumnOffset(i);
|
||||
const ImGuiID column_id = window->DC.ColumnsSetId + ImGuiID(i);
|
||||
const float column_w = 4.0f;
|
||||
const float column_w = 4.0f; // Width for interaction
|
||||
const ImRect column_rect(ImVec2(x - column_w, y1), ImVec2(x + column_w, y2));
|
||||
if (IsClippedEx(column_rect, &column_id, false))
|
||||
continue;
|
||||
|
15
imgui.h
15
imgui.h
@ -231,9 +231,8 @@ namespace ImGui
|
||||
IMGUI_API float GetItemsLineHeightWithSpacing(); // distance (in pixels) between 2 consecutive lines of standard height widgets == GetWindowFontSize() + GetStyle().FramePadding.y*2 + GetStyle().ItemSpacing.y
|
||||
|
||||
// Columns
|
||||
// You can also use SameLine(pos_x) for simplified columning. The columns API is still work-in-progress and rather lacking.
|
||||
IMGUI_API void BeginColumns(const char* id, int count, ImGuiColumnsFlags flags = 0); // setup number of columns. use an identifier to distinguish multiple column sets. close with EndColumns().
|
||||
IMGUI_API void EndColumns(); // close columns
|
||||
// You can also use SameLine(pos_x) for simplified columns. The columns API is still work-in-progress and rather lacking.
|
||||
IMGUI_API void Columns(int count = 1, const char* id = NULL, bool border = true);
|
||||
IMGUI_API void NextColumn(); // next column, defaults to current row or next row if the current row is finished
|
||||
IMGUI_API int GetColumnIndex(); // get current column index
|
||||
IMGUI_API float GetColumnWidth(int column_index = -1); // get column width (in pixels). pass -1 to use current column
|
||||
@ -241,7 +240,6 @@ namespace ImGui
|
||||
IMGUI_API float GetColumnOffset(int column_index = -1); // get position of column line (in pixels, from the left side of the contents region). pass -1 to use current column, otherwise 0..GetColumnsCount() inclusive. column 0 is usually 0.0f and not resizable unless you call this
|
||||
IMGUI_API void SetColumnOffset(int column_index, float offset_x); // set position of column line (in pixels, from the left side of the contents region). pass -1 to use current column
|
||||
IMGUI_API int GetColumnsCount();
|
||||
IMGUI_API void Columns(int count = 1, const char* id = NULL, bool border = true);
|
||||
|
||||
// ID scopes
|
||||
// If you are creating widgets in a loop you most likely want to push a unique identifier so ImGui can differentiate them.
|
||||
@ -524,15 +522,6 @@ enum ImGuiWindowFlags_
|
||||
ImGuiWindowFlags_ChildMenu = 1 << 27 // Don't use! For internal use by BeginMenu()
|
||||
};
|
||||
|
||||
// Flags for ImGui::Columns()
|
||||
enum ImGuiColumnsFlags_
|
||||
{
|
||||
// Default: 0
|
||||
ImGuiColumnsFlags_NoBorder = 1 << 0, // Disable column dividers
|
||||
ImGuiColumnsFlags_NoPreserveWidths = 1 << 1, // Disable column width preservation when adjusting columns
|
||||
ImGuiColumnsFlags_NoForceWithinWindow = 1 << 2 // Disable forcing columns to fit within window
|
||||
};
|
||||
|
||||
// Flags for ImGui::InputText()
|
||||
enum ImGuiInputTextFlags_
|
||||
{
|
||||
|
@ -1553,49 +1553,6 @@ void ImGui::ShowTestWindow(bool* p_open)
|
||||
}
|
||||
*/
|
||||
|
||||
if (ImGui::TreeNode("Advanced settings"))
|
||||
{
|
||||
static bool border = true;
|
||||
static bool preserveWidths = true;
|
||||
static bool forceWithinWindow = true;
|
||||
|
||||
ImGui::Checkbox("Border", &border);
|
||||
ImGui::SameLine();
|
||||
ImGui::Checkbox("Preserve widths", &preserveWidths);
|
||||
ImGui::SameLine();
|
||||
ImGui::Checkbox("Force within window", &forceWithinWindow);
|
||||
|
||||
ImGuiColumnsFlags flags = 0;
|
||||
flags |= (border ? 0 : ImGuiColumnsFlags_NoBorder);
|
||||
flags |= (preserveWidths ? 0 : ImGuiColumnsFlags_NoPreserveWidths);
|
||||
flags |= (forceWithinWindow ? 0 : ImGuiColumnsFlags_NoForceWithinWindow);
|
||||
|
||||
ImGui::BeginColumns("AdvancedColumns", 4, flags);
|
||||
ImGui::Separator();
|
||||
ImGui::Text("ID"); ImGui::NextColumn();
|
||||
ImGui::Text("Name"); ImGui::NextColumn();
|
||||
ImGui::Text("Path"); ImGui::NextColumn();
|
||||
ImGui::Text("Flags"); ImGui::NextColumn();
|
||||
ImGui::Separator();
|
||||
const char* names[3] = { "One", "Two", "Three" };
|
||||
const char* paths[3] = { "/path/one", "/path/two", "/path/three" };
|
||||
static int selected = -1;
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
char label[32];
|
||||
sprintf(label, "%04d", i);
|
||||
if (ImGui::Selectable(label, selected == i, ImGuiSelectableFlags_SpanAllColumns))
|
||||
selected = i;
|
||||
ImGui::NextColumn();
|
||||
ImGui::Text(names[i]); ImGui::NextColumn();
|
||||
ImGui::Text(paths[i]); ImGui::NextColumn();
|
||||
ImGui::Text("...."); ImGui::NextColumn();
|
||||
}
|
||||
ImGui::EndColumns();
|
||||
ImGui::Separator();
|
||||
ImGui::TreePop();
|
||||
}
|
||||
|
||||
// Create multiple items in a same cell before switching to next column
|
||||
if (ImGui::TreeNode("Mixed items"))
|
||||
{
|
||||
|
@ -183,6 +183,14 @@ enum ImGuiSliderFlags_
|
||||
ImGuiSliderFlags_Vertical = 1 << 0
|
||||
};
|
||||
|
||||
enum ImGuiColumnsFlags_
|
||||
{
|
||||
// Default: 0
|
||||
ImGuiColumnsFlags_NoBorder = 1 << 0, // Disable column dividers
|
||||
ImGuiColumnsFlags_NoPreserveWidths = 1 << 1, // Disable column width preservation when adjusting columns
|
||||
ImGuiColumnsFlags_NoForceWithinWindow = 1 << 2 // Disable forcing columns to fit within window
|
||||
};
|
||||
|
||||
enum ImGuiSelectableFlagsPrivate_
|
||||
{
|
||||
// NB: need to be in sync with last value of ImGuiSelectableFlags_
|
||||
@ -598,7 +606,7 @@ struct IMGUI_API ImGuiDrawContext
|
||||
float ColumnsStartPosY;
|
||||
float ColumnsCellMinY;
|
||||
float ColumnsCellMaxY;
|
||||
ImGuiColumnsFlags ColumnsFlags;
|
||||
ImGuiColumnsFlags ColumnsFlags;
|
||||
ImGuiID ColumnsSetId;
|
||||
ImVector<ImGuiColumnData> ColumnsData;
|
||||
|
||||
@ -748,6 +756,10 @@ namespace ImGui
|
||||
IMGUI_API void OpenPopupEx(ImGuiID id, bool reopen_existing);
|
||||
IMGUI_API bool IsPopupOpen(ImGuiID id);
|
||||
|
||||
// New Columns API
|
||||
IMGUI_API void BeginColumns(const char* id, int count, ImGuiColumnsFlags flags = 0); // setup number of columns. use an identifier to distinguish multiple column sets. close with EndColumns().
|
||||
IMGUI_API void EndColumns(); // close columns
|
||||
|
||||
// NB: All position are in absolute pixels coordinates (never using window coordinates internally)
|
||||
// AVOID USING OUTSIDE OF IMGUI.CPP! NOT FOR PUBLIC CONSUMPTION. THOSE FUNCTIONS ARE A MESS. THEIR SIGNATURE AND BEHAVIOR WILL CHANGE, THEY NEED TO BE REFACTORED INTO SOMETHING DECENT.
|
||||
IMGUI_API void RenderText(ImVec2 pos, const char* text, const char* text_end = NULL, bool hide_text_after_hash = true);
|
||||
|
Loading…
Reference in New Issue
Block a user