void UniquelyControlledElement::CreateUniqueView(BaseComponent* pContent) { DestroyView(); m_pContent = Ptr(DynamicCast(pContent)); if (nullptr == m_pContent) { S2_LOG(UI, "Failed to create a view for the content passed to a UniquelyControlledElement. No view will be allocated. Name=%s, Content Type=%s", GetName(), nullptr != pContent ? pContent->GetClassType()->GetName() : "[Content Address Invalid]"); return; } SetContent(static_cast(nullptr)); SlApplication *pApplication = SlApplication::Current(); if (nullptr != pApplication) { SlWindow *pWindow = pApplication->GetMainWindow(); if (nullptr != pWindow) { // f32 fWidth = pWindow->GetActualWidth(); f32 fHeight = pWindow->GetActualHeight(); // Start collapsed, we'll make visible when either visibility changes or when the elements loads. m_pContent->SetVisibility(Visibility_Hidden); m_pContent->SetHorizontalAlignment(GetHorizontalAlignment()); m_pContent->SetVerticalAlignment(GetVerticalAlignment()); m_pRootNode = MakePtr(); m_pRootNode->SetStretch(Stretch_Fill); m_pRootNode->SetDataContext(GetDataContext()); m_uViewIndex = pWindow->RegisterView(m_pRootNode); BoxedValue *pfUIWidth = TryFindResource("UIWidth"); BoxedValue *pfUIHeight = TryFindResource("UIHeight"); Ptr pBorder = MakePtr(); pBorder->SetWidth(nullptr != pfUIWidth ? *static_cast(pfUIWidth->GetValuePtr()) : 3840.0f); pBorder->SetHeight(nullptr != pfUIHeight ? *static_cast(pfUIHeight->GetValuePtr()) : 2160.0f); m_pRootNode->SetChild(pBorder); pBorder->SetChild(m_pContent); pWindow->InitView(m_uViewIndex, static_cast(fWidth), static_cast(fHeight), 1, true); SlRenderer::AddRenderTaskStatic(&SelfClass::RenderThread_InitRendererForView, *(u32**)(&m_uViewIndex)); } } SetContent(MakePtr()); // Set the dummy positional object }