Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
zaafar opened this issue Dec 3, 2023 · 12 comments
Labels
tabs tab bars, tabs

Comments

@zaafar
Copy link

zaafar commented Dec 3, 2023


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 zaafar changed the title [feature request] a ImGuiWindowFlags that is like ImGuiWindowFlags_UnsavedDocument but not exactly the same [feature request] a ImGuiTabItemFlags that is like ImGuiTabItemFlags_UnsavedDocument but not exactly the same Dec 3, 2023
@zaafar
Copy link
Author

zaafar commented Dec 3, 2023

EDITS: update from ImGuiWindowFlags to ImGuiTabItemFlags

@ocornut ocornut added the tabs tab bars, tabs label Dec 3, 2023
@ocornut
Copy link
Owner

ocornut commented Dec 3, 2023

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

@zaafar
Copy link
Author

zaafar commented Dec 3, 2023

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 ocornut changed the title [feature request] a ImGuiTabItemFlags that is like ImGuiTabItemFlags_UnsavedDocument but not exactly the same A ImGuiTabItemFlags that is like ImGuiTabItemFlags_UnsavedDocument but not exactly the same Dec 5, 2023
@ocornut
Copy link
Owner

ocornut commented Dec 5, 2023

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

@zaafar
Copy link
Author

zaafar commented Dec 5, 2023

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
Copy link
Author

zaafar commented Dec 5, 2023

hence the TLDR of the first post :)

@ocornut
Copy link
Owner

ocornut commented Dec 7, 2023

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 added a commit that referenced this issue Dec 7, 2023
@ocornut
Copy link
Owner

ocornut commented Dec 7, 2023

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!

@ocornut ocornut closed this as completed Dec 7, 2023
@zaafar
Copy link
Author

zaafar commented Dec 7, 2023

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
Copy link
Author

zaafar commented Dec 7, 2023

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
Copy link
Author

zaafar commented Jan 10, 2024

@ocornut nothing urgent, i think, you did a mistake in updating changelog c58d2c8

you modified 1.61 change log rather than latest one.

@ocornut
Copy link
Owner

ocornut commented Jan 11, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tabs tab bars, tabs
Projects
None yet
Development

No branches or pull requests

2 participants