Skip to content

Commit 59b63de

Browse files
committed
Misc shallow merge/sync from docking designed to faciliate cross-merging between docking and string_view.
1 parent 317b33d commit 59b63de

File tree

4 files changed

+48
-25
lines changed

4 files changed

+48
-25
lines changed

imgui.cpp

+7-5
Original file line numberDiff line numberDiff line change
@@ -1027,7 +1027,7 @@ static void UpdateKeyRoutingTable(ImGuiKeyRoutingTable* rt);
10271027
static void UpdateSettings();
10281028
static bool UpdateWindowManualResize(ImGuiWindow* window, const ImVec2& size_auto_fit, int* border_held, int resize_grip_count, ImU32 resize_grip_col[4], const ImRect& visibility_rect);
10291029
static void RenderWindowOuterBorders(ImGuiWindow* window);
1030-
static void RenderWindowDecorations(ImGuiWindow* window, const ImRect& title_bar_rect, bool title_bar_is_highlight, int resize_grip_count, const ImU32 resize_grip_col[4], float resize_grip_draw_size);
1030+
static void RenderWindowDecorations(ImGuiWindow* window, const ImRect& title_bar_rect, bool title_bar_is_highlight, bool handle_borders_and_resize_grips, int resize_grip_count, const ImU32 resize_grip_col[4], float resize_grip_draw_size);
10311031
static void RenderWindowTitleBarContents(ImGuiWindow* window, const ImRect& title_bar_rect, const char* name, bool* p_open);
10321032
static void RenderDimmedBackgroundBehindWindow(ImGuiWindow* window, ImU32 col);
10331033
static void RenderDimmedBackgrounds();
@@ -5765,7 +5765,7 @@ static void ImGui::RenderWindowOuterBorders(ImGuiWindow* window)
57655765

57665766
// Draw background and borders
57675767
// Draw and handle scrollbars
5768-
void ImGui::RenderWindowDecorations(ImGuiWindow* window, const ImRect& title_bar_rect, bool title_bar_is_highlight, int resize_grip_count, const ImU32 resize_grip_col[4], float resize_grip_draw_size)
5768+
void ImGui::RenderWindowDecorations(ImGuiWindow* window, const ImRect& title_bar_rect, bool title_bar_is_highlight, bool handle_borders_and_resize_grips, int resize_grip_count, const ImU32 resize_grip_col[4], float resize_grip_draw_size)
57695769
{
57705770
ImGuiContext& g = *GImGui;
57715771
ImGuiStyle& style = g.Style;
@@ -5830,7 +5830,7 @@ void ImGui::RenderWindowDecorations(ImGuiWindow* window, const ImRect& title_bar
58305830
Scrollbar(ImGuiAxis_Y);
58315831

58325832
// Render resize grips (after their input handling so we don't have a frame of latency)
5833-
if (!(flags & ImGuiWindowFlags_NoResize))
5833+
if (handle_borders_and_resize_grips && !(flags & ImGuiWindowFlags_NoResize))
58345834
{
58355835
for (int resize_grip_n = 0; resize_grip_n < resize_grip_count; resize_grip_n++)
58365836
{
@@ -5844,7 +5844,8 @@ void ImGui::RenderWindowDecorations(ImGuiWindow* window, const ImRect& title_bar
58445844
}
58455845

58465846
// Borders
5847-
RenderWindowOuterBorders(window);
5847+
if (handle_borders_and_resize_grips)
5848+
RenderWindowOuterBorders(window);
58485849
}
58495850
}
58505851

@@ -6503,7 +6504,8 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
65036504
// Handle title bar, scrollbar, resize grips and resize borders
65046505
const ImGuiWindow* window_to_highlight = g.NavWindowingTarget ? g.NavWindowingTarget : g.NavWindow;
65056506
const bool title_bar_is_highlight = want_focus || (window_to_highlight && window->RootWindowForTitleBarHighlight == window_to_highlight->RootWindowForTitleBarHighlight);
6506-
RenderWindowDecorations(window, title_bar_rect, title_bar_is_highlight, resize_grip_count, resize_grip_col, resize_grip_draw_size);
6507+
const bool handle_borders_and_resize_grips = true; // This exists to facilitate merge with 'docking' branch.
6508+
RenderWindowDecorations(window, title_bar_rect, title_bar_is_highlight, handle_borders_and_resize_grips, resize_grip_count, resize_grip_col, resize_grip_draw_size);
65076509

65086510
if (render_decorations_in_parent)
65096511
window->DrawList = &window->DrawListInst;

imgui.h

+1
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,7 @@ namespace ImGui
783783
IMGUI_API int GetColumnsCount();
784784

785785
// Tab Bars, Tabs
786+
// - Note: Tabs are automatically created by the docking system (when in 'docking' branch). Use this to create tab bars/tabs yourself.
786787
IMGUI_API bool BeginTabBar(const char* str_id, ImGuiTabBarFlags flags = 0); // create and append into a TabBar
787788
IMGUI_API void EndTabBar(); // only call EndTabBar() if BeginTabBar() returns true!
788789
IMGUI_API bool BeginTabItem(const char* label, bool* p_open = NULL, ImGuiTabItemFlags flags = 0); // create a Tab. Returns true if the Tab is selected.

imgui_internal.h

+10-7
Original file line numberDiff line numberDiff line change
@@ -3017,8 +3017,9 @@ namespace ImGui
30173017
IMGUI_API void TabBarQueueReorder(ImGuiTabBar* tab_bar, const ImGuiTabItem* tab, int offset);
30183018
IMGUI_API void TabBarQueueReorderFromMousePos(ImGuiTabBar* tab_bar, const ImGuiTabItem* tab, ImVec2 mouse_pos);
30193019
IMGUI_API bool TabBarProcessReorder(ImGuiTabBar* tab_bar);
3020-
IMGUI_API bool TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open, ImGuiTabItemFlags flags);
3020+
IMGUI_API bool TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open, ImGuiTabItemFlags flags, ImGuiWindow* docked_window);
30213021
IMGUI_API ImVec2 TabItemCalcSize(const char* label, bool has_close_button_or_unsaved_marker);
3022+
IMGUI_API ImVec2 TabItemCalcSize(ImGuiWindow* window);
30223023
IMGUI_API void TabItemBackground(ImDrawList* draw_list, const ImRect& bb, ImGuiTabItemFlags flags, ImU32 col);
30233024
IMGUI_API void TabItemLabelAndCloseButton(ImDrawList* draw_list, const ImRect& bb, ImGuiTabItemFlags flags, ImVec2 frame_padding, const char* label, ImGuiID tab_id, ImGuiID close_button_id, bool is_contents_visible, bool* out_just_closed, bool* out_text_clipped);
30243025

@@ -3048,25 +3049,27 @@ namespace ImGui
30483049
// Widgets
30493050
IMGUI_API void TextEx(const char* text, const char* text_end = NULL, ImGuiTextFlags flags = 0);
30503051
IMGUI_API bool ButtonEx(const char* label, const ImVec2& size_arg = ImVec2(0, 0), ImGuiButtonFlags flags = 0);
3052+
IMGUI_API bool ArrowButtonEx(const char* str_id, ImGuiDir dir, ImVec2 size_arg, ImGuiButtonFlags flags = 0);
3053+
IMGUI_API bool ImageButtonEx(ImGuiID id, ImTextureID texture_id, const ImVec2& size, const ImVec2& uv0, const ImVec2& uv1, const ImVec4& bg_col, const ImVec4& tint_col);
3054+
IMGUI_API void SeparatorEx(ImGuiSeparatorFlags flags);
3055+
IMGUI_API bool CheckboxFlags(const char* label, ImS64* flags, ImS64 flags_value);
3056+
IMGUI_API bool CheckboxFlags(const char* label, ImU64* flags, ImU64 flags_value);
3057+
3058+
// Widgets: Window Decorations
30513059
IMGUI_API bool CloseButton(ImGuiID id, const ImVec2& pos);
30523060
IMGUI_API bool CollapseButton(ImGuiID id, const ImVec2& pos);
3053-
IMGUI_API bool ArrowButtonEx(const char* str_id, ImGuiDir dir, ImVec2 size_arg, ImGuiButtonFlags flags = 0);
30543061
IMGUI_API void Scrollbar(ImGuiAxis axis);
30553062
IMGUI_API bool ScrollbarEx(const ImRect& bb, ImGuiID id, ImGuiAxis axis, ImS64* p_scroll_v, ImS64 avail_v, ImS64 contents_v, ImDrawFlags flags);
3056-
IMGUI_API bool ImageButtonEx(ImGuiID id, ImTextureID texture_id, const ImVec2& size, const ImVec2& uv0, const ImVec2& uv1, const ImVec4& bg_col, const ImVec4& tint_col);
30573063
IMGUI_API ImRect GetWindowScrollbarRect(ImGuiWindow* window, ImGuiAxis axis);
30583064
IMGUI_API ImGuiID GetWindowScrollbarID(ImGuiWindow* window, ImGuiAxis axis);
30593065
IMGUI_API ImGuiID GetWindowResizeCornerID(ImGuiWindow* window, int n); // 0..3: corners
30603066
IMGUI_API ImGuiID GetWindowResizeBorderID(ImGuiWindow* window, ImGuiDir dir);
3061-
IMGUI_API void SeparatorEx(ImGuiSeparatorFlags flags);
3062-
IMGUI_API bool CheckboxFlags(const char* label, ImS64* flags, ImS64 flags_value);
3063-
IMGUI_API bool CheckboxFlags(const char* label, ImU64* flags, ImU64 flags_value);
30643067

30653068
// Widgets low-level behaviors
30663069
IMGUI_API bool ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool* out_held, ImGuiButtonFlags flags = 0);
30673070
IMGUI_API bool DragBehavior(ImGuiID id, ImGuiDataType data_type, void* p_v, float v_speed, const void* p_min, const void* p_max, const char* format, ImGuiSliderFlags flags);
30683071
IMGUI_API bool SliderBehavior(const ImRect& bb, ImGuiID id, ImGuiDataType data_type, void* p_v, const void* p_min, const void* p_max, const char* format, ImGuiSliderFlags flags, ImRect* out_grab_bb);
3069-
IMGUI_API bool SplitterBehavior(const ImRect& bb, ImGuiID id, ImGuiAxis axis, float* size1, float* size2, float min_size1, float min_size2, float hover_extend = 0.0f, float hover_visibility_delay = 0.0f);
3072+
IMGUI_API bool SplitterBehavior(const ImRect& bb, ImGuiID id, ImGuiAxis axis, float* size1, float* size2, float min_size1, float min_size2, float hover_extend = 0.0f, float hover_visibility_delay = 0.0f, ImU32 bg_col = 0);
30703073
IMGUI_API bool TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* label, const char* label_end = NULL);
30713074
IMGUI_API void TreePushOverrideID(ImGuiID id);
30723075
IMGUI_API void TreeNodeSetOpen(ImGuiID id, bool open);

imgui_widgets.cpp

+30-13
Original file line numberDiff line numberDiff line change
@@ -1473,7 +1473,7 @@ void ImGui::Separator()
14731473
}
14741474

14751475
// Using 'hover_visibility_delay' allows us to hide the highlight and mouse cursor for a short time, which can be convenient to reduce visual noise.
1476-
bool ImGui::SplitterBehavior(const ImRect& bb, ImGuiID id, ImGuiAxis axis, float* size1, float* size2, float min_size1, float min_size2, float hover_extend, float hover_visibility_delay)
1476+
bool ImGui::SplitterBehavior(const ImRect& bb, ImGuiID id, ImGuiAxis axis, float* size1, float* size2, float min_size1, float min_size2, float hover_extend, float hover_visibility_delay, ImU32 bg_col)
14771477
{
14781478
ImGuiContext& g = *GImGui;
14791479
ImGuiWindow* window = g.CurrentWindow;
@@ -1521,7 +1521,9 @@ bool ImGui::SplitterBehavior(const ImRect& bb, ImGuiID id, ImGuiAxis axis, float
15211521
}
15221522
}
15231523

1524-
// Render
1524+
// Render at new position
1525+
if (bg_col & IM_COL32_A_MASK)
1526+
window->DrawList->AddRectFilled(bb_render.Min, bb_render.Max, bg_col, 0.0f);
15251527
const ImU32 col = GetColorU32(held ? ImGuiCol_SeparatorActive : (hovered && g.HoveredIdTimer >= hover_visibility_delay) ? ImGuiCol_SeparatorHovered : ImGuiCol_Separator);
15261528
window->DrawList->AddRectFilled(bb_render.Min, bb_render.Max, col, 0.0f);
15271529

@@ -7303,7 +7305,7 @@ struct ImGuiTabBarSection
73037305
namespace ImGui
73047306
{
73057307
static void TabBarLayout(ImGuiTabBar* tab_bar);
7306-
static ImU32 TabBarCalcTabID(ImGuiTabBar* tab_bar, const char* label);
7308+
static ImU32 TabBarCalcTabID(ImGuiTabBar* tab_bar, const char* label, ImGuiWindow* docked_window);
73077309
static float TabBarCalcMaxTabWidth();
73087310
static float TabBarScrollClamp(ImGuiTabBar* tab_bar, float scrolling);
73097311
static void TabBarScrollToTab(ImGuiTabBar* tab_bar, ImGuiID tab_id, ImGuiTabBarSection* sections);
@@ -7696,9 +7698,11 @@ static void ImGui::TabBarLayout(ImGuiTabBar* tab_bar)
76967698
window->DC.IdealMaxPos.x = ImMax(window->DC.IdealMaxPos.x, tab_bar->BarRect.Min.x + tab_bar->WidthAllTabsIdeal);
76977699
}
76987700

7699-
// Dockables uses Name/ID in the global namespace. Non-dockable items use the ID stack.
7700-
static ImU32 ImGui::TabBarCalcTabID(ImGuiTabBar* tab_bar, const char* label)
7701+
// Dockable windows uses Name/ID in the global namespace. Non-dockable items use the ID stack.
7702+
static ImU32 ImGui::TabBarCalcTabID(ImGuiTabBar* tab_bar, const char* label, ImGuiWindow* docked_window)
77017703
{
7704+
IM_ASSERT(docked_window == NULL); // master branch only
7705+
IM_UNUSED(docked_window);
77027706
if (tab_bar->Flags & ImGuiTabBarFlags_DockNode)
77037707
{
77047708
ImGuiID id = ImHashStr(label);
@@ -8005,7 +8009,7 @@ bool ImGui::BeginTabItem(const char* label, bool* p_open, ImGuiTabItemFlags f
80058009
}
80068010
IM_ASSERT(!(flags & ImGuiTabItemFlags_Button)); // BeginTabItem() Can't be used with button flags, use TabItemButton() instead!
80078011

8008-
bool ret = TabItemEx(tab_bar, label, p_open, flags);
8012+
bool ret = TabItemEx(tab_bar, label, p_open, flags, NULL);
80098013
if (ret && !(flags & ImGuiTabItemFlags_NoPushId))
80108014
{
80118015
ImGuiTabItem* tab = &tab_bar->Tabs[tab_bar->LastTabItemIdx];
@@ -8046,10 +8050,10 @@ bool ImGui::TabItemButton(const char* label, ImGuiTabItemFlags flags)
80468050
IM_ASSERT_USER_ERROR(tab_bar != NULL, "Needs to be called between BeginTabBar() and EndTabBar()!");
80478051
return false;
80488052
}
8049-
return TabItemEx(tab_bar, label, NULL, flags | ImGuiTabItemFlags_Button | ImGuiTabItemFlags_NoReorder);
8053+
return TabItemEx(tab_bar, label, NULL, flags | ImGuiTabItemFlags_Button | ImGuiTabItemFlags_NoReorder, NULL);
80508054
}
80518055

8052-
bool ImGui::TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open, ImGuiTabItemFlags flags)
8056+
bool ImGui::TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open, ImGuiTabItemFlags flags, ImGuiWindow* docked_window)
80538057
{
80548058
// Layout whole tab bar if not already done
80558059
ImGuiContext& g = *GImGui;
@@ -8064,7 +8068,7 @@ bool ImGui::TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open,
80648068
return false;
80658069

80668070
const ImGuiStyle& style = g.Style;
8067-
const ImGuiID id = TabBarCalcTabID(tab_bar, label);
8071+
const ImGuiID id = TabBarCalcTabID(tab_bar, label, docked_window);
80688072

80698073
// If the user called us with *p_open == false, we early out and don't render.
80708074
// We make a call to ItemAdd() so that attempts to use a contextual popup menu with an implicit ID won't use an older ID.
@@ -8114,9 +8118,16 @@ bool ImGui::TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open,
81148118
tab->LastFrameVisible = g.FrameCount;
81158119
tab->Flags = flags;
81168120

8117-
// Append name with zero-terminator
8118-
tab->NameOffset = (ImS32)tab_bar->TabsNames.size();
8119-
tab_bar->TabsNames.append(label, label + strlen(label) + 1);
8121+
// Append name _WITH_ the zero-terminator
8122+
if (docked_window != NULL)
8123+
{
8124+
IM_ASSERT(docked_window == NULL); // master branch only
8125+
}
8126+
else
8127+
{
8128+
tab->NameOffset = (ImS32)tab_bar->TabsNames.size();
8129+
tab_bar->TabsNames.append(label, label + strlen(label) + 1);
8130+
}
81208131

81218132
// Update selected tab
81228133
if (!is_tab_button)
@@ -8279,7 +8290,7 @@ void ImGui::SetTabItemClosed(const char* label)
82798290
if (is_within_manual_tab_bar)
82808291
{
82818292
ImGuiTabBar* tab_bar = g.CurrentTabBar;
8282-
ImGuiID tab_id = TabBarCalcTabID(tab_bar, label);
8293+
ImGuiID tab_id = TabBarCalcTabID(tab_bar, label, NULL);
82838294
if (ImGuiTabItem* tab = TabBarFindTabByID(tab_bar, tab_id))
82848295
tab->WantClose = true; // Will be processed by next call to TabBarLayout()
82858296
}
@@ -8297,6 +8308,12 @@ ImVec2 ImGui::TabItemCalcSize(const char* label, bool has_close_button_or_unsave
82978308
return ImVec2(ImMin(size.x, TabBarCalcMaxTabWidth()), size.y);
82988309
}
82998310

8311+
ImVec2 ImGui::TabItemCalcSize(ImGuiWindow*)
8312+
{
8313+
IM_ASSERT(0); // This function exists to facilitate merge with 'docking' branch.
8314+
return ImVec2(0.0f, 0.0f);
8315+
}
8316+
83008317
void ImGui::TabItemBackground(ImDrawList* draw_list, const ImRect& bb, ImGuiTabItemFlags flags, ImU32 col)
83018318
{
83028319
// While rendering tabs, we trim 1 pixel off the top of our bounding box so they can fit within a regular frame height while looking "detached" from it.

0 commit comments

Comments
 (0)