使用 Stack Layout 节点

使用 Stack Layout 节点在选定轴上依次排列节点。

您可以设置方向和起始点,以在 x、y 和 z 轴上排列 Stack Layout 3D 子节点,以及在 x 和 y 轴上排列 Stack Layout 2D 子节点。

../../_images/stack-layout.gif

创建一个 Stack Layout 节点

要创建 Stack Layout 节点:

  1. 在 Node Tree 按 Alt 并右键单击 中,选择您要创建 Stack Layout 节点的节点,并选择 Stack Layout 3D 或 Stack Layout 2D。

    您只能在 3D 节点中创建 3D 节点,例如 Scene 节点,并且只能在 2D 节点中创建 2D 节点。

    ../../_images/node-tree-create-stack-layout-2d.png

    小技巧

    在 Preview 中,选择 Stack Layout 2D tool stack-layout-tool,通过在 Preview 中点击并拖动来创建 Stack Layout 2D 节点。Stack Layout 2D 上方的 stack-tool-arrow 显示布局的方向。

    • 创建宽度大于高度的布局时,布局方向在 x 轴上。

      ../../_images/stack-layout-x-axis.png ../../_images/stack-layout-x-direction.png
    • 创建高度大于宽度的布局时,布局方向在 y 轴上。

      ../../_images/stack-layout-y-axis.png ../../_images/stack-layout-y-direction.png
  2. 在 Node Tree 中,将子节点添加到您在上一步中创建的布局中。

    例如,如果您创建了一个 Stack Layout 3D 节点,请添加几个 Sphere 节点,如果您创建了一个 Stack Layout 2D 节点,请添加几个 Image 节点。

    当您添加子节点时,Stack Layout 节点会根据其 Direction 属性定义的轴来定位它们。

    ../../_images/node-tree-stack-layout-images.png ../../_images/preview-stack-layout-images.png
  3. (可选) In the Properties set the Direction property to the axis long which you want the Stack Layout node to arrange its child nodes.

    ../../_images/stack-layout-change-direction.gif
  4. (可选) 要清除布局中子节点周围的区域,在 Node Tree 中选择布局中的子节点,在 Properties 中单击 image0,并添加和设置边距属性:

    • Depth Margin 用于清除子节点前后区域。

    • Horizontal Margin 用于清除子节点左右两侧的区域。

    • Vertical Margin 清除子节点顶部和底部的区域。

    ../../_images/stack-layout-add-margin.gif

反转 Stack Layout 节点子节点的顺序。

要反转 Stack Layout 节点中子节点的顺序,在 Node Tree 中选择您想要反转子节点顺序的 Stack Layout 节点,并在 Properties 中启用 Reversed 属性。

../../_images/stack-layout-reversing-order.gif

设置 Stack Layout 2D 节点的外观

要设置 2D 节点的外观:

在 API 中使用 Stack Layout 3D 节点

要创建 Stack Layout 3D 节点:

// Create a Stack Layout 3D node named Stack.
StackLayout3DSharedPtr stack = StackLayout3D::create(domain, "Stack");

要控制 Stack Layout 3D 节点的方向:

// Set the Stack Layout 3D node to arrange its items along the x axis.
stack->setDirection(StackLayout3D::DirectionX);

要将项添加到 Stack Layout 3D 节点:

// Stack Layout 3D node arranges its items in the order that you add items.
// Create a Model node and ...
Model3DSharedPtr item1 = Model3D::createBox(domain, "item1", Vector3(1.3f, 1.3f, 1.3f), ThemeRed);
// ... add it to the Stack Layout 3D node.
stack->addChild(item1);
Model3DSharedPtr item2 = Model3D::createSphere(domain, "item2", 0.8f, 30, 30, ThemeGreen);
stack->addChild(item2);
Model3DSharedPtr item3 = Model3D::createBox(domain, "item3", Vector3(1.0f, 1.0f, 1.0f), ThemeBlue);
stack->addChild(item3);

要反向 Stack Layout 3D 节点排列其项的顺序:

// Set the Stack Layout 3D node to arrange its items in the reverse order.
stack->setReversed(true);

有关详细信息,请参阅 StackLayout3D 类。

在 API 中使用 Stack Layout 2D 节点

要创建 Stack Layout 2D 节点:

// Create a Stack Layout 2D node named Stack.
StackLayout2DSharedPtr stack = StackLayout2D::create(domain, "Stack");

要控制 Stack Layout 2D 节点的方向:

// Set the Stack Layout 2D node to arrange its items along the x axis.
stack->setDirection(StackLayout2D::DirectionX);

要将项添加到 Stack Layout 2D 节点:

// Stack Layout 2D arranges its items in the order that you add items.
// Create a 2D node ...
EmptyNode2DSharedPtr item1 = EmptyNode2D::create(domain, "item1", 100.0f, 100.0f, ThemeRed);
// ... and add it to the Stack Layout 2D node.
stack->addChild(item1);
EmptyNode2DSharedPtr item2 = EmptyNode2D::create(domain, "item2", 100.0f, 100.0f, ThemeGreen);
stack->addChild(item2);
EmptyNode2DSharedPtr item3 = EmptyNode2D::create(domain, "item3", 100.0f, 100.0f, ThemeBlue);
stack->addChild(item3);

要反向 Stack Layout 2D 节点排列其项的顺序:

// Set the Stack Layout 2D node to arrange its items in the reverse order.
stack->setReversed(true);

有关详细信息,请参阅 StackLayout2D 类。

Stack Layout 属性类型和消息

有关 Stack Layout 节点的可用属性类型和消息的列表,请参阅 Stack Layout 2D 和 Stack Layout 3D。

另请参阅

使用 Dock Layout 节点

使用 Flow Layout 节点

使用 Grid Layout 节点

使用 Stack Layout 节点

使用 Trajectory Layout 节点

布局控制节点

使用 Kanzi Studio Preview 工具为节点启用点击手势。