-
-
Notifications
You must be signed in to change notification settings - Fork 135
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
g.TreeNode() does not allow a QTreeView-alike widget (Table + TreeNode) #134
Comments
Ugly workaround:I have been able to illegally hack around this with max uglyness code:
I abuse the the fact that: 1] It helps me "forcing" 2] if Thus the first |
Fix Proposal:Maybe the workaround above would helps you to figure a way to fix this behavior. Maybe explicitly propose two
|
@folays Thanks very much to point out this edge case. I will check it later because I'm out of office right now. I also noticed that newest Table API's demo provides a table+treenode example, I'll read your proposal and provide a solution later. |
@folays TreeTableWidget is ready to use. |
Example and lectures:
BeginTable
+TreeNode
imgui
(C++) of the screenshot above (Table
+TreeNode
) is here : https://github.com/ocornut/imgui/blob/v1.80/imgui_demo.cpp#L4427giu
of aTreeNode" (without
Table`) is here : https://github.com/AllenDang/giu/blob/v0.5.2/examples/widgets/widgets.go#L132giu
of*TreeNodeWidget.Build()
is here : https://github.com/AllenDang/giu/blob/v0.5.2/Widgets.go#L1861Problem:
giu
does not currently permit to record the same widget given in the screenshoot in (1).How you are supposed to draw
Table+TreeNode
:Please suppose your want to build a
Table
(with 2+ columns) and you want to use aTreeNode
in the 1st column.The C++
imgui
TreeNode() function (orimgui-go
'simgui.TreeNodeV()
returns anopen
flag.When
C++/imgui-go
.TreeNode*()
functions returns theopen
"status", you will be able to act upon it, but you are supposed to act on it ONLY LATER.You're supposed to immediately continue to "draw" the remaining columns FIRST in the current row.
Then, once you're at the end of the current row, you would either:
open == false
: nothing special, you should callC++/imgui-go
'sTableNextRow()
and then draw yours columnopen == true
: you could draw one or more sub-line(s), which you would probably want INDENTED, and once you (possibly recursively) draw those line(s), you would (if indented) have to callC++/imgui-go
'simgui.TreePop()
BUT :
giu
is sort-of in the way of acting upon theopen
status.Why:
giu
proposes a Layout() function which is called immediately whengiu
's(*TreeNodeWidget).Build()
is called.giu
's(*TreeNodeWidget)
'sLayout
seems to be think through for an immediate usage of "drawing the content of theTreeNode
.Except that when used in a
Table
, aTreeNodeWidget
should be perceived as having no context beside the textual item it represents, especially given that you are supposed to draw the renaming columns FIRST.This lead to complicated setup where the code below would work incorrectly:
The intention of the code above should be clear, to issue a table looking like that:
But it won't do that if you "open" the
Node1
.Due to the implementations of
giu
's(*TreeNodeWidget).Build()
, if theNode1
is opened, giu's(*TreeNodeWidget).Build()
will immediately draw ("callBuild()
s) on the[]Widget
s contained instruct *TreeNodeWidget
's memberlayout Layout
.Thus, the
Node1
's andNode2
's columns will be "interleaved" (or more correctly, NOT where they are expected to be).In this situation, you could have alleviated the problem by putting nothing in
giu
's(*TreeNodeWidget).Layout()
function, and draw (in all cases, whetheropen
being true or false) the remaining columns ofNode1
row (you would do that in the next remainingg.Row()
parameters just after/outside theg.TreeNode()
call.Then, BEFORE drawing a possible
Node3
(level 0) row, you sort-of COULD drawNode2
(level 1) row.But you cannot really do it, you would encounter two more problems (1st one alleviatable, 2nd one not at all):
1]
open
flag is lost, since it is not exposed outside ofgiu
'sg.TreeNode()
call, nor(*TreeNodeWidget).Build()
. You COULD alleviate this problem by:1a] in the
g.Row()
immediately beforeg.TreeNode("Node1-Col1")
, you could register ag.Custom(func() { myOpen = false } )
which would allow you to always "reset" yourvar myOpen bool
variable.2a] then in the
(*TreeNodeWidget).Layout()
widgets, you could have inserted ag.Custom(func() { myOpen = true })
, which would allow you to "leak" theopen
flag outside of(*TreeNodeWidget).Build()
2] Even if you successfully leaked the
open
flag outside above,(*TreeNodeWidget).Build()
would have already returned, and thus already called (on your behalf)imgui.TreePop()
, and thus all your hope of indentation of the sub-TreeNode
s are lost.In all cases, even if there is a trick, I supposed it would be convoluted.
Others thoughts:
Your
giu
repo is awesome :) Please don't be upset for my remarks above.I think the problem is more due to
imgui
'sTreeNode
having at the same time:Table
should NOT be not used immediately, but acted upon it only later (when the currentrow
is completed, OUTSIDE of theTreeNode
"content", when theTableNextRow()
will be considered)This behavior of
imgui
seems to change a little from the routine behaviours of otherimgui
widgets.Even
TableNextRow()
have some internal state, but all of thoses are supposed to only be used INSIDE the row being draw.In
ìmgui
andimgui-go
, users are expected toPush
on the context of what they want to draw manually, and themselvesPop
when they completed their "content draw" (e.g.:ImGui::EndTable()
)giu
API seems to be build around an idea of.Layout()
for content, and "automatic"Pop
's being done on behalf of the user, all around a general idea ofgiu
being 10x easier to use.This
giu
paragdim seems to works well with 99% ofimgui
widgets behavior.This reflect in
giu
which currently does not support havinggiu
'sTreeNode
doing a "Push" (via(*TreeNodeWidget).Build()
callingimgui.TreeNodeV()
) without automatic "Pop" ((*TreeNodeWidget).Build()
callingimgui.TreePop()
automatically).That, and the
(*TreeNodeWidget).Layout()
model which does not really fit the usage ofTreeNode
s inside aTable
.(because the "sub-row" content must be in an "indented" (yet sibling) "next-row", and not "inside" the
TreeNode
).The text was updated successfully, but these errors were encountered: