-
-
Notifications
You must be signed in to change notification settings - Fork 10.5k
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
Icons in the tree #282
Comments
There's a few way you can do that but the correct one will have to wait until I make a change to TreeNode - I started it but shelved it. Currently if you do There's will several issues:
So what we need to do is:
You can temporarily hack around your way from those problems by passing a tree node label full of spaces to get a larger hit box, and moving the cursor |
Thanks for the reply. I will go for your temporary hack for now. |
If you use spaces for id remember to do a prior PushId/PopId to make the full-id unique. |
Will do. Thanks! |
Did you mean you wanted to remove the ">" thingie and draw an icon instead? |
And that's the exact same feature but using some internal data structure.
|
Perhaps I can turn part of this, or actually the underlying behavior which does a little more, into a TreeNodeBehavior(). |
Made some change so you can write a custom tree node that is more accurate in term of honoring Auto-Expand-Node-On-Logging and SetNextTreeNode** calls.
Until I add a mechanism to parametrize how far the hit-rectangle of a treenode.should reach, this is probably the best way to just make something fully custom, Not particularly great looking but it's not the type of code you would often look back at. |
Neat :) Thanks! |
This is very old... ImGui API has changed and this code doesn't work any more. Is there any more up to date sample code around? |
@tuket - Here is his function ported to version 1.90 WIP. You should be able to modify it to your needs #include <imgui_internal.h>
bool MyTreeNode(const char* label)
{
ImGuiContext& g = *ImGui::GetCurrentContext();
ImGuiWindow* window = g.CurrentWindow;
ImGuiID id = window->GetID(label);
ImVec2 pos = window->DC.CursorPos;
ImRect bb(pos, ImVec2(pos.x + ImGui::GetContentRegionAvail().x, pos.y + g.FontSize + g.Style.FramePadding.y*2));
bool opened = ImGui::TreeNodeBehaviorIsOpen(id, ImGuiTreeNodeFlags_None);
bool hovered, held;
if (ImGui::ButtonBehavior(bb, id, &hovered, &held, ImGuiButtonFlags_PressedOnClick))
window->DC.StateStorage->SetInt(id, opened ? 0 : 1);
if (hovered || held)
window->DrawList->AddRectFilled(bb.Min, bb.Max, ImGui::GetColorU32(held ? ImGuiCol_HeaderActive : ImGuiCol_HeaderHovered));
// Icon, text
float button_sz = g.FontSize + g.Style.FramePadding.y*2;
window->DrawList->AddRectFilled(pos, ImVec2(pos.x+button_sz, pos.y+button_sz), ImGui::GetColorU32(opened ? IM_COL32(255,0,0,255) : IM_COL32(0,255,0,255)));
ImGui::RenderText(ImVec2(pos.x + button_sz + g.Style.ItemInnerSpacing.x, pos.y + g.Style.FramePadding.y), label);
ImGui::ItemSize(bb, g.Style.FramePadding.y);
ImGui::ItemAdd(bb, id);
if (opened)
ImGui::TreePush(label);
return opened;
} |
Hi,
I wonder if it is currently possible to have custom icons in the tree view? (that would be infront of the text and for the folded/unfolded state)
Think of something like an explorer view/Visual Studio Workspace of files view
The text was updated successfully, but these errors were encountered: