Skip to main content

Component Node 2D

Comments

2 comments

  • li shuhao

    I Cannot upload images.。。。。。。

    0
  • Jason Stanczyk
     
    Component node 2D

    In Kanzi, a Component Node 2D refers to a 2D node that you create within the scene graph. Here's what the knowledge sources tell us:

    What is a 2D Node (Node2D)?

    Node2D is the base class of all 2D nodes in Kanzi. It implements functionality common to all 2D nodes, such as rendering, layout, and hit testing. [Node2D Java API] [Node2D Runtime API]

    To build UI graphs, you use classes derived from Node2D, such as:

    • Image2D
    • EmptyNode2D
    • StackLayout2D
    • TextBlock2D

    Creating a Component Node 2D via Command

    In Kanzi Studio, you can create a 2D node using the CreateComponentNode2D command:

    CreateComponentNode2D parent itemName componentTypeName

    Examples:

    # Create a Content Layout 2D node named "My Content Layout" in the RootPage node
    CreateComponentNode2D "/Screens/Screen/RootPage" "My Content Layout" Kanzi.ContentLayout2D
    
    # Create a Prefab View 2D node named "My Prefab View" in the RootPage node
    CreateComponentNode2D "/Screens/Screen/RootPage" "My Prefab View" Kanzi.PrefabView2D

    [Command Reference]

    Implementing a Custom 2D Node

    If you need custom rendering and layout, you can derive your own class from kanzi::Node2D:

    class ExampleNode2D : public kanzi::Node2D
    {
    public:
        static PropertyType<float> ExampleProperty;
    
        KZ_METACLASS_BEGIN(ExampleNode2D, Node2D, "MyNamespace.ExampleNode2D")
            KZ_METACLASS_PROPERTY_TYPE(ExampleProperty)
        KZ_METACLASS_END()
    
        static ExampleNode2DSharedPtr create(Domain* domain, string_view name);
    
    protected:
        explicit ExampleNode2D(Domain* domain, string_view name);
        void initialize();
        Vector2 measureOverride(Vector2 availableSize) override;
        void updateRenderOverride() override;
    };

    [Custom 2D Node]

    0

Please sign in to leave a comment.