| | 1 | | using System.Collections.Generic; |
| | 2 | | using System.Linq; |
| | 3 | | using DCL.Controllers; |
| | 4 | | using DCL.ECS7.UI; |
| | 5 | | using DCL.ECSComponents; |
| | 6 | | using DCL.ECSRuntime; |
| | 7 | | using DCL.Models; |
| | 8 | | using UnityEngine; |
| | 9 | | using UnityEngine.UIElements; |
| | 10 | | using Random = UnityEngine.Random; |
| | 11 | |
|
| | 12 | | namespace DCL.ECS7 |
| | 13 | | { |
| | 14 | | public struct VisualElementRepresentation |
| | 15 | | { |
| | 16 | | public long entityId; |
| | 17 | | public long parentId; |
| | 18 | | public VisualElement visualElement; |
| | 19 | | public VisualElement parentVisualElement; |
| | 20 | | } |
| | 21 | |
|
| | 22 | | public class CanvasPainter |
| | 23 | | { |
| | 24 | | private const string UI_DOCUMENT_PREFAB_PATH = "RootNode"; |
| | 25 | | private const int FRAMES_PER_PAINT = 10; |
| | 26 | |
|
| | 27 | | internal readonly UIDocument rootNode; |
| | 28 | | internal readonly IUIDataContainer dataContainer; |
| | 29 | | private readonly RendererState rendererState; |
| | 30 | | private readonly BaseList<IParcelScene> loadedScenes; |
| | 31 | | private readonly IUpdateEventHandler updateEventHandler; |
| | 32 | | private readonly IWorldState worldState; |
| | 33 | | private readonly ECSComponentsManager componentsManager; |
| | 34 | |
|
| | 35 | | internal UISceneDataContainer sceneDataContainerToUse; |
| | 36 | | private IParcelScene scene; |
| | 37 | |
|
| 13 | 38 | | internal Dictionary<long, VisualElementRepresentation> visualElements = new Dictionary<long, VisualElementRepres |
| 13 | 39 | | internal List<VisualElementRepresentation> orphanVisualElements = new List<VisualElementRepresentation>(); |
| | 40 | |
|
| | 41 | | internal IECSReadOnlyComponentsGroup<PBUiTransform, PBUiText> textComponentGroup; |
| | 42 | |
|
| | 43 | | internal int framesCounter = 0; |
| | 44 | | internal bool canvasCleared = false; |
| | 45 | |
|
| 13 | 46 | | public CanvasPainter(DataStore_ECS7 dataStoreEcs7, RendererState rendererState, IUpdateEventHandler updateEventH |
| | 47 | | { |
| 13 | 48 | | this.updateEventHandler = updateEventHandler; |
| 13 | 49 | | this.loadedScenes = dataStoreEcs7.scenes; |
| 13 | 50 | | this.rendererState = rendererState; |
| 13 | 51 | | this.dataContainer = dataStoreEcs7.uiDataContainer; |
| 13 | 52 | | this.worldState = worldState; |
| | 53 | |
|
| 13 | 54 | | var prefab = Resources.Load<UIDocument>(UI_DOCUMENT_PREFAB_PATH); |
| 13 | 55 | | rootNode = GameObject.Instantiate(prefab); |
| | 56 | |
|
| 13 | 57 | | updateEventHandler.AddListener(IUpdateEventHandler.EventType.Update, Update); |
| | 58 | |
|
| | 59 | | // Group Components |
| 13 | 60 | | textComponentGroup = componentsManager.CreateComponentGroup<PBUiTransform, PBUiText>(ComponentID.UI_TRANSFOR |
| | 61 | | #if UNITY_EDITOR |
| 13 | 62 | | rootNode.name = "Scene Canvas"; |
| | 63 | | #endif |
| 13 | 64 | | } |
| | 65 | |
|
| | 66 | | public void Dispose() |
| | 67 | | { |
| 13 | 68 | | GameObject.Destroy(rootNode.gameObject); |
| 13 | 69 | | updateEventHandler.RemoveListener(IUpdateEventHandler.EventType.Update, Update); |
| 13 | 70 | | if(sceneDataContainerToUse != null) |
| 8 | 71 | | sceneDataContainerToUse.OnUITransformRemoved -= RemoveVisualElement; |
| 13 | 72 | | } |
| | 73 | |
|
| | 74 | | internal void SetScene(IParcelScene scene) |
| | 75 | | { |
| 9 | 76 | | this.scene = scene; |
| | 77 | |
|
| 9 | 78 | | if(sceneDataContainerToUse != null) |
| 1 | 79 | | sceneDataContainerToUse.OnUITransformRemoved -= RemoveVisualElement; |
| | 80 | |
|
| | 81 | | // We get the UI information of the scene to paint their canvas |
| 9 | 82 | | sceneDataContainerToUse = dataContainer.GetDataContainer(scene); |
| 9 | 83 | | sceneDataContainerToUse.OnUITransformRemoved += RemoveVisualElement; |
| 9 | 84 | | ClearAndHideRootLayout(); |
| 9 | 85 | | } |
| | 86 | |
|
| | 87 | | private void ClearAndHideRootLayout() |
| | 88 | | { |
| 9 | 89 | | rootNode.rootVisualElement.visible = false; |
| 9 | 90 | | rootNode.rootVisualElement.Clear(); |
| 9 | 91 | | canvasCleared = true; |
| 9 | 92 | | } |
| | 93 | |
|
| | 94 | | private void RemoveVisualElement(IDCLEntity entity) |
| | 95 | | { |
| | 96 | | // We try to get the parent |
| 1 | 97 | | if (visualElements.TryGetValue(entity.entityId, out VisualElementRepresentation visualElementRepresentantion |
| | 98 | | { |
| 1 | 99 | | if (visualElementRepresentantion.parentVisualElement != null) |
| 0 | 100 | | visualElementRepresentantion.parentVisualElement.Remove(visualElementRepresentantion.visualElement); |
| | 101 | |
|
| 1 | 102 | | visualElements.Remove(entity.entityId); |
| | 103 | | } |
| 1 | 104 | | } |
| | 105 | |
|
| | 106 | | internal void Update() |
| | 107 | | { |
| 5 | 108 | | framesCounter++; |
| 5 | 109 | | if (!rendererState.Get() || framesCounter < FRAMES_PER_PAINT) |
| 0 | 110 | | return; |
| | 111 | |
|
| 5 | 112 | | framesCounter = 0; |
| | 113 | |
|
| | 114 | | // We look in which scene is the player, and draw the UI of that scene |
| 5 | 115 | | bool sceneFound = false; |
| 12 | 116 | | for (int i = 0; i < loadedScenes.Count; i++) |
| | 117 | | { |
| 6 | 118 | | if(loadedScenes[i].sceneData.id != worldState.GetCurrentSceneId()) |
| | 119 | | continue; |
| 5 | 120 | | sceneFound = true; |
| 5 | 121 | | DrawUI(loadedScenes[i]); |
| 5 | 122 | | break; |
| | 123 | | } |
| | 124 | |
|
| | 125 | | // If we are entering in an empty parcel, or ECS6 scene, we should also clear the UI |
| 5 | 126 | | if (!sceneFound && !canvasCleared) |
| 0 | 127 | | ClearAndHideRootLayout(); |
| 5 | 128 | | } |
| | 129 | |
|
| | 130 | | private void DrawUI(IParcelScene scene) |
| | 131 | | { |
| 5 | 132 | | if(this.scene != scene || canvasCleared) |
| 5 | 133 | | SetScene(scene); |
| | 134 | |
|
| 5 | 135 | | DrawUI(); |
| 5 | 136 | | } |
| | 137 | |
|
| | 138 | | private void DrawUI() |
| | 139 | | { |
| | 140 | | // If the canvas hasn't change or if there is no canvas we skip |
| 5 | 141 | | if (!canvasCleared && (!sceneDataContainerToUse.IsDirty() || !sceneDataContainerToUse.sceneCanvasTransform.A |
| 0 | 142 | | return; |
| | 143 | |
|
| 5 | 144 | | canvasCleared = false; |
| 5 | 145 | | sceneDataContainerToUse.UIRendered(); |
| | 146 | |
|
| | 147 | | // We ensure that the root canvas is visible |
| 5 | 148 | | rootNode.rootVisualElement.visible = true; |
| | 149 | |
|
| | 150 | | // This should be the way to go when we implement the UI events |
| | 151 | | // visualElement.RegisterCallback<ClickEvent>(ev => Debug.Log("Clicked")); |
| | 152 | |
|
| | 153 | | // It can happen that we received or processed the child before the parent, that make some elements orphan |
| | 154 | | // If we have some orphan elements, we try to search and assign the parent here, if we don't found it, we wi |
| 5 | 155 | | TryToSetOrphanParents(); |
| | 156 | |
|
| 5 | 157 | | List<long> entitiesWithRendererComponent = new List<long>(); |
| | 158 | |
|
| | 159 | | // This will create the text elements along their UITransform |
| 5 | 160 | | CreateTextElements(entitiesWithRendererComponent); |
| | 161 | |
|
| | 162 | | // This will create the containers to position the elements |
| 5 | 163 | | CreateContainers(entitiesWithRendererComponent); |
| | 164 | |
|
| | 165 | | // We set the parent of all the elements that has been created |
| 44 | 166 | | foreach (KeyValuePair<long,VisualElementRepresentation> kvp in visualElements) |
| | 167 | | { |
| 17 | 168 | | var visualElement = kvp.Value; |
| 17 | 169 | | SetParent(ref visualElement); |
| | 170 | | } |
| 5 | 171 | | } |
| | 172 | |
|
| | 173 | | internal void CreateContainers(List<long> excludedEntities) |
| | 174 | | { |
| 6 | 175 | | var enumerator = sceneDataContainerToUse.sceneCanvasTransform.GetEnumerator(); |
| | 176 | | try |
| | 177 | | { |
| | 178 | | // We create all the elements that doesn't have a rendering ( Image, Text...etc) since we need them to p |
| 24 | 179 | | while (enumerator.MoveNext()) |
| | 180 | | { |
| 18 | 181 | | var kvp = enumerator.Current; |
| | 182 | | // If the entity doesn't exist we skip |
| 18 | 183 | | if (!scene.entities.TryGetValue( kvp.Key, out IDCLEntity entity)) |
| | 184 | | continue; |
| | 185 | |
|
| | 186 | | // If the entity already have a rendering element, we skip since we don't need to create it again |
| 18 | 187 | | if (excludedEntities.Contains(entity.entityId)) |
| | 188 | | continue; |
| | 189 | |
|
| | 190 | | // We create the element to position the rendering element correctly |
| 18 | 191 | | var visualElement = TransformToVisualElement(kvp.Value, new Image()); |
| 18 | 192 | | visualElements[entity.entityId] = new VisualElementRepresentation() |
| | 193 | | { |
| | 194 | | entityId = entity.entityId, |
| | 195 | | parentId = entity.parentId, |
| | 196 | | visualElement = visualElement |
| | 197 | | }; |
| | 198 | | } |
| 6 | 199 | | } |
| | 200 | | finally |
| | 201 | | { |
| 6 | 202 | | enumerator.Dispose(); |
| 6 | 203 | | } |
| 6 | 204 | | } |
| | 205 | |
|
| | 206 | | internal void CreateTextElements(List<long> entitiesWithRendererComponent) |
| | 207 | | { |
| | 208 | | IECSReadOnlyComponentData<PBUiTransform> componentData; |
| | 209 | |
|
| | 210 | | // We create all the text elements |
| 10 | 211 | | for(int i = 0; i < textComponentGroup.group.Count; i++) |
| | 212 | | { |
| 0 | 213 | | componentData = textComponentGroup.group[i].componentData1; |
| | 214 | |
|
| 0 | 215 | | var textElement = new TextElement(); |
| 0 | 216 | | textElement.text = textComponentGroup.group[i].componentData2.model.Value; |
| 0 | 217 | | var color = textComponentGroup.group[i].componentData2.model.Color; |
| 0 | 218 | | textElement.style.color = new UnityEngine.Color(color.R, color.G,color.B,1); |
| | 219 | |
|
| | 220 | | // We create the text element |
| 0 | 221 | | var visualElement = TransformToVisualElement(componentData.model, textElement, false); |
| | 222 | |
|
| 0 | 223 | | visualElements[componentData.entity.entityId] = new VisualElementRepresentation() |
| | 224 | | { |
| | 225 | | entityId = componentData.entity.entityId, |
| | 226 | | parentId = componentData.entity.parentId, |
| | 227 | | visualElement = visualElement |
| | 228 | | }; |
| | 229 | |
|
| | 230 | | // We add the entity to a list so it doesn't create a visual element for the PBUiTransform since the tra |
| 0 | 231 | | entitiesWithRendererComponent.Add(componentData.entity.entityId); |
| | 232 | | } |
| 5 | 233 | | } |
| | 234 | |
|
| | 235 | | internal void TryToSetOrphanParents() |
| | 236 | | { |
| 10 | 237 | | for(int i = 0; i < orphanVisualElements.Count; i++) |
| | 238 | | { |
| 0 | 239 | | var visualElement = orphanVisualElements[i]; |
| 0 | 240 | | SetParent(ref visualElement, false); |
| | 241 | |
|
| | 242 | | // If we found the parent, we remove it and set it visible |
| 0 | 243 | | if (orphanVisualElements[i].parentVisualElement != null) |
| | 244 | | { |
| 0 | 245 | | orphanVisualElements[i].visualElement.visible = true; |
| 0 | 246 | | orphanVisualElements.Remove(orphanVisualElements[i]); |
| | 247 | | } |
| | 248 | | } |
| 5 | 249 | | } |
| | 250 | |
|
| | 251 | | internal void SetParent(ref VisualElementRepresentation visualElementRepresentation, bool addToOrphanList = true |
| | 252 | | { |
| | 253 | | // if the parent is the root canvas, it doesn't have parent, we skip |
| 20 | 254 | | if (visualElementRepresentation.parentId == SpecialEntityId.SCENE_ROOT_ENTITY) |
| | 255 | | { |
| 5 | 256 | | rootNode.rootVisualElement.Add(visualElementRepresentation.visualElement); |
| 5 | 257 | | visualElementRepresentation.parentVisualElement = rootNode.rootVisualElement; |
| 5 | 258 | | } |
| | 259 | | else |
| | 260 | | { |
| | 261 | | // We try to get the parent |
| 15 | 262 | | if (visualElements.TryGetValue(visualElementRepresentation.parentId, out VisualElementRepresentation par |
| | 263 | | { |
| 14 | 264 | | parentVisualElementRepresentantion.visualElement.Add(visualElementRepresentation.visualElement); |
| 14 | 265 | | visualElementRepresentation.parentVisualElement = parentVisualElementRepresentantion.visualElement; |
| 14 | 266 | | } |
| 1 | 267 | | else if (addToOrphanList) |
| | 268 | | { |
| | 269 | | // There is no father so it is orphan right now. We can try to find the father the next time, we hid |
| 1 | 270 | | visualElementRepresentation.visualElement.visible = false; |
| 1 | 271 | | orphanVisualElements.Add(visualElementRepresentation); |
| | 272 | | } |
| | 273 | | } |
| 1 | 274 | | } |
| | 275 | |
|
| | 276 | | internal VisualElement TransformToVisualElement(PBUiTransform model, VisualElement element, bool randomColor = t |
| | 277 | | { |
| 19 | 278 | | element.style.display = GetDisplay(model.Display); |
| 19 | 279 | | element.style.overflow = GetOverflow(model.Overflow); |
| | 280 | |
|
| | 281 | | // Flex |
| 19 | 282 | | element.style.flexDirection = GetFlexDirection(model.FlexDirection); |
| 19 | 283 | | if (!float.IsNaN(model.FlexBasis)) |
| 6 | 284 | | element.style.flexBasis = new Length(model.FlexBasis, GetUnit(model.FlexBasisUnit)); |
| | 285 | |
|
| 19 | 286 | | element.style.flexGrow = model.FlexGrow; |
| 19 | 287 | | element.style.flexShrink = model.FlexShrink; |
| 19 | 288 | | element.style.flexWrap = GetWrap(model.FlexWrap); |
| | 289 | |
|
| | 290 | | // Align |
| 19 | 291 | | if (model.AlignContent != YGAlign.FlexStart) |
| 3 | 292 | | element.style.alignContent = GetAlign(model.AlignContent); |
| 19 | 293 | | if (model.AlignItems != YGAlign.Auto) |
| 3 | 294 | | element.style.alignItems = GetAlign(model.AlignItems); |
| 19 | 295 | | if (model.AlignSelf != YGAlign.Auto) |
| 6 | 296 | | element.style.alignSelf = GetAlign(model.AlignSelf); |
| 19 | 297 | | element.style.justifyContent = GetJustify(model.JustifyContent); |
| | 298 | |
|
| | 299 | | // Layout size |
| 19 | 300 | | if (!float.IsNaN(model.Height)) |
| 19 | 301 | | element.style.height = new Length(model.Height, GetUnit(model.HeightUnit)); |
| 19 | 302 | | if (!float.IsNaN(model.Width)) |
| 19 | 303 | | element.style.width = new Length(model.Width, GetUnit(model.WidthUnit)); |
| | 304 | |
|
| 19 | 305 | | if (!float.IsNaN(model.MaxWidth)) |
| 3 | 306 | | element.style.maxWidth = new Length(model.MaxWidth, GetUnit(model.MaxWidthUnit)); |
| 19 | 307 | | if (!float.IsNaN(model.MaxHeight)) |
| 3 | 308 | | element.style.maxHeight = new Length(model.MaxHeight, GetUnit(model.MaxHeightUnit)); |
| | 309 | |
|
| 19 | 310 | | if (!float.IsNaN(model.MinHeight)) |
| 3 | 311 | | element.style.minHeight = new Length(model.MinHeight, GetUnit(model.MinHeightUnit)); |
| 19 | 312 | | if (!float.IsNaN(model.MinWidth)) |
| 3 | 313 | | element.style.minWidth = new Length(model.MinWidth, GetUnit(model.MinWidthUnit)); |
| | 314 | |
|
| | 315 | | // Paddings |
| 19 | 316 | | if (!Mathf.Approximately(model.PaddingBottom, 0)) |
| 3 | 317 | | element.style.paddingBottom = new Length(model.PaddingBottom, GetUnit(model.PaddingBottomUnit)); |
| 19 | 318 | | if (!Mathf.Approximately(model.PaddingLeft, 0)) |
| 3 | 319 | | element.style.paddingLeft = new Length(model.PaddingLeft, GetUnit(model.PaddingLeftUnit)); |
| 19 | 320 | | if (!Mathf.Approximately(model.PaddingRight, 0)) |
| 3 | 321 | | element.style.paddingRight = new Length(model.PaddingRight, GetUnit(model.PaddingRightUnit)); |
| 19 | 322 | | if (!Mathf.Approximately(model.PaddingTop, 0)) |
| 3 | 323 | | element.style.paddingTop = new Length(model.PaddingTop, GetUnit(model.PaddingTopUnit)); |
| | 324 | |
|
| | 325 | | // Margins |
| 19 | 326 | | if (!Mathf.Approximately(model.MarginLeft, 0)) |
| 3 | 327 | | element.style.marginLeft = new Length(model.MarginLeft, GetUnit(model.MarginLeftUnit)); |
| 19 | 328 | | if (!Mathf.Approximately(model.MarginRight, 0)) |
| 3 | 329 | | element.style.marginRight = new Length(model.MarginRight, GetUnit(model.MarginRightUnit)); |
| 19 | 330 | | if (!Mathf.Approximately(model.MarginBottom, 0)) |
| 3 | 331 | | element.style.marginBottom = new Length(model.MarginBottom, GetUnit(model.MarginBottomUnit)); |
| 19 | 332 | | if (!Mathf.Approximately(model.MarginTop, 0)) |
| 3 | 333 | | element.style.marginTop = new Length(model.MarginTop, GetUnit(model.MarginTopUnit)); |
| | 334 | |
|
| | 335 | | // Borders |
| 19 | 336 | | element.style.borderBottomWidth = model.BorderBottom; |
| 19 | 337 | | element.style.borderLeftWidth = model.BorderLeft; |
| 19 | 338 | | element.style.borderRightWidth = model.BorderRight; |
| 19 | 339 | | element.style.borderTopWidth = model.BorderTop; |
| | 340 | |
|
| | 341 | | // Position |
| 19 | 342 | | element.style.position = GetPosition(model.PositionType); |
| | 343 | |
|
| | 344 | | // This is for debugging purposes, we will change this to a proper approach so devs can debug the UI easily. |
| 19 | 345 | | if (randomColor) |
| 19 | 346 | | element.style.backgroundColor = Random.ColorHSV(); |
| | 347 | |
|
| 19 | 348 | | return element; |
| | 349 | | } |
| | 350 | |
|
| | 351 | | internal LengthUnit GetUnit(YGUnit unit) |
| | 352 | | { |
| | 353 | | switch (unit) |
| | 354 | | { |
| | 355 | | case YGUnit.Point: |
| 0 | 356 | | return LengthUnit.Pixel; |
| | 357 | | case YGUnit.Percent: |
| 0 | 358 | | return LengthUnit.Percent; |
| | 359 | | default: |
| 0 | 360 | | return LengthUnit.Pixel; |
| | 361 | | } |
| | 362 | | } |
| | 363 | |
|
| | 364 | | internal StyleEnum<Overflow> GetOverflow (YGOverflow overflow) |
| | 365 | | { |
| | 366 | | switch (overflow) |
| | 367 | | { |
| | 368 | | case YGOverflow.Visible: |
| 17 | 369 | | return Overflow.Visible; |
| | 370 | | case YGOverflow.Hidden: |
| 3 | 371 | | return Overflow.Hidden; |
| | 372 | | default: |
| 0 | 373 | | return Overflow.Visible; |
| | 374 | | } |
| | 375 | | } |
| | 376 | |
|
| | 377 | | internal StyleEnum<DisplayStyle> GetDisplay (YGDisplay display) |
| | 378 | | { |
| | 379 | | switch (display) |
| | 380 | | { |
| | 381 | | case YGDisplay.Flex: |
| 20 | 382 | | return DisplayStyle.Flex; |
| | 383 | | break; |
| | 384 | | case YGDisplay.None: |
| 0 | 385 | | return DisplayStyle.None; |
| | 386 | | default: |
| 0 | 387 | | return DisplayStyle.Flex; |
| | 388 | | } |
| | 389 | | } |
| | 390 | |
|
| | 391 | | internal StyleEnum<Justify> GetJustify (YGJustify justify) |
| | 392 | | { |
| | 393 | | switch (justify) |
| | 394 | | { |
| | 395 | | case YGJustify.FlexStart: |
| 16 | 396 | | return Justify.FlexStart; |
| | 397 | | case YGJustify.Center: |
| 5 | 398 | | return Justify.Center; |
| | 399 | | case YGJustify.FlexEnd: |
| 0 | 400 | | return Justify.FlexEnd; |
| | 401 | | case YGJustify.SpaceBetween: |
| 0 | 402 | | return Justify.SpaceBetween; |
| | 403 | | case YGJustify.SpaceAround: |
| 0 | 404 | | return Justify.SpaceAround; |
| | 405 | | default: |
| 0 | 406 | | return Justify.FlexStart; |
| | 407 | | } |
| | 408 | | } |
| | 409 | |
|
| | 410 | | internal StyleEnum<Wrap> GetWrap (YGWrap wrap) |
| | 411 | | { |
| | 412 | | switch (wrap) |
| | 413 | | { |
| | 414 | | case YGWrap.NoWrap: |
| 16 | 415 | | return Wrap.NoWrap; |
| | 416 | | case YGWrap.Wrap: |
| 3 | 417 | | return Wrap.Wrap; |
| | 418 | | case YGWrap.WrapReverse: |
| 2 | 419 | | return Wrap.WrapReverse; |
| | 420 | | default: |
| 0 | 421 | | return Wrap.Wrap; |
| | 422 | | } |
| | 423 | | } |
| | 424 | |
|
| | 425 | | internal StyleEnum<FlexDirection> GetFlexDirection (YGFlexDirection direction) |
| | 426 | | { |
| | 427 | | switch (direction) |
| | 428 | | { |
| | 429 | | case YGFlexDirection.Column: |
| 5 | 430 | | return FlexDirection.Column; |
| | 431 | | case YGFlexDirection.ColumnReverse: |
| 0 | 432 | | return FlexDirection.ColumnReverse; |
| | 433 | | case YGFlexDirection.Row: |
| 15 | 434 | | return FlexDirection.Row; |
| | 435 | | case YGFlexDirection.RowReverse: |
| 2 | 436 | | return FlexDirection.RowReverse; |
| | 437 | | default: |
| 0 | 438 | | return FlexDirection.Row; |
| | 439 | | } |
| | 440 | | } |
| | 441 | |
|
| | 442 | | internal StyleEnum<Position> GetPosition(YGPositionType positionType) |
| | 443 | | { |
| | 444 | | switch (positionType) |
| | 445 | | { |
| | 446 | | case YGPositionType.Relative: |
| 17 | 447 | | return Position.Relative; |
| | 448 | | case YGPositionType.Absolute: |
| 4 | 449 | | return Position.Absolute; |
| | 450 | | default: |
| 0 | 451 | | return Position.Relative; |
| | 452 | | } |
| | 453 | | } |
| | 454 | |
|
| | 455 | | internal StyleEnum<Align> GetAlign(YGAlign align) |
| | 456 | | { |
| | 457 | | switch (align) |
| | 458 | | { |
| | 459 | | case YGAlign.Auto: |
| 0 | 460 | | return Align.Auto; |
| | 461 | | case YGAlign.FlexStart: |
| 0 | 462 | | return Align.FlexStart; |
| | 463 | | case YGAlign.Center: |
| 21 | 464 | | return Align.Center; |
| | 465 | | case YGAlign.FlexEnd: |
| 0 | 466 | | return Align.FlexEnd; |
| | 467 | | case YGAlign.Stretch: |
| 0 | 468 | | return Align.Stretch; |
| | 469 | | default: |
| 0 | 470 | | return Align.Auto; |
| | 471 | | } |
| | 472 | | } |
| | 473 | | } |
| | 474 | | } |