1、组件的ID
只要是需要和使用者交互的组件,每一个组件都需要有一个ID,但是想Text这种组件可以不需要ID,但是想Button这种组件就需要一个ID。
Button("OK"); // Label = "OK", ID = hash of (..., "OK")
Button("Cancel"); // Label = "Cancel", ID = hash of (..., "Cancel")
ID就是创建的时候里面的参数。“OK”/“Cancel”。
2、创建的ID冲突了,应该怎么解决
①创建两个窗口:
Begin("MyWindow");
Button("OK"); // Label = "OK", ID = hash of ("MyWindow", "OK")
End();
Begin("MyOtherWindow");
Button("OK"); // Label = "OK", ID = hash of ("MyOtherWindow", "OK")
End();
②在ID里面使用补码的方式传给imgui,但是不给操作者显示
注意:这里是两个'#'号,使用两个#的时候,“#”前面的字符串就是当前组件的标签,也就是显示的字符,然后ID就是整个字符串,整个时候标签是可以一样的。
Begin("MyWindow");
Button("Play"); // Label = "Play", ID = hash of ("MyWindow", "Play")
Button("Play##foo1"); // Label = "Play", ID = hash of ("MyWindow", "Play##foo1")
// Different from above
Button("Pla

本文探讨了Dear Imgui中组件ID的重要性,特别是在Button等交互元素中的应用。当遇到ID冲突时,可以通过补码方式传递ID或者利用PushID/PopID管理ID栈来解决。此外,TreeNode在创建节点时会自动PushID,使用后记得Pop以避免问题。

884

被折叠的 条评论
为什么被折叠?



