mirror of
				https://github.com/Drezil/imgui.git
				synced 2025-10-31 21:21:06 +01:00 
			
		
		
		
	Merge branch 'master' into docking
# Conflicts: # backends/imgui_impl_dx9.cpp # backends/imgui_impl_win32.cpp # docs/CHANGELOG.txt # imgui.cpp
This commit is contained in:
		| @@ -782,22 +782,30 @@ bool ImGui::ArrowButton(const char* str_id, ImGuiDir dir) | ||||
| } | ||||
|  | ||||
| // Button to close a window | ||||
| bool ImGui::CloseButton(ImGuiID id, const ImVec2& pos)//, float size) | ||||
| bool ImGui::CloseButton(ImGuiID id, const ImVec2& pos) | ||||
| { | ||||
|     ImGuiContext& g = *GImGui; | ||||
|     ImGuiWindow* window = g.CurrentWindow; | ||||
|  | ||||
|     // We intentionally allow interaction when clipped so that a mechanical Alt,Right,Validate sequence close a window. | ||||
|     // (this isn't the regular behavior of buttons, but it doesn't affect the user much because navigation tends to keep items visible). | ||||
|     // Tweak 1: Shrink hit-testing area if button covers an abnormally large proportion of the visible region. That's in order to facilitate moving the window away. (#3825) | ||||
|     // This may better be applied as a general hit-rect reduction mechanism for all widgets to ensure the area to move window is always accessible? | ||||
|     const ImRect bb(pos, pos + ImVec2(g.FontSize, g.FontSize) + g.Style.FramePadding * 2.0f); | ||||
|     bool is_clipped = !ItemAdd(bb, id); | ||||
|     ImRect bb_interact = bb; | ||||
|     const float area_to_visible_ratio = window->OuterRectClipped.GetArea() / bb.GetArea(); | ||||
|     if (area_to_visible_ratio < 1.5f) | ||||
|         bb_interact.Expand(ImFloor(bb_interact.GetSize() * -0.25f)); | ||||
|  | ||||
|     // Tweak 2: We intentionally allow interaction when clipped so that a mechanical Alt,Right,Activate sequence can always close a window. | ||||
|     // (this isn't the regular behavior of buttons, but it doesn't affect the user much because navigation tends to keep items visible). | ||||
|     bool is_clipped = !ItemAdd(bb_interact, id); | ||||
|  | ||||
|     bool hovered, held; | ||||
|     bool pressed = ButtonBehavior(bb, id, &hovered, &held); | ||||
|     bool pressed = ButtonBehavior(bb_interact, id, &hovered, &held); | ||||
|     if (is_clipped) | ||||
|         return pressed; | ||||
|  | ||||
|     // Render | ||||
|     // FIXME: Clarify this mess | ||||
|     ImU32 col = GetColorU32(held ? ImGuiCol_ButtonActive : ImGuiCol_ButtonHovered); | ||||
|     ImVec2 center = bb.GetCenter(); | ||||
|     if (hovered) | ||||
| @@ -3293,7 +3301,7 @@ bool ImGui::TempInputScalar(const ImRect& bb, ImGuiID id, const char* label, ImG | ||||
|         DataTypeApplyOpFromText(data_buf, g.InputTextState.InitialTextA.Data, data_type, p_data, NULL); | ||||
|         if (p_clamp_min || p_clamp_max) | ||||
|         { | ||||
|             if (DataTypeCompare(data_type, p_clamp_min, p_clamp_max) > 0) | ||||
|             if (p_clamp_min && p_clamp_max && DataTypeCompare(data_type, p_clamp_min, p_clamp_max) > 0) | ||||
|                 ImSwap(p_clamp_min, p_clamp_max); | ||||
|             DataTypeClamp(data_type, p_data, p_clamp_min, p_clamp_max); | ||||
|         } | ||||
| @@ -6910,7 +6918,7 @@ namespace ImGui | ||||
|     static ImU32            TabBarCalcTabID(ImGuiTabBar* tab_bar, const char* label, ImGuiWindow* docked_window); | ||||
|     static float            TabBarCalcMaxTabWidth(); | ||||
|     static float            TabBarScrollClamp(ImGuiTabBar* tab_bar, float scrolling); | ||||
|     static void             TabBarScrollToTab(ImGuiTabBar* tab_bar, ImGuiTabItem* tab, ImGuiTabBarSection* sections); | ||||
|     static void             TabBarScrollToTab(ImGuiTabBar* tab_bar, ImGuiID tab_id, ImGuiTabBarSection* sections); | ||||
|     static ImGuiTabItem*    TabBarScrollingButtons(ImGuiTabBar* tab_bar); | ||||
|     static ImGuiTabItem*    TabBarTabListPopupButton(ImGuiTabBar* tab_bar); | ||||
| } | ||||
| @@ -7128,12 +7136,12 @@ static void ImGui::TabBarLayout(ImGuiTabBar* tab_bar) | ||||
|     sections[1].Spacing = sections[1].TabCount > 0 && sections[2].TabCount > 0 ? g.Style.ItemInnerSpacing.x : 0.0f; | ||||
|  | ||||
|     // Setup next selected tab | ||||
|     ImGuiID scroll_track_selected_tab_id = 0; | ||||
|     ImGuiID scroll_to_tab_id = 0; | ||||
|     if (tab_bar->NextSelectedTabId) | ||||
|     { | ||||
|         tab_bar->SelectedTabId = tab_bar->NextSelectedTabId; | ||||
|         tab_bar->NextSelectedTabId = 0; | ||||
|         scroll_track_selected_tab_id = tab_bar->SelectedTabId; | ||||
|         scroll_to_tab_id = tab_bar->SelectedTabId; | ||||
|     } | ||||
|  | ||||
|     // Process order change request (we could probably process it when requested but it's just saner to do it in a single spot). | ||||
| @@ -7141,7 +7149,7 @@ static void ImGui::TabBarLayout(ImGuiTabBar* tab_bar) | ||||
|     { | ||||
|         if (TabBarProcessReorder(tab_bar)) | ||||
|             if (tab_bar->ReorderRequestTabId == tab_bar->SelectedTabId) | ||||
|                 scroll_track_selected_tab_id = tab_bar->ReorderRequestTabId; | ||||
|                 scroll_to_tab_id = tab_bar->ReorderRequestTabId; | ||||
|         tab_bar->ReorderRequestTabId = 0; | ||||
|     } | ||||
|  | ||||
| @@ -7149,7 +7157,7 @@ static void ImGui::TabBarLayout(ImGuiTabBar* tab_bar) | ||||
|     const bool tab_list_popup_button = (tab_bar->Flags & ImGuiTabBarFlags_TabListPopupButton) != 0; | ||||
|     if (tab_list_popup_button) | ||||
|         if (ImGuiTabItem* tab_to_select = TabBarTabListPopupButton(tab_bar)) // NB: Will alter BarRect.Min.x! | ||||
|             scroll_track_selected_tab_id = tab_bar->SelectedTabId = tab_to_select->ID; | ||||
|             scroll_to_tab_id = tab_bar->SelectedTabId = tab_to_select->ID; | ||||
|  | ||||
|     // Leading/Trailing tabs will be shrink only if central one aren't visible anymore, so layout the shrink data as: leading, trailing, central | ||||
|     // (whereas our tabs are stored as: leading, central, trailing) | ||||
| @@ -7169,8 +7177,8 @@ static void ImGui::TabBarLayout(ImGuiTabBar* tab_bar) | ||||
|             most_recently_selected_tab = tab; | ||||
|         if (tab->ID == tab_bar->SelectedTabId) | ||||
|             found_selected_tab_id = true; | ||||
|         if (scroll_track_selected_tab_id == 0 && g.NavJustMovedToId == tab->ID) | ||||
|             scroll_track_selected_tab_id = tab->ID; | ||||
|         if (scroll_to_tab_id == 0 && g.NavJustMovedToId == tab->ID) | ||||
|             scroll_to_tab_id = tab->ID; | ||||
|  | ||||
|         // Refresh tab width immediately, otherwise changes of style e.g. style.FramePadding.x would noticeably lag in the tab bar. | ||||
|         // Additionally, when using TabBarAddTab() to manipulate tab bar order we occasionally insert new tabs that don't have a width yet, | ||||
| @@ -7201,11 +7209,11 @@ static void ImGui::TabBarLayout(ImGuiTabBar* tab_bar) | ||||
|     // Horizontal scrolling buttons | ||||
|     // (note that TabBarScrollButtons() will alter BarRect.Max.x) | ||||
|     if ((tab_bar->WidthAllTabsIdeal > tab_bar->BarRect.GetWidth() && tab_bar->Tabs.Size > 1) && !(tab_bar->Flags & ImGuiTabBarFlags_NoTabListScrollingButtons) && (tab_bar->Flags & ImGuiTabBarFlags_FittingPolicyScroll)) | ||||
|         if (ImGuiTabItem* scroll_track_selected_tab = TabBarScrollingButtons(tab_bar)) | ||||
|         if (ImGuiTabItem* scroll_and_select_tab = TabBarScrollingButtons(tab_bar)) | ||||
|         { | ||||
|             scroll_track_selected_tab_id = scroll_track_selected_tab->ID; | ||||
|             if (!(scroll_track_selected_tab->Flags & ImGuiTabItemFlags_Button)) | ||||
|                 tab_bar->SelectedTabId = scroll_track_selected_tab_id; | ||||
|             scroll_to_tab_id = scroll_and_select_tab->ID; | ||||
|             if ((scroll_and_select_tab->Flags & ImGuiTabItemFlags_Button) == 0) | ||||
|                 tab_bar->SelectedTabId = scroll_to_tab_id; | ||||
|         } | ||||
|  | ||||
|     // Shrink widths if full tabs don't fit in their allocated space | ||||
| @@ -7269,7 +7277,7 @@ static void ImGui::TabBarLayout(ImGuiTabBar* tab_bar) | ||||
|     if (found_selected_tab_id == false) | ||||
|         tab_bar->SelectedTabId = 0; | ||||
|     if (tab_bar->SelectedTabId == 0 && tab_bar->NextSelectedTabId == 0 && most_recently_selected_tab != NULL) | ||||
|         scroll_track_selected_tab_id = tab_bar->SelectedTabId = most_recently_selected_tab->ID; | ||||
|         scroll_to_tab_id = tab_bar->SelectedTabId = most_recently_selected_tab->ID; | ||||
|  | ||||
|     // Lock in visible tab | ||||
|     tab_bar->VisibleTabId = tab_bar->SelectedTabId; | ||||
| @@ -7277,12 +7285,11 @@ static void ImGui::TabBarLayout(ImGuiTabBar* tab_bar) | ||||
|  | ||||
|     // CTRL+TAB can override visible tab temporarily | ||||
|     if (g.NavWindowingTarget != NULL && g.NavWindowingTarget->DockNode && g.NavWindowingTarget->DockNode->TabBar == tab_bar) | ||||
|         tab_bar->VisibleTabId = scroll_track_selected_tab_id = g.NavWindowingTarget->ID; | ||||
|         tab_bar->VisibleTabId = scroll_to_tab_id = g.NavWindowingTarget->ID; | ||||
|  | ||||
|     // Update scrolling | ||||
|     if (scroll_track_selected_tab_id) | ||||
|         if (ImGuiTabItem* scroll_track_selected_tab = TabBarFindTabByID(tab_bar, scroll_track_selected_tab_id)) | ||||
|             TabBarScrollToTab(tab_bar, scroll_track_selected_tab, sections); | ||||
|     if (scroll_to_tab_id != 0) | ||||
|         TabBarScrollToTab(tab_bar, scroll_to_tab_id, sections); | ||||
|     tab_bar->ScrollingAnim = TabBarScrollClamp(tab_bar, tab_bar->ScrollingAnim); | ||||
|     tab_bar->ScrollingTarget = TabBarScrollClamp(tab_bar, tab_bar->ScrollingTarget); | ||||
|     if (tab_bar->ScrollingAnim != tab_bar->ScrollingTarget) | ||||
| @@ -7412,8 +7419,12 @@ static float ImGui::TabBarScrollClamp(ImGuiTabBar* tab_bar, float scrolling) | ||||
|     return ImMax(scrolling, 0.0f); | ||||
| } | ||||
|  | ||||
| static void ImGui::TabBarScrollToTab(ImGuiTabBar* tab_bar, ImGuiTabItem* tab, ImGuiTabBarSection* sections) | ||||
| // Note: we may scroll to tab that are not selected! e.g. using keyboard arrow keys | ||||
| static void ImGui::TabBarScrollToTab(ImGuiTabBar* tab_bar, ImGuiID tab_id, ImGuiTabBarSection* sections) | ||||
| { | ||||
|     ImGuiTabItem* tab = TabBarFindTabByID(tab_bar, tab_id); | ||||
|     if (tab == NULL) | ||||
|         return; | ||||
|     if (tab->Flags & (ImGuiTabItemFlags_Leading | ImGuiTabItemFlags_Trailing)) | ||||
|         return; | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user