-
-
Notifications
You must be signed in to change notification settings - Fork 11.2k
Description
Hi Omar,
I have an issue with ImageButtons. I have following method in my app:
void Foo(int index, vec4 uv) {
static int hov_index = -1;
ImGui::PushID(index);
if (ImGui::ImageButton((void*)(intptr_t)(hov_index == index ? icon_texture_flat_ : icon_texture_), ImVec2(24, 24), ImVec2(uv.x, uv.w), ImVec2(uv.z, uv.y), 0 )) {
Foonction();
}
ImGui::PopID();
if (ImGui::IsItemHovered()) {
hov_index = (ImGui::IsMouseDown(0) ? index : -1);
}
}
I wanted to achieve than if user press and hold the button, image is changed (flat and normal icon), which worked perfectly. The problem was that from that point ImageButton never returned true. After debugging a bit, I presumed that since ImGuiID is generated from texture id (and I have two different textures), it actually never recognizes that the item is pressed.
My solution was to overload the ImGui::ImageButton as ImageButton(ImTextureID user_texture_id, ImTextureID user_texture_id_down ....
copy/paste complete ImageButton definition, then change last line in definition to: window->DrawList->AddImage(!held ? user_texture_id : user_texture_id_down, image_bb.Min, image_bb.Max, uv0, uv1, GetColorU32(tint_col));
From that point it worked as expected.
I have two questions:
- Why there is
PushID((void*)(intptr_t)user_texture_id);
if for example I PushID myself? Shouldn't ImGui check if there is a pushed ID already by the user, and in case there is none, use your existent solution of adding texture_id as ID? - Is there any chance/plan to add overloaded ImageButton with 3 states normal, pushed, hovered?
UI: saw there is something similar at #1390
Thanks