Skip to content

Include thedmd's layout extensions in ImGui Java #390

@slava110

Description

@slava110

Hi. I'm using ImGui to make node editor (using imgui-node-editor extension). I want to position node title at the top center of the node.
Using this piece of code:

var textWidth = ImGui.calcTextSizeX(nodeName);
var nodeWidth = NodeEditor.getNodeSizeX(node.getNodeId()) - 20F;
var textX = Math.max(0F, (nodeWidth - textWidth) * 0.5F);
ImGui.setCursorPosX(ImGui.getCursorPosX() + textX);

Makes the title text appear at the left side of the node at first frame (node width is not known initially, depends on port name widths). At the next frame, it's repositioned to the center of the node. But this repositioning is noticeable for user. Not ideal.
Also, this solution is kinda hacky (without - 20F title is offset to the right a bit. Maybe it's not the exact value, not sure where it's coming from, maybe node borders).
Blueprints example of imgui-node-editor uses Spring extension from https://github.com/thedmd/imgui/tree/feature/layout (as mentioned in the project's README). I think that functions from that fork would not only be useful for ImGui NodeEditor, but also other use-cases where you need to position element horizontally.
Would be cool if you can look at it and, maybe, implement in imgui-java?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions