XnStatus XnDeviceStream::UpdateRequiredSize()
{
	XnStatus nRetVal = XN_STATUS_OK;
	
	XnUInt32 nRequiredSize;
	nRetVal = CalcRequiredSize(&nRequiredSize);
	XN_IS_STATUS_OK(nRetVal);

	nRetVal = m_RequiredSize.UnsafeUpdateValue(nRequiredSize);
	XN_IS_STATUS_OK(nRetVal);
	
	return (XN_STATUS_OK);
}
void TextUiModel::CollectVertices( Text const& text, UiVertexInserter_t& Inserter, bool ScaleWithRatio )
{
    int w, h;
    engine::Engine::Get().GetSystem<engine::WindowSystem>()->GetWindowSize( w, h );
    float Ratio = ( ScaleWithRatio && h != 0 ) ? ( 1.0f * w / h ) : 1.0f;
    glm::vec2 RequiredSize, Scaler;
    std::string Buf;
    if( !CalcRequiredSize( text, Scaler, RequiredSize, Buf, Ratio ) )
    {
        return;
    }
    glm::vec4 const& Col = text.mColor;
    glm::vec4 Dim = text.mDimensions;
    switch( text.mHAlign )
    {
    case TextWidget::HAlign::Center:
        Dim.x += ( Dim.z - RequiredSize.x ) / 2.0;
        break;
    case TextWidget::HAlign::Right:
        Dim.x += ( Dim.z - RequiredSize.x );
        break;
    default:
        break;
    }

    switch( text.mVAlign )
    {
    case TextWidget::VAlign::Mid:
        Dim.y += ( Dim.w - RequiredSize.y ) / 2.0;
        break;
    case TextWidget::VAlign::Bottom:
        Dim.y += ( Dim.w - RequiredSize.y );
        break;
    default:
        break;
    }

    static Font& Fnt( Font::Get() );
    for( std::string::const_iterator i = Buf.begin(), e = Buf.end(); i != e; ++i )
    {
        Character const& Char = Fnt.GetChar( *i );
        SpritePhase const& Phase = Char.Phase;
        Dim.z = Scaler.x * Char.Size.x;
        Dim.w = Scaler.x * Ratio * Char.Size.y;
        TexturedBox( Dim, Phase, Col, Inserter );
        Dim.x += Dim.z;
    }
}
bool TextUiModel::CalcRequiredSize( Widget const& Wdg, glm::vec2& OutScaler, glm::vec2& OutReqSize, std::string& OutBuf, float Ratio )
{
    Text text( Wdg( Widget::PT_FontSize ), Wdg.GetDimensions(), GetColor( Wdg ), Wdg( Widget::PT_Text ), false );
    return CalcRequiredSize( text, OutScaler, OutReqSize, OutBuf, Ratio );
}