ocornut / imgui

Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies
MIT License
59.76k stars 10.17k forks source link

A ImGuiTabItemFlags that is like ImGuiTabItemFlags_UnsavedDocument but not exactly the same #7084

Closed zaafar closed 9 months ago

zaafar commented 9 months ago

Version/Branch of Dear ImGui:

Version: v1.90 Branch: docking

My Issue/Question:

Currently ImGuiTabItemFlags_UnsavedDocument is doing 2 things

1: assuming document isn't saved and displaying dot next to the title.

2: tab is selected when clicking the X and closure is not assumed

while this is a perfectly fine usecase for unsaved documents.

my use-case is a bit different, I basically want to ask the user if they really want to close the tab or not

for this use-case (1) isn't necessary i.e. no need to always display a dot on the tab

Following are the screenshot of my usecase

here is me allowing users to add/remove a tab by pressing X (or + sign). You can see all tabs have dot, which isn't required add_remove_tab_usecase

here is me asking the user (via popup) do you really wanna close the tab after user press X. (to mitigate accidents) do_you_want_to_delete

so TLDR: Would be nice if we keep ImGuiTabItemFlags_UnsavedDocument as is however introduces a new flag (e.g. ImGuiTabItemFlags_DoNotAssumeClosure) so folks who want to use just (2) can do that.

Thank you for the amazing lib, Cheers!

zaafar commented 9 months ago

EDITS: update from ImGuiWindowFlags to ImGuiTabItemFlags

ocornut commented 9 months ago

You can already detect closure on TabItem() return and decide to not close the tab and show a modal.

zaafar commented 9 months ago

I am sorry, I should have said that I am using imgui public API (i.e. BeginTabItem and EndTabItem for creating tabs). I am assuming that the TabItem API you have mentioned is internal. That is fine, I will figure out how to incorporate that. :)

ocornut commented 9 months ago

TabItem() is called by BeginTabItem(). After you call BeginTabItem() you can check if the bool you passed has changed back to false.

zaafar commented 9 months ago

sorry in advance for the c# code.

yes, you are right I can do that (as shown in the code below)

ImGui.BeginTabItem("fakeNameThatITotallyDontUse", ref shouldNotDeleteIfTrue, ImGuiTabItemFlags.None);
// adds logic to remove tab when shouldNotDeleteIfTrue is False

However,

(1) Once I check shouldNotDeleteIfTrue == False ????? -> Open Model for "Do you want to delete it?" for user -> User select NO -> that tab will go/move to the end. (Actually user doesn't have to select NO for the tab to move to the end, however, when user select Yes, it doesn't matter but that's just a small implementation detail)

this happens because by default in the TAB API "closure is assumed" (as mentioned in the imgui docs as well)

if I use the following code, tab doesn't move to the end of the tab bar because closure isn't assumed.

ImGui.BeginTabItem("fakeNameThatITotallyDontUse", ref shouldNotDeleteIfTrue, ImGuiTabItemFlags.UnsavedDocument);

==Screenshots For Proof of (1)==

starting tab position

image

pressing X on tab2

image

tab2 is now on the far right.

image

zaafar commented 9 months ago

hence the TLDR of the first post :)

ocornut commented 9 months ago

My bad, I thought there was a call to mark the tab as reopened but it's not possible presently. I think you are right and maybe the best solution is to introduce a flag.

ocornut commented 9 months ago

I have added the ImGuiTabItemFlags_NoAssumedClosure flag in c58d2c8 This should cherry-pick easily if you need to use this immediately in docking branch. Thanks!

zaafar commented 9 months ago

Thank you, i will test it once there is a release. I don’t think so cherrypick is required, that info in the first post might be wrong.

zaafar commented 9 months ago

ignore my last comment, cherry-pick to docking is required.

EDIT: ignore my last comment, I want this in docking but not immediately (when new release is out). :)

zaafar commented 8 months ago

@ocornut nothing urgent, i think, you did a mistake in updating changelog https://github.com/ocornut/imgui/commit/c58d2c89c3f91bbd42b66d67f42f6f11363867d3

you modified 1.61 change log rather than latest one.

ocornut commented 8 months ago

Thank you. I fixed it and amended the release Changelog with that missing bit indeed! https://github.com/ocornut/imgui/releases/tag/v1.90.1