mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-20 21:27:52 -06:00
Changes forced by imgui upgrade, updated imgui readme and
updated ImGuiWrapper::selectable function (It was a copy of ImGui::Selectable with slight changes. The function was changed a lot in ImGui 1.83, I copied the new version and reapplied the changes.)
This commit is contained in:
parent
935675a35a
commit
9244e2ae32
3 changed files with 71 additions and 53 deletions
|
@ -2,11 +2,7 @@
|
||||||
|
|
||||||
For more information go to https://github.com/ocornut/imgui
|
For more information go to https://github.com/ocornut/imgui
|
||||||
|
|
||||||
THIS DIRECTORY CONTAINS THE imgui-1.75 58b3e02 SOURCE DISTRIBUTION.
|
THIS DIRECTORY CONTAINS THE imgui-1.83 ad5d1a8 SOURCE DISTRIBUTION.
|
||||||
|
|
||||||
Customized with the following commits:
|
Customized with the following commits:
|
||||||
042880ba2df913916b2cc77f7bb677e07bfd2c58
|
f93d0001baa5443da2c6510d11b03c675e652418
|
||||||
67c55c74901f1d337ef08f2090a87cfb4263bb0f
|
|
||||||
a94c952b40d36b1505fb77b87c0dd739e1034659
|
|
||||||
3ca3a544a87cc569b69351a77996c287763388a5
|
|
||||||
6586a46ea23e86d54d228c55c63ca55680d25d56
|
|
||||||
|
|
|
@ -728,7 +728,7 @@ void GLCanvas3D::Labels::render(const std::vector<const ModelInstance*>& sorted_
|
||||||
}
|
}
|
||||||
|
|
||||||
// force re-render while the windows gets to its final size (it takes several frames)
|
// force re-render while the windows gets to its final size (it takes several frames)
|
||||||
if (ImGui::GetWindowContentRegionWidth() + 2.0f * ImGui::GetStyle().WindowPadding.x != ImGui::CalcWindowExpectedSize(ImGui::GetCurrentWindow()).x)
|
if (ImGui::GetWindowContentRegionWidth() + 2.0f * ImGui::GetStyle().WindowPadding.x != ImGui::CalcWindowNextAutoFitSize(ImGui::GetCurrentWindow()).x)
|
||||||
m_canvas.request_extra_frame();
|
m_canvas.request_extra_frame();
|
||||||
|
|
||||||
imgui.end();
|
imgui.end();
|
||||||
|
@ -779,7 +779,7 @@ void GLCanvas3D::Tooltip::render(const Vec2d& mouse_position, GLCanvas3D& canvas
|
||||||
ImGui::TextUnformatted(m_text.c_str());
|
ImGui::TextUnformatted(m_text.c_str());
|
||||||
|
|
||||||
// force re-render while the windows gets to its final size (it may take several frames) or while hidden
|
// force re-render while the windows gets to its final size (it may take several frames) or while hidden
|
||||||
if (alpha < 1.0f || ImGui::GetWindowContentRegionWidth() + 2.0f * ImGui::GetStyle().WindowPadding.x != ImGui::CalcWindowExpectedSize(ImGui::GetCurrentWindow()).x)
|
if (alpha < 1.0f || ImGui::GetWindowContentRegionWidth() + 2.0f * ImGui::GetStyle().WindowPadding.x != ImGui::CalcWindowNextAutoFitSize(ImGui::GetCurrentWindow()).x)
|
||||||
canvas.request_extra_frame();
|
canvas.request_extra_frame();
|
||||||
|
|
||||||
size = ImGui::GetWindowSize();
|
size = ImGui::GetWindowSize();
|
||||||
|
|
|
@ -524,63 +524,87 @@ static bool selectable(const char* label, bool selected, ImGuiSelectableFlags fl
|
||||||
ImGuiContext& g = *GImGui;
|
ImGuiContext& g = *GImGui;
|
||||||
const ImGuiStyle& style = g.Style;
|
const ImGuiStyle& style = g.Style;
|
||||||
|
|
||||||
if ((flags & ImGuiSelectableFlags_SpanAllColumns) && window->DC.CurrentColumns) // FIXME-OPT: Avoid if vertically clipped.
|
// Submit label or explicit size to ItemSize(), whereas ItemAdd() will submit a larger/spanning rectangle.
|
||||||
ImGui::PushColumnsBackground();
|
|
||||||
|
|
||||||
ImGuiID id = window->GetID(label);
|
ImGuiID id = window->GetID(label);
|
||||||
ImVec2 label_size = ImGui::CalcTextSize(label, NULL, true);
|
ImVec2 label_size = ImGui::CalcTextSize(label, NULL, true);
|
||||||
ImVec2 size(size_arg.x != 0.0f ? size_arg.x : label_size.x, size_arg.y != 0.0f ? size_arg.y : label_size.y);
|
ImVec2 size(size_arg.x != 0.0f ? size_arg.x : label_size.x, size_arg.y != 0.0f ? size_arg.y : label_size.y);
|
||||||
ImVec2 pos = window->DC.CursorPos;
|
ImVec2 pos = window->DC.CursorPos;
|
||||||
pos.y += window->DC.CurrLineTextBaseOffset;
|
pos.y += window->DC.CurrLineTextBaseOffset;
|
||||||
ImRect bb_inner(pos, pos + size);
|
|
||||||
ImGui::ItemSize(size, 0.0f);
|
ImGui::ItemSize(size, 0.0f);
|
||||||
|
|
||||||
// Fill horizontal space.
|
// Fill horizontal space
|
||||||
ImVec2 window_padding = window->WindowPadding;
|
// We don't support (size < 0.0f) in Selectable() because the ItemSpacing extension would make explicitly right-aligned sizes not visibly match other widgets.
|
||||||
float max_x = (flags & ImGuiSelectableFlags_SpanAllColumns) ? ImGui::GetWindowContentRegionMax().x : ImGui::GetContentRegionMax().x;
|
const bool span_all_columns = (flags & ImGuiSelectableFlags_SpanAllColumns) != 0;
|
||||||
float w_draw = ImMax(label_size.x, window->Pos.x + max_x - window_padding.x - pos.x);
|
const float min_x = span_all_columns ? window->ParentWorkRect.Min.x : pos.x;
|
||||||
ImVec2 size_draw((size_arg.x != 0 && !(flags & ImGuiSelectableFlags_DrawFillAvailWidth)) ? size_arg.x : w_draw, size_arg.y != 0.0f ? size_arg.y : size.y);
|
const float max_x = span_all_columns ? window->ParentWorkRect.Max.x : window->WorkRect.Max.x;
|
||||||
ImRect bb(pos, pos + size_draw);
|
if (size_arg.x == 0.0f || (flags & ImGuiSelectableFlags_SpanAvailWidth))
|
||||||
if (size_arg.x == 0.0f || (flags & ImGuiSelectableFlags_DrawFillAvailWidth))
|
size.x = ImMax(label_size.x, max_x - min_x);
|
||||||
bb.Max.x += window_padding.x;
|
|
||||||
|
|
||||||
// Selectables are tightly packed together so we extend the box to cover spacing between selectable.
|
// Text stays at the submission position, but bounding box may be extended on both sides
|
||||||
const float spacing_x = style.ItemSpacing.x;
|
const ImVec2 text_min = pos;
|
||||||
const float spacing_y = style.ItemSpacing.y;
|
const ImVec2 text_max(min_x + size.x, pos.y + size.y);
|
||||||
const float spacing_L = IM_FLOOR(spacing_x * 0.50f);
|
|
||||||
const float spacing_U = IM_FLOOR(spacing_y * 0.50f);
|
// Selectables are meant to be tightly packed together with no click-gap, so we extend their box to cover spacing between selectable.
|
||||||
bb.Min.x -= spacing_L;
|
ImRect bb(min_x, pos.y, text_max.x, text_max.y);
|
||||||
bb.Min.y -= spacing_U;
|
if ((flags & ImGuiSelectableFlags_NoPadWithHalfSpacing) == 0)
|
||||||
bb.Max.x += (spacing_x - spacing_L);
|
{
|
||||||
bb.Max.y += (spacing_y - spacing_U);
|
const float spacing_x = span_all_columns ? 0.0f : style.ItemSpacing.x;
|
||||||
|
const float spacing_y = style.ItemSpacing.y;
|
||||||
|
const float spacing_L = IM_FLOOR(spacing_x * 0.50f);
|
||||||
|
const float spacing_U = IM_FLOOR(spacing_y * 0.50f);
|
||||||
|
bb.Min.x -= spacing_L;
|
||||||
|
bb.Min.y -= spacing_U;
|
||||||
|
bb.Max.x += (spacing_x - spacing_L);
|
||||||
|
bb.Max.y += (spacing_y - spacing_U);
|
||||||
|
}
|
||||||
|
//if (g.IO.KeyCtrl) { GetForegroundDrawList()->AddRect(bb.Min, bb.Max, IM_COL32(0, 255, 0, 255)); }
|
||||||
|
|
||||||
|
// Modify ClipRect for the ItemAdd(), faster than doing a PushColumnsBackground/PushTableBackground for every Selectable..
|
||||||
|
const float backup_clip_rect_min_x = window->ClipRect.Min.x;
|
||||||
|
const float backup_clip_rect_max_x = window->ClipRect.Max.x;
|
||||||
|
if (span_all_columns)
|
||||||
|
{
|
||||||
|
window->ClipRect.Min.x = window->ParentWorkRect.Min.x;
|
||||||
|
window->ClipRect.Max.x = window->ParentWorkRect.Max.x;
|
||||||
|
}
|
||||||
|
|
||||||
bool item_add;
|
bool item_add;
|
||||||
if (flags & ImGuiSelectableFlags_Disabled)
|
if (flags & ImGuiSelectableFlags_Disabled)
|
||||||
{
|
{
|
||||||
ImGuiItemFlags backup_item_flags = window->DC.ItemFlags;
|
ImGuiItemFlags backup_item_flags = g.CurrentItemFlags;
|
||||||
window->DC.ItemFlags |= ImGuiItemFlags_Disabled | ImGuiItemFlags_NoNavDefaultFocus;
|
g.CurrentItemFlags |= ImGuiItemFlags_Disabled | ImGuiItemFlags_NoNavDefaultFocus;
|
||||||
item_add = ImGui::ItemAdd(bb, id);
|
item_add = ImGui::ItemAdd(bb, id);
|
||||||
window->DC.ItemFlags = backup_item_flags;
|
g.CurrentItemFlags = backup_item_flags;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
item_add = ImGui::ItemAdd(bb, id);
|
item_add = ImGui::ItemAdd(bb, id);
|
||||||
}
|
}
|
||||||
if (!item_add)
|
|
||||||
|
if (span_all_columns)
|
||||||
{
|
{
|
||||||
if ((flags & ImGuiSelectableFlags_SpanAllColumns) && window->DC.CurrentColumns)
|
window->ClipRect.Min.x = backup_clip_rect_min_x;
|
||||||
ImGui::PopColumnsBackground();
|
window->ClipRect.Max.x = backup_clip_rect_max_x;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!item_add)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// FIXME: We can standardize the behavior of those two, we could also keep the fast path of override ClipRect + full push on render only,
|
||||||
|
// which would be advantageous since most selectable are not selected.
|
||||||
|
if (span_all_columns && window->DC.CurrentColumns)
|
||||||
|
ImGui::PushColumnsBackground();
|
||||||
|
else if (span_all_columns && g.CurrentTable)
|
||||||
|
ImGui::TablePushBackgroundChannel();
|
||||||
|
|
||||||
// We use NoHoldingActiveID on menus so user can click and _hold_ on a menu then drag to browse child entries
|
// We use NoHoldingActiveID on menus so user can click and _hold_ on a menu then drag to browse child entries
|
||||||
ImGuiButtonFlags button_flags = 0;
|
ImGuiButtonFlags button_flags = 0;
|
||||||
if (flags & ImGuiSelectableFlags_NoHoldingActiveID) { button_flags |= ImGuiButtonFlags_NoHoldingActiveId; }
|
if (flags & ImGuiSelectableFlags_NoHoldingActiveID) { button_flags |= ImGuiButtonFlags_NoHoldingActiveId; }
|
||||||
if (flags & ImGuiSelectableFlags_PressedOnClick) { button_flags |= ImGuiButtonFlags_PressedOnClick; }
|
if (flags & ImGuiSelectableFlags_SelectOnClick) { button_flags |= ImGuiButtonFlags_PressedOnClick; }
|
||||||
if (flags & ImGuiSelectableFlags_PressedOnRelease) { button_flags |= ImGuiButtonFlags_PressedOnRelease; }
|
if (flags & ImGuiSelectableFlags_SelectOnRelease) { button_flags |= ImGuiButtonFlags_PressedOnRelease; }
|
||||||
if (flags & ImGuiSelectableFlags_Disabled) { button_flags |= ImGuiButtonFlags_Disabled; }
|
if (flags & ImGuiSelectableFlags_Disabled) { button_flags |= ImGuiButtonFlags_Disabled; }
|
||||||
if (flags & ImGuiSelectableFlags_AllowDoubleClick) { button_flags |= ImGuiButtonFlags_PressedOnClickRelease | ImGuiButtonFlags_PressedOnDoubleClick; }
|
if (flags & ImGuiSelectableFlags_AllowDoubleClick) { button_flags |= ImGuiButtonFlags_PressedOnClickRelease | ImGuiButtonFlags_PressedOnDoubleClick; }
|
||||||
if (flags & ImGuiSelectableFlags_AllowItemOverlap) { button_flags |= ImGuiButtonFlags_AllowItemOverlap; }
|
if (flags & ImGuiSelectableFlags_AllowItemOverlap) { button_flags |= ImGuiButtonFlags_AllowItemOverlap; }
|
||||||
|
|
||||||
if (flags & ImGuiSelectableFlags_Disabled)
|
if (flags & ImGuiSelectableFlags_Disabled)
|
||||||
selected = false;
|
selected = false;
|
||||||
|
@ -594,8 +618,8 @@ static bool selectable(const char* label, bool selected, ImGuiSelectableFlags fl
|
||||||
{
|
{
|
||||||
if (!g.NavDisableMouseHover && g.NavWindow == window && g.NavLayer == window->DC.NavLayerCurrent)
|
if (!g.NavDisableMouseHover && g.NavWindow == window && g.NavLayer == window->DC.NavLayerCurrent)
|
||||||
{
|
{
|
||||||
|
ImGui::SetNavID(id, window->DC.NavLayerCurrent, window->DC.NavFocusScopeIdCurrent, ImRect(bb.Min - window->Pos, bb.Max - window->Pos));
|
||||||
g.NavDisableHighlight = true;
|
g.NavDisableHighlight = true;
|
||||||
ImGui::SetNavID(id, window->DC.NavLayerCurrent, window->DC.NavFocusScopeIdCurrent);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (pressed)
|
if (pressed)
|
||||||
|
@ -618,29 +642,27 @@ static bool selectable(const char* label, bool selected, ImGuiSelectableFlags fl
|
||||||
ImGui::RenderNavHighlight(bb, id, ImGuiNavHighlightFlags_TypeThin | ImGuiNavHighlightFlags_NoRounding);
|
ImGui::RenderNavHighlight(bb, id, ImGuiNavHighlightFlags_TypeThin | ImGuiNavHighlightFlags_NoRounding);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((flags & ImGuiSelectableFlags_SpanAllColumns) && window->DC.CurrentColumns)
|
if (span_all_columns && window->DC.CurrentColumns)
|
||||||
{
|
|
||||||
ImGui::PopColumnsBackground();
|
ImGui::PopColumnsBackground();
|
||||||
bb.Max.x -= (ImGui::GetContentRegionMax().x - max_x);
|
else if (span_all_columns && g.CurrentTable)
|
||||||
}
|
ImGui::TablePopBackgroundChannel();
|
||||||
|
|
||||||
// mark a label with a ImGui::ColorMarkerHovered, if item is hovered
|
// mark a label with a ColorMarkerHovered, if item is hovered
|
||||||
char* marked_label = new char[512]; //255 symbols is not enough for translated string (e.t. to Russian)
|
char marked_label[512]; //255 symbols is not enough for translated string (e.t. to Russian)
|
||||||
if (hovered)
|
if (hovered)
|
||||||
sprintf(marked_label, "%c%s", ImGui::ColorMarkerHovered, label);
|
sprintf(marked_label, "%c%s", ImGui::ColorMarkerHovered, label);
|
||||||
else
|
else
|
||||||
strcpy(marked_label, label);
|
strcpy(marked_label, label);
|
||||||
|
|
||||||
if (flags & ImGuiSelectableFlags_Disabled) ImGui::PushStyleColor(ImGuiCol_Text, style.Colors[ImGuiCol_TextDisabled]);
|
if (flags & ImGuiSelectableFlags_Disabled) ImGui::PushStyleColor(ImGuiCol_Text, style.Colors[ImGuiCol_TextDisabled]);
|
||||||
ImGui::RenderTextClipped(bb_inner.Min, bb_inner.Max, marked_label, NULL, &label_size, style.SelectableTextAlign, &bb);
|
ImGui::RenderTextClipped(text_min, text_max, marked_label, NULL, &label_size, style.SelectableTextAlign, &bb);
|
||||||
if (flags & ImGuiSelectableFlags_Disabled) ImGui::PopStyleColor();
|
if (flags & ImGuiSelectableFlags_Disabled) ImGui::PopStyleColor();
|
||||||
|
|
||||||
delete[] marked_label;
|
|
||||||
|
|
||||||
// Automatically close popups
|
// Automatically close popups
|
||||||
if (pressed && (window->Flags & ImGuiWindowFlags_Popup) && !(flags & ImGuiSelectableFlags_DontClosePopups) && !(window->DC.ItemFlags & ImGuiItemFlags_SelectableDontClosePopup)) ImGui::CloseCurrentPopup();
|
if (pressed && (window->Flags & ImGuiWindowFlags_Popup) && !(flags & ImGuiSelectableFlags_DontClosePopups) && !(g.CurrentItemFlags & ImGuiItemFlags_SelectableDontClosePopup))
|
||||||
|
ImGui::CloseCurrentPopup();
|
||||||
|
|
||||||
IMGUI_TEST_ENGINE_ITEM_INFO(id, label, window->DC.ItemFlags);
|
IMGUI_TEST_ENGINE_ITEM_INFO(id, label, window->DC.LastItemStatusFlags);
|
||||||
return pressed;
|
return pressed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue