コード例 #1
0
        private void Layout(int index, UIGraphData graph, NativeArray <NodeInfo> configLayout, NativeArray <UIPassState> stateLayout, UIContextData *context)
        {
            if (!graph.TryGetConfigBlock(index, UIConfigLayoutTable.DisplayConfig, out IntPtr displayConfig) || (((DisplayConfig *)displayConfig.ToPointer())->display == VisibilityStyle.Visible))
            {
                var nodeInfo     = configLayout[index];
                var headerConfig = (HeaderConfig *)(graph.value + nodeInfo.nodeOffset).ToPointer();
                var configSource = graph.value + nodeInfo.configOffset;
                var state        = (UIPassState *)(((IntPtr)stateLayout.GetUnsafePtr()) + (UnsafeUtility.SizeOf <UIPassState>() * index)).ToPointer();

                IntPtr boxConfig;
                bool   hasBoxConfig = graph.TryGetConfigBlock(index, UIConfigLayoutTable.BoxModelConfig, out boxConfig);
                if (hasBoxConfig)
                {
                    BoxModelConfig *boxConfigPtr = (BoxModelConfig *)boxConfig.ToPointer();
                    state->localBox += boxConfigPtr->margin.Normalize(*context);
                    state->inner     = boxConfigPtr->padding.Normalize(*context);
                }
                FunctionPointer <UILayoutPass> layout = headerConfig->schemaIndex >= 0 ? schema.Value.elements[headerConfig->schemaIndex].layout : default;
                for (int childIndex = 0; childIndex < headerConfig->childCount; childIndex++)
                {
                    if (layout.IsCreated)
                    {
                        layout.Invoke(
                            childIndex,
                            graph.value,
                            (NodeInfo *)UnsafeUtility.AddressOf(ref nodeInfo),
                            (IntPtr)stateLayout.GetUnsafePtr(),
                            context
                            );
                    }
                    Layout(UnsafeUtility.ReadArrayElement <int>((graph.value + nodeInfo.childrenOffset).ToPointer(), childIndex), graph, configLayout, stateLayout, context);
                }
                if (layout.IsCreated)
                {
                    layout.Invoke(
                        -1,
                        graph.value,
                        (NodeInfo *)UnsafeUtility.AddressOf(ref nodeInfo),
                        (IntPtr)stateLayout.GetUnsafePtr(),
                        context
                        );
                }
                if (graph.TryGetConfigBlock(index, UIConfigLayoutTable.SizeConfig, out IntPtr sizeConfig))
                {
                    var sizeConfigPtr = ((SizeConfig *)sizeConfig.ToPointer());
                    state->size = new float2(
                        math.clamp(state->size.x, sizeConfigPtr->minWidth.Normalize(*context), sizeConfigPtr->maxWidth.Normalize(*context)),
                        math.clamp(state->size.y, sizeConfigPtr->minHeight.Normalize(*context), sizeConfigPtr->maxHeight.Normalize(*context)));
                }
                if (hasBoxConfig)
                {
                    state->size += new float2(state->inner.x + state->inner.z, state->inner.y + state->inner.w);
                }
            }
        }
コード例 #2
0
        public static void Render(IntPtr configPtr, NodeInfo *nodeInfo, UIPassState *statePtr, UIVertexData *vertexDataPtr, UIContextData *context)
        {
            IntPtr            configSource           = configPtr + nodeInfo->configOffset;
            BoxModelConfig *  boxConfig              = (BoxModelConfig *)UIConfigUtility.GetConfig(nodeInfo->configurationMask, UIConfigLayoutTable.BoxModelConfig, configSource).ToPointer();
            BackgroundConfig *backgroundConfig       = (BackgroundConfig *)UIConfigUtility.GetConfig(nodeInfo->configurationMask, UIConfigLayoutTable.BackgroundConfig, configSource).ToPointer();
            BorderConfig *    borderConfig           = (BorderConfig *)UIConfigUtility.GetConfig(nodeInfo->configurationMask, UIConfigLayoutTable.BorderConfig, configSource).ToPointer();
            SizeConfig *      sizeConfig             = (SizeConfig *)UIConfigUtility.GetConfig(nodeInfo->configurationMask, UIConfigLayoutTable.SizeConfig, configSource).ToPointer();
            BoxLayoutConfig * sequentialLayoutConfig = (BoxLayoutConfig *)UIConfigUtility.GetConfig(nodeInfo->configurationMask, UIConfigLayoutTable.BoxLayoutConfig, configSource).ToPointer();
            HeaderConfig *    headerConfig           = (HeaderConfig *)(configPtr + nodeInfo->nodeOffset);

            UIRenderBoxWriters.WriteRenderBox(statePtr, backgroundConfig, borderConfig, vertexDataPtr, context);
        }
コード例 #3
0
        public static void Layout(int childIndex, IntPtr configPtr, NodeInfo *nodeInfo, IntPtr statePtr, UIContextData *context)
        {
            if (childIndex < 0)
            {
                UIPassState *     selfPtr          = (UIPassState *)(((IntPtr)statePtr) + (UnsafeUtility.SizeOf <UIPassState>() * nodeInfo->index)).ToPointer();
                IntPtr            configSource     = configPtr + nodeInfo->configOffset;
                BoxModelConfig *  boxConfig        = (BoxModelConfig *)UIConfigUtility.GetConfig(nodeInfo->configurationMask, UIConfigLayoutTable.BoxModelConfig, configSource).ToPointer();
                BackgroundConfig *backgroundConfig = (BackgroundConfig *)UIConfigUtility.GetConfig(nodeInfo->configurationMask, UIConfigLayoutTable.BackgroundConfig, configSource).ToPointer();
                BorderConfig *    borderConfig     = (BorderConfig *)UIConfigUtility.GetConfig(nodeInfo->configurationMask, UIConfigLayoutTable.BorderConfig, configSource).ToPointer();
                SizeConfig *      sizeConfig       = (SizeConfig *)UIConfigUtility.GetConfig(nodeInfo->configurationMask, UIConfigLayoutTable.SizeConfig, configSource).ToPointer();

                BoxLayoutConfig *boxLayoutConfig = (BoxLayoutConfig *)UIConfigUtility.GetConfig(nodeInfo->configurationMask, UIConfigLayoutTable.BoxLayoutConfig, configSource).ToPointer();
                HeaderConfig *   headerConfig    = (HeaderConfig *)(configPtr + nodeInfo->nodeOffset);
                float            height          = 0f;
                float            width           = 0f;
                float2           childrenSize    = default;
                int4             multiplier      = default;
                //float4 padding = boxConfig->padding.Normalize(*context);
                float4 constraints = new float4(
                    sizeConfig->minWidth.Normalize(*context), sizeConfig->maxWidth.Normalize(*context),
                    sizeConfig->minHeight.Normalize(*context), sizeConfig->maxHeight.Normalize(*context)
                    );
                var spacing = boxLayoutConfig->spacing.Normalize(*context);
                switch (boxLayoutConfig->direction)
                {
                case Direction.Left:
                    for (int i = 0; i < headerConfig->childCount; i++)
                    {
                        var childState = (UIPassState *)(((IntPtr)statePtr) + (UnsafeUtility.SizeOf <UIPassState>() * UnsafeUtility.ReadArrayElement <int>((configPtr + nodeInfo->childrenOffset).ToPointer(), headerConfig->childCount - 1 - i))).ToPointer();
                        LayoutHorizontal(childState, ref width, ref height);
                        if (i + 1 < headerConfig->childCount)
                        {
                            width += spacing;
                        }
                    }
                    multiplier = new int4(1, 0, 0, 1);
                    break;

                case Direction.Right:
                    for (int i = 0; i < headerConfig->childCount; i++)
                    {
                        var childState = (UIPassState *)(statePtr + (UnsafeUtility.SizeOf <UIPassState>() * (UnsafeUtility.ReadArrayElement <int>((configPtr + nodeInfo->childrenOffset).ToPointer(), i)))).ToPointer();
                        LayoutHorizontal(childState, ref width, ref height);
                        if (i + 1 < headerConfig->childCount)
                        {
                            width += spacing;
                        }
                    }
                    multiplier = new int4(1, 0, 0, 1);
                    break;

                case Direction.Up:
                    for (int i = 0; i < headerConfig->childCount; i++)
                    {
                        var childState = (UIPassState *)(((IntPtr)statePtr) + (UnsafeUtility.SizeOf <UIPassState>() * UnsafeUtility.ReadArrayElement <int>((configPtr + nodeInfo->childrenOffset).ToPointer(), i))).ToPointer();
                        LayoutVertical(childState, ref height, ref width);
                        if (i + 1 < headerConfig->childCount)
                        {
                            height += spacing;
                        }
                    }
                    multiplier = new int4(0, 1, 1, 0);
                    break;

                case Direction.Down:
                    for (int i = 0; i < headerConfig->childCount; i++)
                    {
                        var childState = (UIPassState *)(((IntPtr)statePtr) + (UnsafeUtility.SizeOf <UIPassState>() * UnsafeUtility.ReadArrayElement <int>((configPtr + nodeInfo->childrenOffset).ToPointer(), headerConfig->childCount - 1 - i))).ToPointer();
                        LayoutVertical(childState, ref height, ref width);
                        if (i + 1 < headerConfig->childCount)
                        {
                            height += spacing;
                        }
                    }
                    multiplier = new int4(0, 1, 1, 0);
                    break;
                }
                childrenSize  = new float2(width, height);
                selfPtr->size = new float2(
                    math.clamp(childrenSize.x, constraints.x, constraints.y),
                    math.clamp(childrenSize.y, constraints.z, constraints.w)
                    );;
                UIJobUtility.AdjustPosition(childrenSize, constraints, boxLayoutConfig, selfPtr, statePtr, headerConfig->childCount, (configPtr + nodeInfo->childrenOffset).ToPointer(), multiplier);

                //Debug.Log(selfPtr->size);
            }
        }