原来,我不必要地使事情复杂化。出于上下文菜单的目的,您实际上只需要一棵任意树(带有
Parent
,FirstChild
和NextSibling
)。可视化上下文菜单树的最佳方法与其他任何树一样,只是水平分支而不是垂直分支。实际上,根本不需要能够沿着4个不同的方向(Up
,Down
,Left
和Right
)走树,因为您需要的所有信息都是已经存在Parent
,FirstChild
和NextSibling
(所有这些都很容易确定您是否已经具有路径字符串列表)。
该线程可以安全地关闭。
我没有使用XPath或任何与Web或DOM相关的库,但我想利用XPath样式的方法来填充上下文菜单小部件的内容:
struct ContextMenuNode
{
ContextMenuNode* Left; // Parent Menu
ContextMenuNode* Right; // Sub Menu
ContextMenuNode* Up; // Previous Sibling
ContextMenuNode* Down; // Next Sibling
FString Path; // An XPath-like string
FString Caption; // Display text of this menu item
}
我想做的是这样的:
// Defined in a class declaration:
TArray<ContextMenuNode*> MenuNodes;
// ...
/* This should create 2 unique nodes ("/File" doesn't exist yet within MenuNodes),
establish Left & Right relationships between them, and
return the newly created "/File/Open" node,
adding both nodes into MenuNodes
*/
auto openFileNode = AddNode("/File/Open");
/* Much like the previous line, this should
create 1 unique node (since "/File" should already exist from the previous call),
Left should be "/File", Up should be "/File/Open".
But also, we need to update THOSE nodes in relation to this node now...
Both "/File/Open" and "/File/Save" are Up/Down siblings with the same Left ("/File")
*/
auto saveFileNode = AddNode("/File/Save");
这是如何实现的,或者只是有更好的方法来解决这个问题?
对不熟悉UE4的人有用的链接: