Skip to content

Commit cc1283f

Browse files
committed
Added ImGuiWindowFlags_UnsavedDocument window flag to append '*' to title without altering the ID, as a convenience to avoid using the ### operator. (merged from Docking branch)
1 parent 15447f5 commit cc1283f

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

docs/CHANGELOG.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ Breaking Changes:
3939
The addition of new configuration options in the Docking branch is pushing for a little reorganization of those names.
4040

4141
Other Changes:
42+
- Added ImGuiWindowFlags_UnsavedDocument window flag to append '*' to title without altering
43+
the ID, as a convenience to avoid using the ### operator.
4244
- Resizing windows from edge is now enabled by default (io.ConfigWindowsResizeFromEdges=true). Note that
4345
it only works _if_ the back-end sets ImGuiBackendFlags_HasMouseCursors, which the standard back-end do.
4446
- Added io.ConfigWindowsMoveFromTitleBarOnly option. Still is ignored by window with no title bars (often popups).

imgui.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5093,8 +5093,11 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
50935093
window->DC.NavLayerCurrentMask = (1 << ImGuiNavLayer_Main);
50945094
window->DC.ItemFlags = item_flags_backup;
50955095

5096-
// Title text (FIXME: refactor text alignment facilities along with RenderText helpers, this is too much code for what it does.)
5097-
ImVec2 text_size = CalcTextSize(name, NULL, true);
5096+
// Title bar text (with: horizontal alignment, avoiding collapse/close button, optional "unsaved document" marker)
5097+
// FIXME: Refactor text alignment facilities along with RenderText helpers, this is too much code..
5098+
const char* UNSAVED_DOCUMENT_MARKER = "*";
5099+
float marker_size_x = (flags & ImGuiWindowFlags_UnsavedDocument) ? CalcTextSize(UNSAVED_DOCUMENT_MARKER, NULL, false).x : 0.0f;
5100+
ImVec2 text_size = CalcTextSize(name, NULL, true) + ImVec2(marker_size_x, 0.0f);
50985101
ImRect text_r = title_bar_rect;
50995102
float pad_left = (flags & ImGuiWindowFlags_NoCollapse) ? style.FramePadding.x : (style.FramePadding.x + g.FontSize + style.ItemInnerSpacing.x);
51005103
float pad_right = (p_open == NULL) ? style.FramePadding.x : (style.FramePadding.x + g.FontSize + style.ItemInnerSpacing.x);
@@ -5105,6 +5108,12 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
51055108
ImRect clip_rect = text_r;
51065109
clip_rect.Max.x = window->Pos.x + window->Size.x - (p_open ? title_bar_rect.GetHeight() - 3 : style.FramePadding.x); // Match the size of CloseButton()
51075110
RenderTextClipped(text_r.Min, text_r.Max, name, NULL, &text_size, style.WindowTitleAlign, &clip_rect);
5111+
if (flags & ImGuiWindowFlags_UnsavedDocument)
5112+
{
5113+
ImVec2 marker_pos = ImVec2(ImMax(text_r.Min.x, text_r.Min.x + (text_r.GetWidth() - text_size.x) * style.WindowTitleAlign.x) + text_size.x, text_r.Min.y) + ImVec2(2 - marker_size_x, 0.0f);
5114+
ImVec2 off = ImVec2(0.0f, (float)(int)(-g.FontSize * 0.25f));
5115+
RenderTextClipped(marker_pos + off, text_r.Max + off, UNSAVED_DOCUMENT_MARKER, NULL, NULL, ImVec2(0, style.WindowTitleAlign.y), &clip_rect);
5116+
}
51085117
}
51095118

51105119
// Save clipped aabb so we can access it in constant-time in FindHoveredWindow()

imgui.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,7 @@ enum ImGuiWindowFlags_
665665
ImGuiWindowFlags_AlwaysUseWindowPadding = 1 << 16, // Ensure child windows without border uses style.WindowPadding (ignored by default for non-bordered child windows, because more convenient)
666666
ImGuiWindowFlags_NoNavInputs = 1 << 18, // No gamepad/keyboard navigation within the window
667667
ImGuiWindowFlags_NoNavFocus = 1 << 19, // No focusing toward this window with gamepad/keyboard navigation (e.g. skipped by CTRL+TAB)
668+
ImGuiWindowFlags_UnsavedDocument = 1 << 20, // Append '*' to title without affecting the ID, as a convenience to avoid using the ### operator. When used in a tab/docking context, tab is selected on closure and closure is deferred by one frame to allow code to cancel the closure (with a confirmation popup, etc.) without flicker.
668669
ImGuiWindowFlags_NoNav = ImGuiWindowFlags_NoNavInputs | ImGuiWindowFlags_NoNavFocus,
669670
ImGuiWindowFlags_NoDecoration = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoCollapse,
670671
ImGuiWindowFlags_NoInputs = ImGuiWindowFlags_NoMouseInputs | ImGuiWindowFlags_NoNavInputs | ImGuiWindowFlags_NoNavFocus,

0 commit comments

Comments
 (0)