c++ - 如何使用路径字符串正确填充/导航此树结构?
问题描述
更新:
事实证明我不必要地使事情复杂化。出于上下文菜单的目的,您实际上只需要一个任意树(带有
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 的人有用的链接:
解决方案
推荐阅读
- kubernetes - 伊斯蒂奥。如何将虚拟主机添加到 Envoy?
- python - discord.py 忽略机器人(client.command)
- node.js - 如何在 NestJS GraphQL 解析器中访问 Response 对象
- c# - 用于 Java .aar 文件的 Xamarin Android 元数据
- google-apps-script - Google Script - 将工作表转换为 XLSX 并通过 HTTP 下载
- python - Pandas 使用 Lookup 使用来自另一个 DataFrame 的多个列添加新列
- apache-nifi - Aache NIFI 适用于这个用例吗?
- python - 根据条件将列中的值附加到另一列
- discord.js - 要使用的 Discord.js 数据库
- reactjs - 组件组成问题反应