1 Star 0 Fork 0

高云鹏/SUI

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
simple_ui_middleware_treenode.c 4.66 KB
一键复制 编辑 原始数据 按行查看 历史
EHusky 提交于 2023-06-19 19:12 . v0.1.0.alpha.dev2
/**
******************************************************************************
* @file simple_ui_middleware_treenode.c
* @author Enoky Bertram
* @version v0.1.0.alpha.dev2
* @date Jun.19.2023
* @brief 数据结构中间层
* @note happyhappyhappy
******************************************************************************
*/
#include "simple_ui_middleware_treenode.h"
/**
* @name create_ui_node
* @brief 创建一个节点
* @param node_type 节点类型
* @param name 节点名称
* @param data 节点数据地址
* @return simple_ui_node_s_t
* @note 内部调用
*/
simple_ui_node_s_t *create_ui_node(simple_ui_node_type_e_t node_type, const char *name, void *data)
{
simple_ui_node_s_t *new_node = (simple_ui_node_s_t *)malloc(sizeof(simple_ui_node_s_t));
new_node->info.node_type = node_type;
strcpy(new_node->info.name, name);
new_node->info.data = data;
new_node->parent = NULL;
new_node->first_child = NULL;
new_node->next_sibling = NULL;
return new_node;
}
/**
* @name add_sub_ui_node
* @brief 创建一个节点
* @param parent 父节点地址
* @param child 子节点地址
* @return void
* @note 内部调用
*/
void add_sub_ui_node(simple_ui_node_s_t *parent, simple_ui_node_s_t *child)
{
child->parent = parent;
if (NULL == parent->first_child)
{
parent->first_child = child;
}
else
{
simple_ui_node_s_t *sibling = parent->first_child;
while (NULL != sibling->next_sibling)
{
sibling = sibling->next_sibling;
}
sibling->next_sibling = child;
}
}
/**
* @name find_child_ui_node_by_name
* @brief 通过名称寻找子节点
* @param parent 父节点地址
* @param child_name 子节点名称
* @return simple_ui_node_s_t
* @note 内部调用
*/
simple_ui_node_s_t *find_child_ui_node_by_name(simple_ui_node_s_t *parent, const char *child_name)
{
// 如果父节点为空,直接返回父节点
if (NULL == parent || NULL == parent->first_child)
{
return NULL;
}
simple_ui_node_s_t *found_node = parent->first_child;
if (0 == strcmp(found_node->info.name, child_name))
return found_node;
else
{
found_node = found_node->next_sibling;
while (NULL != found_node)
{
if (0 == strcmp(found_node->info.name, child_name))
return found_node;
found_node = found_node->next_sibling;
}
}
return found_node;
}
/**
* @name find_child_ui_node_by_index
* @brief 通过索引寻找子节点
* @param parent 父节点地址
* @param child_index 子节点名称
* @return simple_ui_node_s_t
* @note 内部调用
*/
simple_ui_node_s_t *find_child_ui_node_by_index(simple_ui_node_s_t *parent, uint8_t child_index)
{
uint8_t index = child_index;
// 如果父节点为空,直接返回父节点
if (NULL == parent || NULL == parent->first_child)
{
return NULL;
}
simple_ui_node_s_t *found_node = parent->first_child;
while (index--)
{
found_node = found_node->next_sibling;
}
return found_node;
}
/**
* @name get_node_index_of_root
* @brief 获得子节点在根节点下的索引
* @param child 子节点地址
* @return uint8_t
* @note 内部调用
*/
uint8_t get_node_index_of_root(simple_ui_node_s_t *child)
{
if (NULL == child)
return -1;
simple_ui_node_s_t *root = child;
uint8_t index = 0;
while (NULL != root->parent)
{
root = root->parent;
index++;
}
return index;
}
/**
* @name get_node_index_of_parent
* @brief 获得子节点在父节点下的索引
* @param child 子节点地址
* @return uint8_t
* @note 内部调用
*/
uint8_t get_node_index_of_parent(simple_ui_node_s_t *child)
{
if (NULL == child || NULL == child->parent || NULL == child->parent->first_child)
return -1;
simple_ui_node_s_t *first_sibling = child->parent->first_child;
uint8_t index = 0;
while (child != first_sibling)
{
first_sibling = first_sibling->next_sibling;
index++;
}
return index;
}
/**
* @name get_child_node_num_of_parent
* @brief 获得节点的子节点数
* @param parent 父节点地址
* @return uint8_t
* @note 内部调用
*/
uint8_t get_child_node_num_of_parent(simple_ui_node_s_t *parent)
{
uint8_t num = 0;
if (NULL == parent)
{
return -1;
}
simple_ui_node_s_t *child_node = parent->first_child;
while (NULL != child_node)
{
child_node = child_node->next_sibling;
num++;
}
return num;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/EuwHusky/sui.git
git@gitee.com:EuwHusky/sui.git
EuwHusky
sui
SUI
main

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385