mirror of
				https://github.com/Drezil/imgui.git
				synced 2025-10-31 13:11:05 +01:00 
			
		
		
		
	ImGuiWindowFlags_UnsavedDocument/ImGuiTabItmeFlags_UnsavedDocument display a dot instead of a '*'.
This commit is contained in:
		| @@ -8077,14 +8077,7 @@ void ImGui::TabItemLabelAndCloseButton(ImDrawList* draw_list, const ImRect& bb, | ||||
| #endif | ||||
|  | ||||
|     // Render text label (with clipping + alpha gradient) + unsaved marker | ||||
|     const char* TAB_UNSAVED_MARKER = "*"; | ||||
|     ImRect text_pixel_clip_bb(bb.Min.x + frame_padding.x, bb.Min.y + frame_padding.y, bb.Max.x - frame_padding.x, bb.Max.y); | ||||
|     if (flags & ImGuiTabItemFlags_UnsavedDocument) | ||||
|     { | ||||
|         text_pixel_clip_bb.Max.x -= CalcTextSize(TAB_UNSAVED_MARKER, NULL, false).x; | ||||
|         ImVec2 unsaved_marker_pos(ImMin(bb.Min.x + frame_padding.x + label_size.x + 2, text_pixel_clip_bb.Max.x), bb.Min.y + frame_padding.y + IM_FLOOR(-g.FontSize * 0.25f)); | ||||
|         RenderTextClippedEx(draw_list, unsaved_marker_pos, bb.Max - frame_padding, TAB_UNSAVED_MARKER, NULL, NULL); | ||||
|     } | ||||
|     ImRect text_ellipsis_clip_bb = text_pixel_clip_bb; | ||||
|  | ||||
|     // Return clipped state ignoring the close button | ||||
| @@ -8094,7 +8087,10 @@ void ImGui::TabItemLabelAndCloseButton(ImDrawList* draw_list, const ImRect& bb, | ||||
|         //draw_list->AddCircle(text_ellipsis_clip_bb.Min, 3.0f, *out_text_clipped ? IM_COL32(255, 0, 0, 255) : IM_COL32(0, 255, 0, 255)); | ||||
|     } | ||||
|  | ||||
|     // Close Button | ||||
|     const float button_sz = g.FontSize; | ||||
|     const ImVec2 button_pos(ImMax(bb.Min.x, bb.Max.x - frame_padding.x * 2.0f - button_sz), bb.Min.y); | ||||
|  | ||||
|     // Close Button & Unsaved Marker | ||||
|     // We are relying on a subtle and confusing distinction between 'hovered' and 'g.HoveredId' which happens because we are using ImGuiButtonFlags_AllowOverlapMode + SetItemAllowOverlap() | ||||
|     //  'hovered' will be true when hovering the Tab but NOT when hovering the close button | ||||
|     //  'g.HoveredId==id' will be true when hovering the Tab including when hovering the close button | ||||
| @@ -8102,15 +8098,16 @@ void ImGui::TabItemLabelAndCloseButton(ImDrawList* draw_list, const ImRect& bb, | ||||
|     bool close_button_pressed = false; | ||||
|     bool close_button_visible = false; | ||||
|     if (close_button_id != 0) | ||||
|         if (is_contents_visible || bb.GetWidth() >= g.Style.TabMinWidthForCloseButton) | ||||
|         if (is_contents_visible || bb.GetWidth() >= ImMax(button_sz, g.Style.TabMinWidthForCloseButton)) | ||||
|             if (g.HoveredId == tab_id || g.HoveredId == close_button_id || g.ActiveId == tab_id || g.ActiveId == close_button_id) | ||||
|                 close_button_visible = true; | ||||
|     bool unsaved_marker_visible = (flags & ImGuiTabItemFlags_UnsavedDocument) != 0 && (button_pos.x + button_sz <= bb.Max.x); | ||||
|  | ||||
|     if (close_button_visible) | ||||
|     { | ||||
|         ImGuiLastItemDataBackup last_item_backup; | ||||
|         const float close_button_sz = g.FontSize; | ||||
|         PushStyleVar(ImGuiStyleVar_FramePadding, frame_padding); | ||||
|         if (CloseButton(close_button_id, ImVec2(bb.Max.x - frame_padding.x * 2.0f - close_button_sz, bb.Min.y))) | ||||
|         if (CloseButton(close_button_id, button_pos)) | ||||
|             close_button_pressed = true; | ||||
|         PopStyleVar(); | ||||
|         last_item_backup.Restore(); | ||||
| @@ -8118,12 +8115,23 @@ void ImGui::TabItemLabelAndCloseButton(ImDrawList* draw_list, const ImRect& bb, | ||||
|         // Close with middle mouse button | ||||
|         if (!(flags & ImGuiTabItemFlags_NoCloseWithMiddleMouseButton) && IsMouseClicked(2)) | ||||
|             close_button_pressed = true; | ||||
|  | ||||
|         text_pixel_clip_bb.Max.x -= close_button_sz; | ||||
|     } | ||||
|     else if (unsaved_marker_visible) | ||||
|     { | ||||
|         const ImRect bullet_bb(button_pos, button_pos + ImVec2(button_sz, button_sz) + g.Style.FramePadding * 2.0f); | ||||
|         RenderBullet(bullet_bb.GetCenter()); | ||||
|     } | ||||
|  | ||||
|     // This is all rather complicated | ||||
|     // (the main idea is that because the close button only appears on hover, we don't want it to alter the ellipsis position) | ||||
|     // FIXME: if FramePadding is noticeably large, ellipsis_max_x will be wrong here (e.g. #3497), maybe for consistency that parameter of RenderTextEllipsis() shouldn't exist.. | ||||
|     float ellipsis_max_x = close_button_visible ? text_pixel_clip_bb.Max.x : bb.Max.x - 1.0f; | ||||
|     if (close_button_visible || unsaved_marker_visible) | ||||
|     { | ||||
|         text_pixel_clip_bb.Max.x -= close_button_visible ? (button_sz) : (button_sz * 0.80f); | ||||
|         text_ellipsis_clip_bb.Max.x -= unsaved_marker_visible ? (button_sz * 0.80f) : 0.0f; | ||||
|         ellipsis_max_x = text_pixel_clip_bb.Max.x; | ||||
|     } | ||||
|     RenderTextEllipsis(draw_list, text_ellipsis_clip_bb.Min, text_ellipsis_clip_bb.Max, text_pixel_clip_bb.Max.x, ellipsis_max_x, label, NULL, &label_size); | ||||
|  | ||||
| #if 0 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user