Flex Panel 노드 생성하기
flexpanel_create_node
함수는 새로운 Flex Panel 노드를 생성합니다. 이 함수는 선택적으로 JSON 문자열이나 노드의 속성을 포함하는 구조체를 인자로 받을 수 있습니다. 이러한 속성은 나중에 다른 Flex Panel 함수들을 사용하여 설정할 수 있습니다. 반환된 노드는 다른 노드의 자식으로 삽입될 수 있습니다. 더 이상 노드가 필요하지 않을 경우, 반드시 삭제해야 메모리에 남지 않습니다.
문법
flexpanel_create_node([struct_or_json]);
인자 설명
인자 | 타입 | 설명 |
---|---|---|
struct_or_json | Struct 또는 String | 노드 정보가 담긴 구조체 또는 JSON 문자열 |
반환값
- Flex Panel Node
예제
예제 1: 빈 노드 생성하기
n_root = flexpanel_create_node();
이 코드는 빈 노드를 생성합니다. 이후 이 노드에 속성을 설정하고 다른 노드를 자식으로 삽입할 수 있습니다.
예제 2: 구조체 전달하기
var node_properties = {
"width": "100%",
"height": 300,
"padding": 10,
"nodes": [
{"height": 50},
{"flex": 1, "flexDirection": "column", "nodes": [{"aspectRatio": 2}, {"aspectRatio": 2}]}
]
};
n_root = flexpanel_create_node(node_properties);
이 코드는 구조체를 사용하여 노드를 생성합니다. 이 구조체는 루트 노드와 모든 중첩된 자식 노드의 속성 정보를 포함합니다.
예제 3: JSON 문자열 전달하기
n_root = flexpanel_create_node(@'{"width": "80%", "height": 200, "padding": 20, "nodes": [{"height": 20}, {"flex": 1, "flexDirection": "row", "nodes": [{"aspectRatio": 1}, {"aspectRatio": 1}, {"aspectRatio": 1}]}]}');
이 코드는 이전과 동일한 노드를 생성하지만, 구조체 대신 JSON 다중 문자열을 사용합니다.
활용 예제
예제 1: 복잡한 레이아웃 생성하기
var complex_layout = {
"width": "100%",
"height": "100%",
"nodes": [
{"height": 50},
{"flex": 1, "flexDirection": "row", "nodes": [
{"flex": 1, "aspectRatio": 1},
{"flex": 1, "aspectRatio": 1},
{"flex": 1, "aspectRatio": 1}
]}
]
};
n_complex = flexpanel_create_node(complex_layout);
예제 2: 동적으로 노드 추가하기
var new_node = flexpanel_create_node({"height": 100});
flexpanel_add_child(n_root, new_node);
예제 3: 노드 삭제하기
flexpanel_delete_node(n_root);
이 예제들은 Flex Panel 노드를 생성하고 조작하는 다양한 방법을 보여줍니다.