コード例 #1
0
void RadioButton::updateBounds()
{
    Label::updateBounds();

    Vector2 size;
    if (_selected)
    {
        const Rectangle& selectedRegion = getImageRegion("selected", NORMAL);
        size.set(selectedRegion.width, selectedRegion.height);
    }
    else
    {
        const Rectangle& unselectedRegion = getImageRegion("unselected", NORMAL);
        size.set(unselectedRegion.width, unselectedRegion.height);
    }

    if (_autoSize & AUTO_SIZE_HEIGHT)
    {
        // Text-only width was already measured in Label::update - append image
        const Theme::Border& border = getBorder(NORMAL);
        const Theme::Border& padding = getPadding();
        setHeightInternal(std::max(_bounds.height, size.y + border.top + border.bottom + padding.top + padding.bottom));
    }

    if (_autoSize & AUTO_SIZE_WIDTH)
    {
        // Text-only width was already measured in Label::update - append image
        setWidthInternal(_bounds.height + 5 + _bounds.width);
    }
}
コード例 #2
0
ファイル: ImageControl.cpp プロジェクト: 03050903/GamePlay
void ImageControl::updateBounds()
{
    if (_batch)
    {
        if (_autoSize & AUTO_SIZE_WIDTH)
        {
            setWidthInternal(_batch->getSampler()->getTexture()->getWidth());
        }

        if (_autoSize & AUTO_SIZE_HEIGHT)
        {
            setHeightInternal(_batch->getSampler()->getTexture()->getWidth());
        }
    }

    Control::updateBounds();
}
コード例 #3
0
void RadioButton::updateBounds()
{
    Label::updateBounds();

    const Rectangle& region = _image ? _image->getRegion() : Rectangle(0, 0);
    Vector2 size(region.width, region.height);

    size *= _iconScale;

    if (_autoSize & AUTO_SIZE_HEIGHT)
    {
        // Text-only width was already measured in Label::update - append image
        const Theme::Border& border = getBorder(NORMAL);
        const Theme::Border& padding = getPadding();
        setHeightInternal(std::max(size.y, _bounds.height) + border.top + border.bottom + padding.top + padding.bottom);
    }

    if ((_autoSize & AUTO_SIZE_WIDTH) != 0 && _font)
    {
        // Text-only width was already measured in Label::update - append image
        setWidthInternal(size.x + 5 + _bounds.width);
    }
}
コード例 #4
0
ファイル: Label.cpp プロジェクト: reven86/GamePlay
void Label::updateBounds()
{
    if (_autoSize != AUTO_SIZE_NONE && _font)
    {
        // Measure bounds based only on normal state so that bounds updates are not always required on state changes.
        // This is a trade-off for functionality vs performance, but changing the size of UI controls on hover/focus/etc
        // is a pretty bad practice so we'll prioritize performance here.
        if (_autoSize & AUTO_SIZE_WIDTH)
        {
            float w, h;
            _font->measureText(_text.c_str(), getFontSize(NORMAL), getTextDrawingFlags(NORMAL), &w, &h, getCharacterSpacing(NORMAL), getLineSpacing(NORMAL));
            setWidthInternal(ceilf(w + getBorder(NORMAL).left + getBorder(NORMAL).right + getPadding().left + getPadding().right));
            if (_autoSize & AUTO_SIZE_HEIGHT)
                setHeightInternal(ceilf(h + getBorder(NORMAL).top + getBorder(NORMAL).bottom + getPadding().top + getPadding().bottom));
        }
        else // _autoSize & AUTO_SIZE_HEIGHT
        {
            GP_ASSERT(_autoSize & AUTO_SIZE_HEIGHT);

            // recalculate height due to word wrapping
            float h = getFontSize(NORMAL);
            if (_textBounds.width > 0.0f)
            {
                gameplay::Rectangle clipBounds(_textBounds.width, FLT_MAX);
                gameplay::Rectangle out;
                _font->measureText(_text.c_str(), clipBounds, getFontSize(NORMAL), getTextDrawingFlags(NORMAL), &out, getTextAlignment(NORMAL), 
                    true, true, getCharacterSpacing(NORMAL), getLineSpacing(NORMAL));

                h = out.height;
            }

            setHeightInternal(ceilf(h + getBorder(NORMAL).top + getBorder(NORMAL).bottom + getPadding().top + getPadding().bottom));
        }
    }

    Control::updateBounds();
}