MCPcopy Create free account
hub / github.com/KebsCS/KBotExt / RenderWindowTitleBarContents

Method RenderWindowTitleBarContents

KBotExt/imgui/imgui.cpp:6059–6145  ·  view source on GitHub ↗

Render title text, collapse button, close button

Source from the content-addressed store, hash-verified

6057
6058// Render title text, collapse button, close button
6059void ImGui::RenderWindowTitleBarContents(ImGuiWindow* window, const ImRect& title_bar_rect, const char* name, bool* p_open)
6060{
6061 ImGuiContext& g = *GImGui;
6062 ImGuiStyle& style = g.Style;
6063 ImGuiWindowFlags flags = window->Flags;
6064
6065 const bool has_close_button = (p_open != NULL);
6066 const bool has_collapse_button = !(flags & ImGuiWindowFlags_NoCollapse) && (style.WindowMenuButtonPosition != ImGuiDir_None);
6067
6068 // Close & Collapse button are on the Menu NavLayer and don't default focus (unless there's nothing else on that layer)
6069 // FIXME-NAV: Might want (or not?) to set the equivalent of ImGuiButtonFlags_NoNavFocus so that mouse clicks on standard title bar items don't necessarily set nav/keyboard ref?
6070 const ImGuiItemFlags item_flags_backup = g.CurrentItemFlags;
6071 g.CurrentItemFlags |= ImGuiItemFlags_NoNavDefaultFocus;
6072 window->DC.NavLayerCurrent = ImGuiNavLayer_Menu;
6073
6074 // Layout buttons
6075 // FIXME: Would be nice to generalize the subtleties expressed here into reusable code.
6076 float pad_l = style.FramePadding.x;
6077 float pad_r = style.FramePadding.x;
6078 float button_sz = g.FontSize;
6079 ImVec2 close_button_pos;
6080 ImVec2 collapse_button_pos;
6081 if (has_close_button)
6082 {
6083 close_button_pos = ImVec2(title_bar_rect.Max.x - pad_r - button_sz, title_bar_rect.Min.y + style.FramePadding.y);
6084 pad_r += button_sz + style.ItemInnerSpacing.x;
6085 }
6086 if (has_collapse_button && style.WindowMenuButtonPosition == ImGuiDir_Right)
6087 {
6088 collapse_button_pos = ImVec2(title_bar_rect.Max.x - pad_r - button_sz, title_bar_rect.Min.y + style.FramePadding.y);
6089 pad_r += button_sz + style.ItemInnerSpacing.x;
6090 }
6091 if (has_collapse_button && style.WindowMenuButtonPosition == ImGuiDir_Left)
6092 {
6093 collapse_button_pos = ImVec2(title_bar_rect.Min.x + pad_l, title_bar_rect.Min.y + style.FramePadding.y);
6094 pad_l += button_sz + style.ItemInnerSpacing.x;
6095 }
6096
6097 // Collapse button (submitting first so it gets priority when choosing a navigation init fallback)
6098 if (has_collapse_button)
6099 if (CollapseButton(window->GetID("#COLLAPSE"), collapse_button_pos))
6100 window->WantCollapseToggle = true; // Defer actual collapsing to next frame as we are too far in the Begin() function
6101
6102 // Close button
6103 if (has_close_button)
6104 if (CloseButton(window->GetID("#CLOSE"), close_button_pos))
6105 *p_open = false;
6106
6107 window->DC.NavLayerCurrent = ImGuiNavLayer_Main;
6108 g.CurrentItemFlags = item_flags_backup;
6109
6110 // Title bar text (with: horizontal alignment, avoiding collapse/close button, optional "unsaved document" marker)
6111 // FIXME: Refactor text alignment facilities along with RenderText helpers, this is WAY too much messy code..
6112 const float marker_size_x = (flags & ImGuiWindowFlags_UnsavedDocument) ? button_sz * 0.80f : 0.0f;
6113 const ImVec2 text_size = CalcTextSize(name, NULL, true) + ImVec2(marker_size_x, 0.0f);
6114
6115 // As a nice touch we try to ensure that centered title text doesn't get affected by visibility of Close/Collapse button,
6116 // while uncentered title text will still reach edges correctly.

Callers

nothing calls this directly

Calls 6

ImVec2Function · 0.85
ImSaturateFunction · 0.85
ImMinFunction · 0.85
ImMaxFunction · 0.85
ImClampFunction · 0.85
GetIDMethod · 0.80

Tested by

no test coverage detected