Updated ImGui.

This commit is contained in:
Бранимир Караџић 2019-10-05 10:20:28 -07:00
parent 0c5c2fcdcf
commit b91d0b69e1
4 changed files with 101 additions and 52 deletions

View File

@ -2971,7 +2971,7 @@ static inline bool IsWindowContentHoverable(ImGuiWindow* window, ImGuiHoveredFla
}
// Advance cursor given item size for layout.
void ImGui::ItemSize(const ImVec2& size, float text_offset_y)
void ImGui::ItemSize(const ImVec2& size, float text_baseline_y)
{
ImGuiContext& g = *GImGui;
ImGuiWindow* window = g.CurrentWindow;
@ -2980,28 +2980,28 @@ void ImGui::ItemSize(const ImVec2& size, float text_offset_y)
// Always align ourselves on pixel boundaries
const float line_height = ImMax(window->DC.CurrLineSize.y, size.y);
const float text_base_offset = ImMax(window->DC.CurrLineTextBaseOffset, text_offset_y);
//if (g.IO.KeyAlt) window->DrawList->AddRect(window->DC.CursorPos, window->DC.CursorPos + ImVec2(size.x, line_height), IM_COL32(255,0,0,200)); // [DEBUG]
window->DC.CursorPosPrevLine.x = window->DC.CursorPos.x + size.x;
window->DC.CursorPosPrevLine.y = window->DC.CursorPos.y;
window->DC.CursorPos.x = (float)(int)(window->Pos.x + window->DC.Indent.x + window->DC.ColumnsOffset.x);
window->DC.CursorPos.y = (float)(int)(window->DC.CursorPos.y + line_height + g.Style.ItemSpacing.y);
window->DC.CursorPos.x = (float)(int)(window->Pos.x + window->DC.Indent.x + window->DC.ColumnsOffset.x); // Next line
window->DC.CursorPos.y = (float)(int)(window->DC.CursorPos.y + line_height + g.Style.ItemSpacing.y); // Next line
window->DC.CursorMaxPos.x = ImMax(window->DC.CursorMaxPos.x, window->DC.CursorPosPrevLine.x);
window->DC.CursorMaxPos.y = ImMax(window->DC.CursorMaxPos.y, window->DC.CursorPos.y - g.Style.ItemSpacing.y);
//if (g.IO.KeyAlt) window->DrawList->AddCircle(window->DC.CursorMaxPos, 3.0f, IM_COL32(255,0,0,255), 4); // [DEBUG]
window->DC.PrevLineSize.y = line_height;
window->DC.PrevLineTextBaseOffset = text_base_offset;
window->DC.CurrLineSize.y = window->DC.CurrLineTextBaseOffset = 0.0f;
window->DC.CurrLineSize.y = 0.0f;
window->DC.PrevLineTextBaseOffset = ImMax(window->DC.CurrLineTextBaseOffset, text_baseline_y);
window->DC.CurrLineTextBaseOffset = 0.0f;
// Horizontal layout mode
if (window->DC.LayoutType == ImGuiLayoutType_Horizontal)
SameLine();
}
void ImGui::ItemSize(const ImRect& bb, float text_offset_y)
void ImGui::ItemSize(const ImRect& bb, float text_baseline_y)
{
ItemSize(bb.GetSize(), text_offset_y);
ItemSize(bb.GetSize(), text_baseline_y);
}
// Declare item bounding box for clipping and interaction.

View File

@ -2047,8 +2047,44 @@ static void ShowDemoWindowLayout()
if (ImGui::TreeNode("Text Baseline Alignment"))
{
{
ImGui::BulletText("Text baseline:");
ImGui::SameLine();
HelpMarker("This is testing the vertical alignment that gets applied on text to keep it aligned with widgets. Lines only composed of text or \"small\" widgets fit in less vertical spaces than lines with normal widgets.");
ImGui::Indent();
ImGui::Text("KO Blahblah"); ImGui::SameLine();
ImGui::Button("Some framed item"); ImGui::SameLine();
HelpMarker("Baseline of button will look misaligned with text..");
// If your line starts with text, call AlignTextToFramePadding() to align text to upcoming widgets.
// Because we don't know what's coming after the Text() statement, we need to move the text baseline down by FramePadding.y
ImGui::AlignTextToFramePadding();
ImGui::Text("OK Blahblah"); ImGui::SameLine();
ImGui::Button("Some framed item"); ImGui::SameLine();
HelpMarker("We call AlignTextToFramePadding() to vertically align the text baseline by +FramePadding.y");
// SmallButton() uses the same vertical padding as Text
ImGui::Button("TEST##1"); ImGui::SameLine();
ImGui::Text("TEST"); ImGui::SameLine();
ImGui::SmallButton("TEST##2");
// If your line starts with text, call AlignTextToFramePadding() to align text to upcoming widgets.
ImGui::AlignTextToFramePadding();
ImGui::Text("Text aligned to framed item"); ImGui::SameLine();
ImGui::Button("Item##1"); ImGui::SameLine();
ImGui::Text("Item"); ImGui::SameLine();
ImGui::SmallButton("Item##2"); ImGui::SameLine();
ImGui::Button("Item##3");
ImGui::Unindent();
}
ImGui::Spacing();
{
ImGui::BulletText("Multi-line text:");
ImGui::Indent();
ImGui::Text("One\nTwo\nThree"); ImGui::SameLine();
ImGui::Text("Hello\nWorld"); ImGui::SameLine();
ImGui::Text("Banana");
@ -2065,17 +2101,23 @@ static void ShowDemoWindowLayout()
ImGui::Button("HOP##2"); ImGui::SameLine();
ImGui::Text("Hello\nWorld"); ImGui::SameLine();
ImGui::Text("Banana");
ImGui::Unindent();
}
ImGui::Button("TEST##1"); ImGui::SameLine();
ImGui::Text("TEST"); ImGui::SameLine();
ImGui::SmallButton("TEST##2");
ImGui::Spacing();
ImGui::AlignTextToFramePadding(); // If your line starts with text, call this to align it to upcoming widgets.
ImGui::Text("Text aligned to Widget"); ImGui::SameLine();
ImGui::Button("Widget##1"); ImGui::SameLine();
ImGui::Text("Widget"); ImGui::SameLine();
ImGui::SmallButton("Widget##2"); ImGui::SameLine();
ImGui::Button("Widget##3");
{
ImGui::BulletText("Misc items:");
ImGui::Indent();
// SmallButton() sets FramePadding to zero. Text baseline is aligned to match baseline of previous Button
ImGui::Button("80x80", ImVec2(80, 80));
ImGui::SameLine();
ImGui::Button("50x50", ImVec2(50, 50));
ImGui::SameLine();
ImGui::Button("Button()");
ImGui::SameLine();
ImGui::SmallButton("SmallButton()");
// Tree
const float spacing = ImGui::GetStyle().ItemInnerSpacing.x;
@ -2096,6 +2138,8 @@ static void ShowDemoWindowLayout()
ImGui::AlignTextToFramePadding();
ImGui::BulletText("Node");
ImGui::SameLine(0.0f, spacing); ImGui::Button("Button##4");
ImGui::Unindent();
}
ImGui::TreePop();
}

View File

@ -383,6 +383,7 @@ enum ImGuiSeparatorFlags_
// This is going to be exposed in imgui.h when stabilized enough.
enum ImGuiItemFlags_
{
ImGuiItemFlags_None = 0,
ImGuiItemFlags_NoTabStop = 1 << 0, // false
ImGuiItemFlags_ButtonRepeat = 1 << 1, // false // Button() will return true multiple times based on io.KeyRepeatDelay and io.KeyRepeatRate settings.
ImGuiItemFlags_Disabled = 1 << 2, // false // [BETA] Disable interactions but doesn't affect visuals yet. See github.com/ocornut/imgui/issues/211
@ -1541,8 +1542,8 @@ namespace ImGui
IMGUI_API void PushOverrideID(ImGuiID id);
// Basic Helpers for widget code
IMGUI_API void ItemSize(const ImVec2& size, float text_offset_y = 0.0f);
IMGUI_API void ItemSize(const ImRect& bb, float text_offset_y = 0.0f);
IMGUI_API void ItemSize(const ImVec2& size, float text_baseline_y = 0.0f);
IMGUI_API void ItemSize(const ImRect& bb, float text_baseline_y = 0.0f);
IMGUI_API bool ItemAdd(const ImRect& bb, ImGuiID id, const ImRect* nav_bb = NULL);
IMGUI_API bool ItemHoverable(const ImRect& bb, ImGuiID id);
IMGUI_API bool IsClippedEx(const ImRect& bb, ImGuiID id, bool clip_even_when_logged);
@ -1704,7 +1705,8 @@ namespace ImGui
IMGUI_API void ShadeVertsLinearUV(ImDrawList* draw_list, int vert_start_idx, int vert_end_idx, const ImVec2& a, const ImVec2& b, const ImVec2& uv_a, const ImVec2& uv_b, bool clamp);
// Debug Tools
inline void DebugStartItemPicker() { GImGui->DebugItemPickerActive = true; }
inline void DebugDrawItemRect(ImU32 col = IM_COL32(255,0,0,255)) { ImGuiContext& g = *GImGui; ImGuiWindow* window = g.CurrentWindow; GetForegroundDrawList(window)->AddRect(window->DC.LastItemRect.Min, window->DC.LastItemRect.Max, col); }
inline void DebugStartItemPicker() { ImGuiContext& g = *GImGui; g.DebugItemPickerActive = true; }
} // namespace ImGui

View File

@ -112,6 +112,7 @@ static ImVec2 InputTextCalcTextSizeW(const ImWchar* text_begin, const
//-------------------------------------------------------------------------
// [SECTION] Widgets: Text, etc.
//-------------------------------------------------------------------------
// - TextEx() [Internal]
// - TextUnformatted()
// - Text()
// - TextV()
@ -2444,7 +2445,7 @@ bool ImGui::SliderBehaviorT(const ImRect& bb, ImGuiID id, ImGuiDataType data_typ
FLOATTYPE v_new_off_f = (v_max - v_min) * clicked_t;
TYPE v_new_off_floor = (TYPE)(v_new_off_f);
TYPE v_new_off_round = (TYPE)(v_new_off_f + (FLOATTYPE)0.5);
if (!is_decimal && v_new_off_floor < v_new_off_round)
if (v_new_off_floor < v_new_off_round)
v_new = v_min + v_new_off_round;
else
v_new = v_min + v_new_off_floor;
@ -5284,9 +5285,11 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* l
{
if (pressed)
{
const float arrow_x1 = text_pos.x - text_offset_x;
const float arrow_x2 = arrow_x1 + g.FontSize + padding.x * 2.0f;
toggled = !(flags & (ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick)) || (g.NavActivateId == id);
if (flags & ImGuiTreeNodeFlags_OpenOnArrow)
toggled |= IsMouseHoveringRect(interact_bb.Min, ImVec2(interact_bb.Min.x + text_offset_x, interact_bb.Max.y)) && (!g.NavDisableMouseHover);
toggled |= IsMouseHoveringRect(ImVec2(arrow_x1, interact_bb.Min.y), ImVec2(arrow_x2, interact_bb.Max.y)) && (!g.NavDisableMouseHover);
if (flags & ImGuiTreeNodeFlags_OpenOnDoubleClick)
toggled |= g.IO.MouseDoubleClicked[0];
if (g.DragDropActive && is_open) // When using Drag and Drop "hold to open" we keep the node highlighted after opening, but never close it again.